The netsa.util.clitest module provides an API for driving automated tests of command-line applications. It doesn’t do the work of a test framekwork; for that, use a framework library such as unittest or functest.
Enough of netsa.util.clitest has been implemented to fulfill a minimal set of requirements. Additional features will be added as necessary to support more complex testing.
This module is influenced by https://pypi.python.org/pypi/Paste
A usage example:
from clitest import *
env = Environment("./test-output")
# Run the command
result = env.run("ryscatterplot --help")
assert(result.success())
assert(result.stdout() == "whatever the help output is")
assert(result.stderr() == "")
# Clean up whatever detritus the command left
env.cleanup()
Class of exceptions raised by the clitest module.
An environment for running commands, including a set of environment variables and a working directory.
The work_dir argument is the working directory in which the commands are run. If work_dir is None, a directory will be made using tempfile.mkdtemp with default values.
work_dir must not already exist or run will raise a TestingException. If save_work_dir is False, cleanup will remove this directory when it is called.
If debug is True, several debug messages will be emitted on stderr.
Any additional keyword arguments are used as environment variables.
Returns the value of env_name in the environment. If env_name does not exist in the environment, this method returns None.
Sets the value of env_name in the environment to env_val. env_val must be a string.
Removes env_name from the environment. If env_name doesn’t exist, this method has no effect.
Returns the working directory in which the commands are run.
Runs a single command, capturing and returning result information. Keyword arguments are passed to netsa.util.shell.run_parallel. See the documentation of that function for an explanation of how such arguments are interpreted.
Returns a Result object representing the outcome.
Cleans up resources left behind by the test process.
Contains information on a command’s exit status and output.
Returns True if the exit code of the process was 0. This usually, but not always, indicates that the process ran successfully. Know Your Tool before relying on this function.
Returns True if the process exited with the specified exit code. If the exit code is None or unsupplied, returns True if the process terminated normally (e.g., not on a signal).
Returns the exit status of the process, if the process exited normally (e.g., was not terminated on a signal). Otherwise, this function returns None.
Returns the signal on which the process terminated, if the process terminated on a signal. Otherwise, this function returns None.
Returns True if the process terminated on the specified signal. If the signal is None or unsupplied, returns True if the process terminated on a signal.
Returns a human-readable representation of how the process exited.
Returns the raw exit status of the process, as an integer formatted in the style of os.wait.
Returns the standard output of the process as a string.
Returns the standard error of the process as a string.
Returns the information contained in the result as a human-readable string.