Jump to >

reviewbot.tools.testing.testcases

Base test case support for tools.

New in version 3.0.

Classes

BaseToolTestCase(*args, **kwargs)

Base class for Tool test cases.

ToolTestCaseMetaclass(name, bases, d)

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() or setup_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 of str) – 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 a test_tag_*.

Parameters
  • func_name (str) – The original name of the function.

  • tag (unicode) – 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

class BaseToolTestCase(*args, **kwargs)[source]

Bases: kgb.agency.SpyAgency, reviewbot.testing.testcases.TestCase

Base class for Tool test cases.

New in version 3.0.

tool_class = None[source]

The tool class to test.

This is required.

Type:

type

tool_exe_config_key = None[source]

The key in the configuration identifying the executable of the tool.

This is required.

Type:

unicode

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:

unicode

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 to tool_exe_path.

Type:

dict

run_get_can_handle_file(filename, file_contents=b'', tool_settings={})[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().

Parameters
  • filename (unicode) – 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.

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={})[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().

Parameters
  • filename (unicode) – The filename of the file being reviewed.

  • file_contents (bytes) – File content to review.

  • checkout_dir (unicode, 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.

Returns

A 2-tuple containing:

  1. The review (reviewbot.processing.review.Review)

  2. 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 from other_files (along with filename) to reviewbot.processing.review.File instances.

Return type

tuple

setup_integration_test(**kwargs)[source]

Set up an integration test.

Parameters

**kwargs (dict) – Keyword arguments passed to integration_test().

setup_simulation_test(**kwargs)[source]

Set up a simulation test.

Parameters

**kwargs (dict) – Keyword arguments passed to simulation_test().

__annotations__ = {}[source]