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.
- __optional_keys__ = frozenset({})¶
- __orig_bases__ = (<function TypedDict>, typing.Generic[~_CommandT])¶
- __parameters__ = (~_CommandT,)¶
- __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: List[str] = [], 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.
repository_info (
rbtools.clients.base.repository.RepositoryInfo
) –The repository information to set for the command.
If being set,
tool
must also be set.tool (
rbtools.clients.base.BaseSCMClient
) –The SCM client to set for the command.
If being set,
repository_info
must also be set.scan (
bool
, optional) – Whether to allow for repository scanning. IfFalse
, andrepository_info
andtool
aren’t provided, then no repositories will be matched.server_url (
str
, optional) – The URL to use as the Review Board URL.stdout (
io.BytesIO
, optional) – A stream used to capture standard output.stderr (
io.BytesIO
, optional) – A stream used to capture standard error.stdin (
io.BytesIO
, optional) – A stream used to provide standard input.setup_transport_func (
callable
, optional) –A callback to call in order to set up transport URLs.
This must take a
transport
argument.initialize (
bool
, optional) – Whether to initialize the command before returning.
- Returns:
The command instance.
- Return type:
- run_command(args: List[str] = [], server_url: str = 'https://reviews.example.com/', **kwargs) RunCommandResult[_CommandT] [source]¶
Run a command class and return results.
- 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.
repository_info (
rbtools.clients.base.repository.RepositoryInfo
) –The repository information to set for the command.
If being set,
tool
must also be set.tool (
rbtools.clients.base.BaseSCMClient
) –The SCM client to set for the command.
If being set,
repository_info
must also be set.scan (
bool
, optional) – Whether to allow for repository scanning. IfFalse
, andrepository_info
andtool
aren’t provided, then no repositories will be matched.server_url (
str
, optional) – The URL to use as the Review Board URL.stdin (
io.BytesIO
, optional) – A stream used to provide standard input.setup_transport_func (
callable
, optional) –A callback to call in order to set up transport URLs.
This must take a
transport
argument.
- 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,)¶