turbomoleio.testing package

Module contents

Module with utility functions for the testing infrastructure.

class turbomoleio.testing.ItestConfig[source]

Bases: object

Class to store the configuration parameters used inside the integration tests.

The actual values are expected to be set by pytest.

define_timeout = 10
delete_tmp_dir = True
dryrun = False
dryrun_fpath = 'dryrun_itest.json'
dryrun_use_ref_control = False
generate_ref = False
tol = 0.0001
exception turbomoleio.testing.ItestError[source]

Bases: BaseException

Error to be raised if an itest fails.

turbomoleio.testing.assert_MSONable(obj, test_if_subclass=True)[source]

Test if obj is MSONable.

This tries to convert an object to a dictionary and back and checking if the dictionaries are equivalent.

By default, the method tests whether obj is an instance of MSONable. This check can be deactivated by setting test_if_subclass to False.

Parameters:
  • obj – the object to be tests

  • test_if_subclass

turbomoleio.testing.assert_almost_equal(actual, desired, rtol=1e-07, atol=0, ignored_values=None, err_msg='', verbose=True)[source]

Assert whether two objects are equal within a given tolerance.

This function imported from numpy.testing: assert_equal. Version 16.2. Two key modifications compared to the original implementation: 1) allow comparison of numbers with a tolerance on the difference (other functions in numpy that allow a tolerance as an argument do not support comparison between dictionaries). 2) allow to skip the explicit comparison of some attributes in dictionaries.

Raises an AssertionError if two objects are not equal within the required tolerances. Given two objects (scalars, lists, tuples, dictionaries or numpy arrays), check that all elements of these objects are almost equal. An exception is raised at the first conflicting values. Comparison for numerical values is performed with assert_allclose.

Parameters:
  • actual – the object to check.

  • desired – the expected object.

  • rtol (float) – relative tolerance.

  • atol (float) – absolute tolerance.

  • ignored_values (list) – if a comparison between two dictionaries, keywords contained in this list will not be compared (the key should still exist in both the dictionaries though).

  • err_msg (str) – the error message to be printed in case of failure.

  • verbose (bool) – if True, the conflicting values are appended to the error message.

Raises:

AssertionError – if actual and desired are not equal.

turbomoleio.testing.compare_differences(actual, desired, rtol=1e-07, atol=0, current_level=None)[source]

Compare a test object and a reference object to within some tolerance.

Parameters:
  • actual – the object to check.

  • desired – the expected object.

  • rtol (float) – relative tolerance.

  • atol (float) – absolute tolerance.

  • current_level – current_level in a nested comparison.

Returns:

The list of all differences found.

Raises:

AssertionError – if actual and desired are not equal.

turbomoleio.testing.generate_control_for_test(test_definition)[source]

Regenerate control from the definition of the test.

Parameters:

test_definition – Dictionary with the definition of the test.

Returns:

None

turbomoleio.testing.generate_reference_out_parser_files(log_fpath, outdir=None)[source]

Generate the reference test files for the File and Parser objects.

Parameters:
  • log_fpath (str) – Path to the logfile.

  • outdir (str) – Directory to output reference File and Parser_methods objects.

turbomoleio.testing.generate_reference_output(test_definition)[source]

Execute the list of Turbomole commands in the definition of the test.

Parameters:

test_definition – Dictionary with the definition of the test

Returns:

None

turbomoleio.testing.get_control_integration(filename, test_data=None)[source]

Get the path to a reference control file.

Reference control files are in the testfiles/integration/control folder.

Parameters:

filename (str) – the name of the reference control file.

Returns:

the absolute path to the coord file.

Return type:

str

turbomoleio.testing.get_sp(struc, test_data=None)[source]

Get the path to a structure in the testfiles/structures folder.

Parameters:

struc (str) – the name of the structure.

Returns:

the absolute path to the coord file.

Return type:

str

turbomoleio.testing.get_test_data_dir(module=None)[source]

Dynamically and recursively look for the test_data directory.

turbomoleio.testing.get_tests_configs_tm_versions(test_data_dir)[source]

Get the test configs for all supported tm versions.

turbomoleio.testing.get_tfp(file_name=None, test_data=None)[source]

Get test file path.

Parameters:

file_name – The name of the explicit file of which to get the path. If None, will return the test directory path.

Returns:

The full path if a file is given or the path of the testfile directory if file_name is None.

turbomoleio.testing.gisnan(x)[source]

Auxiliary function imported from numpy.testing._private version 16.2.

Used in assert_almost_equal. Imported here since it is not exposed in the public interface.

like isnan, but always raise an error if type not supported instead of returning a TypeError object. .. rubric:: Notes

isnan and other ufunc sometimes return a NotImplementedType object instead of raising any exception. This function is a wrapper to make sure an exception is always raised. This should be removed once this problem is solved at the Ufunc level.

turbomoleio.testing.has_matplotlib()[source]

Determine if matplotlib is installed.

turbomoleio.testing.run_itest(executables, define_options, coord_filename, control_reference_filename, file_classes, arguments=None, datagroups_options=None, test_data=None)[source]

Run the integration tests.

First define is executed and the produced control file is compared with the reference. If successful the required turbomole executables are run and the numerical values of the outputs will be checked with the reference.

Parameters:
  • executables – string or list of strings identifying the list of programs that should be executed.

  • define_options (dict) – the options passed to DefineRunner.

  • coord_filename (str) – the filename of the coord used. Will be taken from the testfiles/structures folder.

  • control_reference_filename (str) – the name of the reference control file used to check the correctness of the execution of DefineRunner. Will be taken from the testfiles/integration/control folder.

  • file_classes – a list of classes subclassing BaseData (or even a single one if only one program required). They will be used to generate outputs from stdout and compared with the reference.

  • arguments – string or list of strings with the arguments to be passed to the each executable.

  • datagroups_options (dict) – a dict of the form {“datagroup_name”: “datagroup_value”}. Can contain additional datagroups that will be set with the cdg utility before running the calculation.

Returns:

True if the test passed successfully

Return type:

bool

turbomoleio.testing.temp_dir(delete, changedir=True)[source]

Create a context manager with a temporary directory.

This uses with tempfile.mkdtemp and cd to it with monty.os.cd.

Parameters:
  • delete (bool) – if True the directory will be deleted at the end of the job, if False it will be preserved.

  • changedir (bool) – if True inside the context manager will make a cd to the temporary directory.

Yields:

the path to the temporary directory created.

turbomoleio.testing.touch_file(path)[source]

Touches a file at the specified path.

Parameters:

path (str) – path to the file.

Returns:

None