Package test_suite :: Package unit_tests :: Module unit_test_runner :: Class Unit_test_runner
[hide private]
[frames] | no frames]

Class Unit_test_runner

source code


Class to run a particular unit test or a directory of unit tests.

Instance Methods [hide private]
 
__init__(self, root_path='.', test_module=None, search_for_root_path=True, search_for_unit_test_path=True, verbose=False)
Initialise the unit test runner.
source code
str
get_first_instance_path(self, path, target_path, offset_path='.')
Get the minimal path searching up the file system to target_directory.
source code
str
paths_from_test_module(self, test_module)
Determine the possible paths of the test_module.
source code
str
run(self, runner=None)
Run a unit test or set of unit tests.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Instance Variables [hide private]
list of str system_path_pattern = ['test_suite/unit_tests', '../..']
A search template for the directory in which relax is installed.
list of str unit_test_path_pattern = ['test_suite/unit_tests', '.']
A search template for the directory from which all unit module directories descend.
list of str test_case_patterns = ['test_.*\\.py$']
A list of regex patterns against which files will be tested to see if they are expected to contain unit tests.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, root_path='.', test_module=None, search_for_root_path=True, search_for_unit_test_path=True, verbose=False)
(Constructor)

source code 

Initialise the unit test runner.

Parameters:
  • root_path (str) - Root path to start searching for modules to unit test from. If the string contains '.' the search starts from the current working directory. Default current working directory.
  • test_module (str) - The name of a module to unit test. If the variable is None a search for all unit tests using <test-pattern> will start from <root_path>, if the variable is '.' a search for all unit tests will commence from the current working directory, otherwise it will be used as a module path from the current root_path or CHECKME: ****module_directory_path****. The module name can be in the directory path format used by the current operating system or a unix style path with /'s including a final .py extension or a dotted moudle name.
  • search_for_root_path (bool) - Whether to carry out a search from the root_directory using self.system_path_pattern to find the directory self.system_directory if no search is carried out self.system_directory is set to None and it is the responsibility of code creating the class to set it before self.run is called.
  • search_for_unit_test_path (bool) - Whether to carry out a search from the root_directory using self.unit_test_path_patter to find the directory self.unit_test_directory if no search is carried out self.unit_test_directory is set to None and it is the responsibility of code creating the class to set it before self.run is called.
  • verbose (bool) - Produce verbose output during testing e.g. directories searched root directories etc.
Overrides: object.__init__

get_first_instance_path(self, path, target_path, offset_path='.')

source code 

Get the minimal path searching up the file system to target_directory.

The algorithm is that we repeatedly chop the end off path and see if the tail of the path matches target_path If it doesn't match we search in the resulting directory by appending target_path and seeing if it exists in the file system. Finally once the required directory structure has been found the offset_path is appended to the found path and the resulting path normalised.

Note the algorithm understands .. and .

Parameters:
  • path (str) - A directory path to search up.
  • target_path (str) - A directory to find in the path or below one of the elements in the path.
  • offset_path (str) - A relative path offset to add to the path that has been found to give the result directory.
Returns: str
The path that has been found or None if the path cannot be found by walking up and analysing the current directory structure.

paths_from_test_module(self, test_module)

source code 

Determine the possible paths of the test_module.

It is assumed that the test_module can be either a path or a python module or package name including dots.

The following heuristics are used:

  1. If the test_module=None add the value '.'.
  2. If the test_module ends with a PY_FILE_EXTENSION append test_module with the PY_FILE_EXTENSION removed.
  3. Add the module_name with .'s converted to /'s and any elements of the form PY_FILE_EXTENSION removed.
  4. Repeat 2 and 3 with the last element of the path repeated with the first letter capitalised.

Note: we can't deal with module methods...

Returns: str
A set of possible module names in python '.' separated format.

run(self, runner=None)

source code 

Run a unit test or set of unit tests.

Parameters:
  • runner (Unit test runner instance (TextTestRunner, BaseGUITestRunner subclass, etc.)) - A unit test runner such as TextTestRunner. None indicates use of the default unit test runner. For an example of how to write a test runner see the python documentation for TextTestRunner in the python source.
Returns: str
A string indicating success or failure of the unit tests run.

Instance Variable Details [hide private]

system_path_pattern

A search template for the directory in which relax is installed. The directory which relax is installed in is viewed as the the 'PYTHONPATH' of the classes to be tested. It must be unique and defined relative to the test suite. For the current setup in relax this is ('test_suite', /'..'). The first string is a directory structure to match the second string is a relative path from that directory to the system directory. The search is started from the value of root_path in the file system.
Type:
list of str
Value:
['test_suite/unit_tests', '../..']

unit_test_path_pattern

A search template for the directory from which all unit module directories descend. For the current setup in relax this is ('unit_tests', '.'). The search is started from the value of root_path in the file system.
Type:
list of str
Value:
['test_suite/unit_tests', '.']

test_case_patterns

A list of regex patterns against which files will be tested to see if they are expected to contain unit tests. If the file has the correct pattern the module contained inside the file will be searched for testCases e.g in the case of test_float.py the module to be searched for would be test_float.Test_float.
Type:
list of str
Value:
['test_.*\\.py$']