pyretis.testing package¶
This package defines common methods which are used for testing.
Package structure¶
Modules¶
- compare.py (
pyretis.testing.compare
) - Common methods for comparing results.
- helpers.py (
pyretis.testing.helpers
) - Common methods for tests.
List of submodules¶
pyretis.testing.compare module¶
Methods that might be useful for several tests.
This module defines methods that can be used for comparing results.
-
pyretis.testing.compare.
compare_files
(file1, file2, skip=None, mode='line')[source]¶ Compare two files.
Parameters: - file1 (string) – The path to the first file to compare.
- file2 (string) – The path to the second file to compare.
- skip (list of strings or list of ints, optional) – A list of items that are to be skipped in the comparison.
- mode (string) – A string used to determine how we do the comparison:
'numerical'
will select a comparison in which the file is parsed and numerical data compared;'line'
will select a line-by-line comparison; anything else will perform a comparison usingfilecmp.cmp()
.
Returns: - out[0] (boolean) – True if the files were found to be equal, False otherwise.
- out[1] (string) – A string with information about the comparison result.
-
pyretis.testing.compare.
compare_files_columns
(file1, file2, file_type, skip=None)[source]¶ Compare two output PyRETIS files.
This method compares files where numbers are stored in columns and the columns have specific labels. Here, we also compare labels and comments.
Parameters: - file1 (string) – The path to the first file to compare.
- file2 (string) – The path to the second file to compare.
- file_type (string) – A string used to determine the file type.
- skip (list of strings, optional) – A list of items from the loaded data we are to skip. This can, for instance, be certain energy terms that are not absolute and can’t easily be compared.
Returns: - out[0] (boolean) – True if the files are deemed to be equal.
- out[1] (string) – A descriptive message of the result of the comparison.
-
pyretis.testing.compare.
compare_files_lines
(file1, file2, skip=None)[source]¶ Compare two files, line by line.
Parameters: - file1 (string) – The path to the first file to compare.
- file2 (string) – The path to the second file to compare.
- skip (list of integers, optional) – These are line numbers we are to skip.
Returns: - out[0] (boolean) – True if the files are deemed to be equal.
- out[1] (string) – A descriptive message of the result of the comparison.
-
pyretis.testing.compare.
compare_files_numerical
(file1, file2)[source]¶ Compare two output PyRETIS files.
Here, we compare files that contain numerical data. We don’t care about comments here, we just compare the actual numerical data.
Parameters: - file1 (string) – The path to the first file to compare.
- file2 (string) – The path to the second file to compare.
Returns: - out[0] (boolean) – True if the files are deemed to be equal.
- out[1] (string) – A descriptive message of the result of the comparison.
-
pyretis.testing.compare.
compare_pathensemble_files
(file1, file2, rel_tol=1e-05, skip=None)[source]¶ Compare two path ensemble files.
We compare line-by-line, but skip comments and we check that numbers are close, as judged by the given relative tolarance.
Parameters: - file1 (string) – The path to the first file to consider in the comparison.
- file2 (string) – The path to the second file to consider in the comparison.
- rel_tol (float, optional) – A relative tolerance which is used to determine if numbers are almost equal.
- skip (list of integers, optional) – These are columns we are to skip in the comparison.
Returns: - out[0] (boolean) – True if the files are equal, False otherwise.
- out[1] (string) – A message describing the result of the comparison.
-
pyretis.testing.compare.
compare_traj_archive
(dir1, dir2)[source]¶ Compare archived trajectories.
These archives consist of trajectory information such as energies, order parameters and positions. Here, we will not compare the actual raw trajectory data, but we verify that the output written by PyRETIS is identical in the two cases.
Parameters: - dir1 (string) – The path to the first directory to use in the comparison.
- dir2 (string) – The path to the second directory to use in the comparison.
Returns: out (list of tuples) – This list contains the files which differed, if any.
-
pyretis.testing.compare.
read_files
(*files, read_comments=True)[source]¶ Read files into memory.
Here, we assume that we are given small files and that we can read these into memory.
Parameters: - files (list of strings) – These are the paths to the files we are to read.
- read_comments (boolean) – If False, we skip lines starting with a “#”.
Returns: out (list of list of strings) – The data read from the different files.
pyretis.testing.helpers module¶
Methods that might be useful for testing.
This module defines generic methods for testing.
-
pyretis.testing.helpers.
search_for_files
(rootdir, match=None)[source]¶ Find files by walking the given directory.
Parameters: - rootdir (string) – The path where we will search from.
- match (string, optional) – If given, the method will only return files that are equal to the given match.
Returns: out (list of strings) – The paths of the found files.