rbtools.testing.commands¶
Command unit testing support.
New in version 3.1.
Classes
|
Mixin for unit tests for commands. |
- class rbtools.testing.commands.CommandTestsMixin(*args, **kwargs)[source]¶
Bases:
SpyAgencyMixin 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.
New in version 3.1.
- command_cls = None[source]¶
The command class being tested.
This must be a subclass of
rbtools.commands.Command.- Type:
- create_command(args=[], server_url='https://reviews.example.com/', initialize=False, **kwargs)[source]¶
Create an argument parser with the given extra fields.
- Parameters:
args (
listofunicode, 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,
toolmust also be set.tool (
rbtools.clients.base.BaseSCMClient) –The SCM client to set for the command.
If being set,
repository_infomust also be set.scan (
bool, optional) – Whether to allow for repository scanning. IfFalse, andrepository_infoandtoolaren’t provided, then no repositories will be matched.server_url (
unicode, 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
transportargument.initialize (
bool, optional) – Whether to initialize the command before returning.
- Returns:
The command instance.
- Return type:
- run_command(args=[], server_url='https://reviews.example.com/', **kwargs)[source]¶
Run a command class and return results.
- Parameters:
args (
listofunicode, 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,
toolmust also be set.tool (
rbtools.clients.base.BaseSCMClient) –The SCM client to set for the command.
If being set,
repository_infomust also be set.scan (
bool, optional) – Whether to allow for repository scanning. IfFalse, andrepository_infoandtoolaren’t provided, then no repositories will be matched.server_url (
unicode, 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
transportargument.
- Returns:
A dictionary of results, containing:
- Keys:
command (
rbtools.commands.Command) – The command instance.exit_code (
int) – The exit code.stderr (
bytes) – The standard error output.stdout (
bytes) – The standard output.
- Return type: