CliCmdTestBase¶
- class lsst.daf.butler.tests.CliCmdTestBase¶
- Bases: - ABC- A test case base that is used to verify click command functions import and call their respective script functions correctly. - Attributes Summary - Get the command line interface function under test, can be overridden to test CLIs other than butler. - Get the mock object to use in place of - 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. - 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()- 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.mock.patch, this is usually a- unittest.mock.MagicMock.
 - mockFuncName¶
- The qualified name of the function to mock, will be passed to unittest.mock.patch, see python docs for details. 
 - Methods Documentation - abstract static command() click.Command¶
- Get the click.Command being tested. 
 - run_command(inputs: list[str]) click.testing.Result¶
- 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. 
 
- inputs[
- Returns:
- resultclick.testing.Result
- The Result object contains the results from calling self.runner.invoke. 
 
- result
 
 - run_missing(inputs: list[str], expectedMsg: str) None¶
- 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: list[str], expectedKwargs: dict[str, str], withTempFile: str | None = None) click.testing.Result¶
- 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 inspect 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. 
- expectedKwargsdict[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. 
- withTempFilestr, 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. 
 
- inputs[
- Returns:
- resultclick.testing.Result
- The result object produced by invocation of the command under test. 
 
- result