reviewbot.tools.testing.testcases¶
Base test case support for tools.
New in version 3.0.
Classes
|
Base class for Tool test cases. |
|
Metaclass for tool tests. |
- class ToolTestCaseMetaclass(name, bases, d)[source]¶
Bases:
type
Metaclass for tool tests.
This is required for all subclasses of
BaseToolTestCase
.This will split any test methods that are marked as a simulation and/or integration test into individual tests, set up by the subclass’s
setup_simulation_test()
orsetup_integration_test()
method.New in version 3.0.
- static __new__(meta, name, bases, d)[source]¶
Construct a new class.
- Parameters:
name (
str
) – The name of the class.bases (
tuple
ofstr
) – The parent classes/mixins.d (
dict
) – The class dictionary.
- Returns:
The new class.
- Return type:
type
- classmethod tag_func_name(func_name, tag)[source]¶
Return a function name tagged with an identifier.
This will convert a
test_*
function name into atest_tag_*
.- Parameters:
func_name (
str
) – The original name of the function.tag (
str
) – The tag to add.
- Returns:
The resulting function name.
- Return type:
str
- classmethod make_integration_test_func(func, func_name)[source]¶
Return a new function for an integration test.
The function will wrap the original function from the class, and set up the state for an integration test.
- Parameters:
func (
callable
) – The function to wrap.func_name (
str
) – The name of the function.
- Returns:
The new integration test function.
- Return type:
callable
- classmethod make_simulation_test_func(func, func_name)[source]¶
Return a new function for a simulation test.
The function will wrap the original function from the class, and set up the state for a simulation test.
- Parameters:
func (
callable
) – The function to wrap.func_name (
str
) – The name of the function.
- Returns:
The new simulation test function.
- Return type:
callable
- __annotations__ = {}¶
- class BaseToolTestCase(*args, **kwargs)[source]¶
Bases:
SpyAgency
,TestCase
Base class for Tool test cases.
New in version 3.0.
- tool_exe_config_key = None[source]¶
The key in the configuration identifying the executable of the tool.
This is required.
- Type:
str
- tool_exe_path = None[source]¶
The path to the executable for running the tool.
This will generally be a fake path for simulated tool runs, but a real one for integration tests. It can be set on the class or during test/test suite setup.
- Type:
str
- tool_extra_exe_paths = {}[source]¶
Extra executables needed to run the tool.
If the tool needs more than one executable for executions or dependency checks, they should be placed here. Keys are equivalent to
tool_exe_config_key
, and values are equivalent totool_exe_path
.- Type:
dict
- run_get_can_handle_file(filename, file_contents=b'', tool_settings={}, file_contents_encoding='utf-8')[source]¶
Run get_can_handle_file with the given file and settings.
This will create the review objects, set up a repository (if needed by the tool), apply any configuration, and run
get_can_handle_file()
.Changed in version 3.1.2: Added the
file_contents_encoding
argument.- Parameters:
filename (
str
) – The filename of the file being reviewed.file_contents (
bytes
, optional) – File content to review.tool_settings (
dict
, optional) – The settings to pass to the tool constructor.file_contents_encoding (
str
, optional) –The encoding used for the provided file contents (both in
file_contents
andother_contents
).If not provided, this will be
utf-8
.New in version 3.1.2.
- Returns:
True
if the file can be handled.False
if it cannot.- Return type:
bool
- run_tool_execute(filename, file_contents, checkout_dir=None, tool_settings={}, other_files={}, file_contents_encoding='utf-8')[source]¶
Run execute with the given file and settings.
This will create the review objects, set up a repository (if needed by the tool), apply any configuration, and run
execute()
.Changed in version 3.1.2: Added the
file_contents_encoding
argument.- Parameters:
filename (
str
) – The filename of the file being reviewed.file_contents (
bytes
) – File content to review.checkout_dir (
str
, optional) – An explicit directory to use as the checkout directory, for tools that require full-repository checkouts.tool_settings (
dict
, optional) – The settings to pass to the tool constructor.other_files (
dict
, optional) –Other files to write to the tree. Each will result in a new file added to the review.
The dictionary is a map of file paths (relative to the checkout directory) to byte strings.
file_contents_encoding (
str
, optional) –The encoding used for the provided file contents (both in
file_contents
andother_contents
).If not provided, this will be
utf-8
.New in version 3.1.2.
- Returns:
A 2-tuple containing:
The review (
reviewbot.processing.review.Review)
The file entry corresponding to
filename
(reviewbot.processing.review.File
)
If
other_files
is specified, the second tuple item will instead be a dictionary of keys fromother_files
(along withfilename
) toreviewbot.processing.review.File
instances.- Return type:
tuple
- setup_integration_test(**kwargs)[source]¶
Set up an integration test.
- Parameters:
**kwargs (
dict
) – Keyword arguments passed tointegration_test()
.
- setup_simulation_test(**kwargs)[source]¶
Set up a simulation test.
- Parameters:
**kwargs (
dict
) – Keyword arguments passed tosimulation_test()
.
- __annotations__ = {}¶