rbtools.testing.commands¶
Command unit testing support.
Added in version 3.1.
Classes
|
Mixin for unit tests for commands. |
The result form a run_command operation. |
- class rbtools.testing.commands.CommandTestsMixin(*args, **kwargs)[source]¶
Bases:
SpyAgency,Generic[_CommandT]Mixin for unit tests for commands.
This provides utility commands for creating and running commands in a controlled environment, allowing API URLs to be created and output and exit codes to be captured.
Subclasses must provide the type of the class as a generic to the mixin, and set
command_clsappropriately.Changed in version 5.0: Added generic support for the mixin, to type command classes and instances.
Added in version 3.1.
- __firstlineno__ = 59¶
- __static_attributes__ = ()¶
- command_cls: type[_CommandT] | None = None¶
The command class being tested.
This must be a subclass of
rbtools.commands.Command.- Type:
- create_command(*, args: list[str] | None = None, server_url: str = 'https://reviews.example.com/', initialize: bool = False, **kwargs) _CommandT[source]¶
Create an argument parser with the given extra fields.
- Parameters:
args (
listofstr, optional) –A list of command line arguments to be passed to the parser.
The command line will receive each item in the list.
server_url (
str, optional) – The URL to use as the Review Board URL.initialize (
bool, optional) – Whether to initialize the command before returning.**kwargs (
dict) – Additional keyword arguments.
- Returns:
The command instance.
- Return type:
- run_command(args: list[str] | None = None, server_url: str = 'https://reviews.example.com/', **kwargs) RunCommandResult[_CommandT][source]¶
Run a command class and return results.
- Parameters:
- Returns:
A dictionary of results from the command execution. See
RunCommandResultfor details.- Return type:
- class rbtools.testing.commands.RunCommandResult[source]¶
Bases:
TypedDict,Generic[_CommandT]The result form a run_command operation.
Added in version 5.0.
- __firstlineno__ = 36¶
- __static_attributes__ = ()¶
- command: ForwardRef('_CommandT', module='rbtools.testing.commands')¶
The command instance that was executed.
- exit_code: ForwardRef('int | str | None', module='rbtools.testing.commands')¶
The exit code of the command.
- json: ForwardRef('dict[str, Any]', module='rbtools.testing.commands')¶
The JSON results of the command.
- stderr: ForwardRef('bytes', module='rbtools.testing.commands')¶
Standard error output from the command.
- stdout: ForwardRef('bytes', module='rbtools.testing.commands')¶
Standard output from the command.