rbtools.testing.commands¶
Command unit testing support.
New in version 3.1.
Classes
|
Mixin for unit tests for commands. |
The result form a run_command operation. |
- class rbtools.testing.commands.RunCommandResult[source]¶
Bases:
TypedDict
,Generic
[_CommandT
]The result form a run_command operation.
New in version 5.0.
- command: _CommandT¶
The command instance that was executed.
- __closed__ = False¶
- __extra_items__ = None¶
- __mutable_keys__ = frozenset({'command', 'exit_code', 'json', 'stderr', 'stdout'})¶
- __optional_keys__ = frozenset({})¶
- __orig_bases__ = (<function TypedDict>, typing.Generic[~_CommandT])¶
- __parameters__ = (~_CommandT,)¶
- __readonly_keys__ = frozenset({})¶
- __required_keys__ = frozenset({'command', 'exit_code', 'json', 'stderr', 'stdout'})¶
- __total__ = True¶
- 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_cls
appropriately.Changed in version 5.0: Added generic support for the mixin, to type command classes and instances.
New in version 3.1.
- command_cls: Optional[type[_CommandT]] = None¶
The command class being tested.
This must be a subclass of
rbtools.commands.Command
.- Type:
- create_command(*, args: Optional[list[str]] = 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 (
list
ofstr
, 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: Optional[list[str]] = 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
RunCommandResult
for details.- Return type:
- __orig_bases__ = (<class 'kgb.agency.SpyAgency'>, typing.Generic[~_CommandT])¶
- __parameters__ = (~_CommandT,)¶