OptFlagTest¶
-
class
lsst.daf.butler.tests.
OptFlagTest
¶ Bases:
lsst.daf.butler.tests.OptTestBase
A mixin that tests an option behaves as a flag, instead of accepting a value.
Attributes Summary
choices
Return the list of valid choices for the option. expectedChoiceValues
Return the list of expected values for the option choices. expectedMultipleKeyValues
The expected valuse to receive in the command function when a test command is called with multiple key - value inputs. expectedMultipleValues
The expected values to receive in the command function when a test command is called with multiple inputs. expectedVal
The expected value to receive in the command function. expectedValDefault
When the option is not required and not passed to the test command, this is the expected default value to appear in the command function. isArgument
True if the Parameter under test is an Argument, False if it is an Option. isBool
True if the option only accepts bool inputs. isChoice
True if the parameter accepts a limited set of input values. isParameter
True if the Parameter under test can be set to an Option or an Argument, False if it only supports one or the other. metavar
Return the metavar expected to be printed in help text after the option flag(s). optionClass
The option class being tested optionFlag
The flag that is used on the command line for the option. optionKey
The option name as it appears as a function argument and in subsequent uses (e.g. optionMultipleKeyValues
The values to pass for the option flag when calling a test command with multiple key-value inputs. optionMultipleValues
The value(s) to pass for the option flag when calling a test command with multiple inputs. optionName
The option name, matches the option flag that appears on the command line. optionValue
The value to pass for the option flag when calling the test command. shortOptionFlag
The abbreviated flag that is used on the command line for the option. shortOptionName
The short option flag that can be used on the command line. valueType
The value type
of the click.Option.Methods Summary
makeInputs
(optionFlag[, values])Make the input arguments for a CLI invocation, taking into account if the parameter is an Option (use option flags) or an Argument (do not use option flags). run_command
(cmd, args)Run a command. run_test
(cmd, cmdArgs, verifyFunc[, verifyArgs])setUp
()test_forFlag_false
()test_forFlag_true
()verifyCalledWith
(result, mockInfo)Verify the command function has been called with specified arguments. verifyError
(result, expectedMsg)Verify the command failed with a non-zero exit code and an expected output message. verifyMissing
(result, verifyArgs)Verify there was a missing argument; that the expected error message has been written to stdout, and that the command exit code is not 0. Attributes Documentation
-
choices
¶ Return the list of valid choices for the option.
-
expectedChoiceValues
¶ Return the list of expected values for the option choices. Must match the size and order of the list returned by
choices
.
-
expectedMultipleKeyValues
¶ The expected valuse to receive in the command function when a test command is called with multiple key - value inputs.
-
expectedMultipleValues
¶ The expected values to receive in the command function when a test command is called with multiple inputs.
Returns:
-
expectedVal
¶ The expected value to receive in the command function. Typically that value is printed to stdout and compared with this value. By default returns the same value as
self.optionValue
.
-
expectedValDefault
¶ When the option is not required and not passed to the test command, this is the expected default value to appear in the command function.
-
isArgument
¶ True if the Parameter under test is an Argument, False if it is an Option.
-
isBool
¶ True if the option only accepts bool inputs.
-
isChoice
¶ True if the parameter accepts a limited set of input values. Default implementation is to see if the option class has an attribute called choices, which should be of type
list
[str
].
-
isParameter
¶ True if the Parameter under test can be set to an Option or an Argument, False if it only supports one or the other.
-
metavar
¶ Return the metavar expected to be printed in help text after the option flag(s). If
None
, won’t run a test for the metavar value.
-
optionClass
¶ The option class being tested
-
optionFlag
¶ The flag that is used on the command line for the option.
-
optionKey
¶ The option name as it appears as a function argument and in subsequent uses (e.g. kwarg dicts); dashes are replaced by underscores.
-
optionMultipleKeyValues
¶ The values to pass for the option flag when calling a test command with multiple key-value inputs.
-
optionMultipleValues
¶ The value(s) to pass for the option flag when calling a test command with multiple inputs.
Returns:
-
optionName
¶ The option name, matches the option flag that appears on the command line.
-
optionValue
¶ The value to pass for the option flag when calling the test command. If the option class restricts option values, by default returns the first item from
self.optionClass.choices
, otherwise returns a nonsense string.
-
shortOptionFlag
¶ The abbreviated flag that is used on the command line for the option.
-
shortOptionName
¶ The short option flag that can be used on the command line.
Returns:
Methods Documentation
-
makeInputs
(optionFlag, values=None)¶ Make the input arguments for a CLI invocation, taking into account if the parameter is an Option (use option flags) or an Argument (do not use option flags).
Parameters: - optionFlag :
str
orNone
The option flag to use if this is an Option. May be None if it is known that the parameter will never be an Option.
- optionValues :
str
,list
[str
], or None The values to use as inputs. If
None
; for an Argument returns an empty list, or for an Option returns a single-item list containing the option flag.
Returns: - optionFlag :
-
run_command
(cmd, args)¶ Run a command.
Parameters: - cmd : click.Command
The command function to call.
- args : [
str
] The arguments to pass to the function call.
Returns: - result :
click.Result
The Result instance that contains the results of the executed command.
-
run_test
(cmd, cmdArgs, verifyFunc, verifyArgs=None)¶
-
setUp
()¶
-
test_forFlag_false
()¶
-
test_forFlag_true
()¶
-
verifyCalledWith
(result, mockInfo)¶ Verify the command function has been called with specified arguments.
-
verifyError
(result, expectedMsg)¶ Verify the command failed with a non-zero exit code and an expected output message.
-
verifyMissing
(result, verifyArgs)¶ Verify there was a missing argument; that the expected error message has been written to stdout, and that the command exit code is not 0.
-