API Reference

data_regression

DataRegressionFixture.check(data_dict, basename=None, fullpath=None)

Checks the given dict against a previously recorded version, or generate a new file.

Parameters
  • data_dict (dict) – any yaml serializable dict.

  • basename (str) – basename of the file to test/record. If not given the name of the test is used. Use either basename or fullpath.

  • fullpath (str) – complete path to use as a reference file. This option will ignore datadir fixture when reading expected files but will still use it to write obtained files. Useful if a reference file is located in the session data dir for example.

basename and fullpath are exclusive.

dataframe_regression

DataFrameRegressionFixture.check(data_frame, basename=None, fullpath=None, tolerances=None, default_tolerance=None)

Checks the given pandas dataframe against a previously recorded version, or generate a new file.

Example:

data_frame = pandas.DataFrame.from_dict({
    'U_gas': U[0][positions],
    'U_liquid': U[1][positions],
    'gas_vol_frac [-]': vol_frac[0][positions],
    'liquid_vol_frac [-]': vol_frac[1][positions],
    'P': Pa_to_bar(P)[positions],
})
dataframe_regression.check(data_frame)
Parameters
  • data_frame (pandas.DataFrame) – pandas DataFrame containing data for regression check.

  • basename (str) – basename of the file to test/record. If not given the name of the test is used.

  • fullpath (str) – complete path to use as a reference file. This option will ignore embed_data completely, being useful if a reference file is located in the session data dir for example.

  • tolerances (dict) –

    dict mapping keys from the data_dict to tolerance settings for the given data. Example:

    tolerances={'U': Tolerance(atol=1e-2)}
    

  • default_tolerance (dict) –

    dict mapping the default tolerance for the current check call. Example:

    default_tolerance=dict(atol=1e-7, rtol=1e-18).
    

    If not provided, will use defaults from numpy’s isclose function.

basename and fullpath are exclusive.

file_regression

FileRegressionFixture.check(contents, encoding=None, extension='.txt', newline=None, basename=None, fullpath=None, binary=False, obtained_filename=None, check_fn=None)

Checks the contents against a previously recorded version, or generate a new file.

Parameters
  • contents (str) – content to be verified.

  • encoding (str|None) – Encoding used to write file, if any.

  • extension (str) – Extension of file.

  • newline (str|None) – See io.open docs.

  • binary (bool) – If the file is binary or text.

  • obtained_filename – ..see:: FileRegressionCheck

  • check_fn – a function with signature (obtained_filename, expected_filename) that should raise AssertionError if both files differ. If not given, use internal function which compares text using difflib.

num_regression

NumericRegressionFixture.check(data_dict, basename=None, fullpath=None, tolerances=None, default_tolerance=None, data_index=None, fill_different_shape_with_nan=True)

Checks the given dict against a previously recorded version, or generate a new file. The dict must map from user-defined keys to 1d numpy arrays or array-like values.

Example:

num_regression.check({
    'U_gas': U[0][positions],
    'U_liquid': U[1][positions],
    'gas_vol_frac [-]': vol_frac[0][positions],
    'liquid_vol_frac [-]': vol_frac[1][positions],
    'P': Pa_to_bar(P)[positions],
})
Parameters
  • data_dict (dict) – dict mapping keys to numpy arrays, or objects that can be coerced to 1d numpy arrays with a numeric dtype (e.g. list, tuple, etc).

  • basename (str) – basename of the file to test/record. If not given the name of the test is used.

  • fullpath (str) – complete path to use as a reference file. This option will ignore embed_data completely, being useful if a reference file is located in the session data dir for example.

  • tolerances (dict) –

    dict mapping keys from the data_dict to tolerance settings for the given data. Example:

    tolerances={'U': Tolerance(atol=1e-2)}
    

  • default_tolerance (dict) –

    dict mapping the default tolerance for the current check call. Example:

    default_tolerance=dict(atol=1e-7, rtol=1e-18).
    

    If not provided, will use defaults from numpy’s isclose function.

  • data_index (list) – If set, will override the indexes shown in the outputs. Default is panda’s default, which is range(0, len(data)).

  • fill_different_shape_with_nan (bool) – If set, all the data provided in the data_dict that has size lower than the bigger size will be filled with np.NaN, in order to save the data in a CSV file.

basename and fullpath are exclusive.

image_regression

ImageRegressionFixture.check(image_data, diff_threshold=0.1, expect_equal=True, basename=None)

Checks that the given image contents are comparable with the ones stored in the data directory.

Parameters
  • image_data (bytes) – image data

  • basename (str|None) – basename to store the information in the data directory. If none, use the name of the test function.

  • expect_equal (bool) – if the image should considered equal below of the given threshold. If False, the image should be considered different at least above the threshold.

  • diff_threshold (float) – Tolerage as a percentage (1 to 100) on how the images are allowed to differ.