spinn_utilities.testing package

Submodules

spinn_utilities.testing.docs_checker module

class spinn_utilities.testing.docs_checker.DocsChecker(*, check_init: bool = True, check_short: bool = True, check_params: bool = True, check_properties: bool = True, check_returns: bool = True, check_types_in_docs: bool = True)[source]

Bases: object

A utility class to check the docs strings for our rules.

As we use type annotations doc strings should not have types. At best they are the same otherwise they are wrong.

We check that all documented params are actually ones used. The inverse is not checked as a good param name is often enough

Sets up the doc checker.

Which functions need to be documented is left to pylint to check. Currently, that is public methods and public methods of public classes. pylint does not insist init methods are documented.

Parameters:
  • check_init – flag to trigger checking of __init__ methods. If True all init methods must have all params documented Descriptions not allowed on __init__ files as they should be on the class only.

  • check_short – Flag to trigger checking of a description. For public (None init) methods (except setters) with no return there must be a short description

  • check_params – Flag to trigger checking of params. If any param is listed all must be. The param does not need to be documented.

  • check_properties – Flag to trigger checking of Properties They must include a description. They should not have a return annotation

  • check_returns – Flag to trigger checking of return annotations when not a property

  • check_types_in_docs – Flag to trigger checking that doc-string have no types

check_dir(dir_path: str) None[source]

Checks all py files in this directory including subdirectories.

check_file(file_path: str) None[source]

Check the documentation in this file.

check_function(node: FunctionDef) None[source]

Check the documentation in this function.

check_no_errors() None[source]

Checks that there are no errors found.

Does not run any checks just check status after they are run

Raises:

AssertionError – If any previous check found an error

get_param_names(node: FunctionDef) Set[str][source]

Gets the names of the parameters found in the abstract syntax tree.

These are the ones actually declared.

Returns:

Names of all parameter including normal and kwargs ones

has_returns(node: FunctionDef) bool[source]
Returns:

True if and only if there is a return declared

is_not_overload(node: FunctionDef) bool[source]
Returns:

True if and only if there is NO @overload decorator

is_property(node: FunctionDef) bool[source]
Returns:

True if and only if there is a @property decorator

spinn_utilities.testing.log_checker module

spinn_utilities.testing.log_checker.assert_logs_contains_once(level: str, log_records: List[LogRecord], message: str) None[source]

Checks if the log records contain exactly one record at the given level with the given sub-message.

Note

While this code does not depend on testfixtures, you will need testfixtures to generate the input data

Parameters:
  • level – The log level. Probably “INFO”, “WARNING” or “ERROR”.

  • log_records – list of log records returned by testfixtures.LogCapture

  • message – String which should be part of a log record

Raises:

AssertionError – If the submessage is not present in the log

spinn_utilities.testing.log_checker.assert_logs_error_contains(log_records: List[LogRecord], submessage: str) None[source]

Checks it the log records contain an ERROR log with this sub-message

Note

While this code does not depend on testfixtures, you will need testfixtures to generate the input data

Parameters:
  • log_records – list of log records returned by testfixtures.LogCapture

  • submessage – String which should be part of an ERROR log

Raises:

AssertionError – If the submessage is not present in the log

spinn_utilities.testing.log_checker.assert_logs_error_not_contains(log_records: List[LogRecord], submessage: str) None[source]

Checks it the log records do not contain an ERROR log with this sub-message.

Note

While this code does not depend on testfixtures, you will need testfixtures to generate the input data

Parameters:
  • log_records – list of log records returned by testfixtures.LogCapture

  • submessage – String which should be part of an ERROR log

Raises:

AssertionError – If the submessage is present in the log

spinn_utilities.testing.log_checker.assert_logs_info_contains(log_records: List[LogRecord], sub_message: str) None[source]

Checks it the log records contain an INFO log with this sub-message

Note

While this code does not depend on testfixtures, you will need testfixtures to generate the input data

Parameters:
  • log_records – list of log records returned by testfixtures.LogCapture

  • sub_message – String which should be part of an INFO log

Raises:

AssertionError – If the submessage is not present in the log

spinn_utilities.testing.log_checker.assert_logs_info_not_contains(log_records: List[LogRecord], submessage: str) None[source]

Checks it the log records do not contain an INFO log with this sub-message.

Note

While this code does not depend on testfixtures, you will need testfixtures to generate the input data

Parameters:
  • log_records – list of log records returned by testfixtures.LogCapture

  • submessage – String which should be part of an INFO log

Raises:

AssertionError – If the submessage is present in the log

spinn_utilities.testing.log_checker.assert_logs_warning_contains(log_records: List[LogRecord], submessage: str) None[source]

Checks it the log records contain an WARNING log with this sub-message

Note

While this code does not depend on testfixtures, you will need testfixtures to generate the input data

Parameters:
  • log_records – list of log records returned by testfixtures.LogCapture

  • submessage – String which should be part of an WARNING log

Raises:

AssertionError – If the submessage is not present in the log

Module contents