sh is a full-fledged subprocess replacement for Python 2, Python 3, PyPy and PyPy3 that allows you to call any program as if it were a function:
from sh import ifconfig
print(ifconfig("eth0"))
sh is not a collection of system commands implemented in Python.
sh relies on various Unix system calls and only works on Unix-like operating systems - Linux, macOS, BSDs etc. Specifically, Windows is not supported.
$> pip install sh
- Andrew Moffat - author/maintainer
- Erik Cederstrand - maintainer
Check out the gh-pages branch and follow the README.rst
there.
I've included a Docker test suite in the docker_test_suit/ folder. To build the image, cd into that directory and run:
$> ./build.sh
This will install ubuntu 18.04 LTS and all supported python versions. Once it's done, stay in that directory and run:
$> ./run.sh
This will mount your local code directory into the container and start the test suite, which will take a long time to run. If you wish to run a single test, you may pass that test to ./run.sh:
$> ./run.sh FunctionalTests.test_unicode_arg
To run a single test for a single environment:
$> ./run.sh -e 3.4 FunctionalTests.test_unicode_arg
First run all of the tests:
$> SH_TESTS_RUNNING=1 coverage run --source=sh -m unittest
This will aggregate a .coverage
. You may then visualize the report with:
$> coverage report
Or generate visual html files with:
$> coverage html
Which will create ./htmlcov/index.html
that you may open in a web browser.