CliCmdTestBase

class lsst.daf.butler.tests.CliCmdTestBase

Bases: abc.ABC

A test case base that is used to verify click command functions import and call their respective script functions correctly.

Attributes Summary

cli Get the command line interface function under test, can be overridden to test CLIs other than butler.
mock Get the mock object to use in place of mockFuncName.
mockFuncName The qualified name of the function to mock, will be passed to unittest.mock.patch, see python docs for details.

Methods Summary

command() Get the click.Command being tested.
defaultExpected()
makeExpected(**kwargs)
run_command(inputs) Use the LogCliRunner with the mock environment variable set to execute a butler subcommand and parameters specified in inputs.
run_missing(inputs, expectedMsg) Run the subcommand specified in inputs and verify a failed outcome where exit code != 0 and an expected message has been written to stdout.
run_test(inputs, expectedKwargs[, withTempFile]) Run the subcommand specified in inputs and verify a successful outcome where exit code = 0 and the mock object has been called with the expected arguments.
setUp()
test_help()

Attributes Documentation

cli

Get the command line interface function under test, can be overridden to test CLIs other than butler.

mock

Get the mock object to use in place of mockFuncName. If not provided will use the default provided by unittest.patch, this is usually a unittest.patch.MagicMock.

mockFuncName

The qualified name of the function to mock, will be passed to unittest.mock.patch, see python docs for details.

Methods Documentation

static command()

Get the click.Command being tested.

static defaultExpected()
classmethod makeExpected(**kwargs)
run_command(inputs)

Use the LogCliRunner with the mock environment variable set to execute a butler subcommand and parameters specified in inputs.

Parameters:
inputs : [str]

A list of strings that begins with the subcommand name and is followed by arguments, option keys and option values.

Returns:
result : click.testing.Result

The Result object contains the results from calling self.runner.invoke.

run_missing(inputs, expectedMsg)

Run the subcommand specified in inputs and verify a failed outcome where exit code != 0 and an expected message has been written to stdout.

Parameters:
inputs : [str]

A list of strings that begins with the subcommand name and is followed by arguments, option keys and option values.

expectedMsg : str

An error message that should be present in stdout after running the subcommand. Can be a regular expression string.

run_test(inputs, expectedKwargs, withTempFile=None)

Run the subcommand specified in inputs and verify a successful outcome where exit code = 0 and the mock object has been called with the expected arguments.

Returns the result object for inspection, e.g. sometimes it’s useful to be able to inpsect or print result.output.

Parameters:
inputs : [str]

A list of strings that begins with the subcommand name and is followed by arguments, option keys and option values.

expectedKwargs : dict [str, str]

The arguments that the subcommand function is expected to have been called with. Keys are the argument name and values are the argument value.

withTempFile : str, optional

If not None, will run in a temporary directory and create a file with the given name, can be used with commands with parameters that require a file to exist.

Returns:
result : click.testing.Result

The result object produced by invocation of the command under test.

setUp()
test_help()