API Reference¶
data_regression¶
-
DataRegressionFixture.
check
(data_dict: Dict[str, Any], basename: Optional[str] = None, fullpath: Optional[os.PathLike[str]] = None) → None¶ Checks the given dict against a previously recorded version, or generate a new file.
Parameters: - data_dict – any yaml serializable dict.
- basename – basename of the file to test/record. If not given the name of the test is used. Use either basename or fullpath.
- fullpath – 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
andfullpath
are exclusive.
dataframe_regression¶
-
DataFrameRegressionFixture.
check
(data_frame: Any, basename: Optional[str] = None, fullpath: Optional[os.PathLike[str]] = None, tolerances: Optional[Dict[str, Dict[str, float]]] = None, default_tolerance: Optional[Dict[str, float]] = None) → None¶ Checks a pandas dataframe, containing only numeric data, 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 containing data for regression check.
- basename – basename of the file to test/record. If not given the name of the test is used.
- fullpath – 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 mapping keys from the data_frame to tolerance settings for the given data. Example:
tolerances={'U': dict(atol=1e-2)}
- default_tolerance –
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
andfullpath
are exclusive.
file_regression¶
-
FileRegressionFixture.
check
(contents: Union[str, bytes], encoding: Optional[str] = None, extension: str = '.txt', newline: Optional[str] = None, basename: Optional[str] = None, fullpath: Optional[os.PathLike[str]] = None, binary: bool = False, obtained_filename: Optional[os.PathLike[str]] = None, check_fn: Optional[Callable[[pathlib.Path, pathlib.Path], None]] = None) → None¶ Checks the contents against a previously recorded version, or generate a new file.
Parameters: - contents – content to be verified.
- encoding – Encoding used to write file, if any.
- extension – Extension of file.
- newline – See io.open docs.
- binary – 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 usingdifflib
.
num_regression¶
-
NumericRegressionFixture.
check
(data_dict: Dict[str, Any], basename: Optional[str] = None, fullpath: Optional[os.PathLike[str]] = None, tolerances: Optional[Dict[str, Dict[str, float]]] = None, default_tolerance: Optional[Dict[str, float]] = None, data_index: Optional[Sequence[int]] = None, fill_different_shape_with_nan: bool = True) → None¶ 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 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 – basename of the file to test/record. If not given the name of the test is used.
- fullpath – 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 mapping keys from the data_dict to tolerance settings for the given data. Example:
tolerances={'U': Tolerance(atol=1e-2)}
- default_tolerance –
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 – 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 – 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
andfullpath
are exclusive.
image_regression¶
-
ImageRegressionFixture.
check
(image_data: bytes, diff_threshold: float = 0.1, expect_equal: bool = True, basename: Optional[str] = None) → None¶ Checks that the given image contents are comparable with the ones stored in the data directory.
Parameters: - image_data – image data
- basename – basename to store the information in the data directory. If none, use the name of the test function.
- expect_equal – 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 – Tolerance as a percentage (1 to 100) on how the images are allowed to differ.
ndarrays_regression¶
-
NDArraysRegressionFixture.
check
(data_dict: Dict[str, Any], basename: Optional[str] = None, fullpath: Optional[os.PathLike[str]] = None, tolerances: Optional[Dict[str, Dict[str, float]]] = None, default_tolerance: Optional[Dict[str, float]] = None) → None¶ Checks a dictionary of NumPy ndarrays, containing only numeric data, against a previously recorded version, or generate a new file.
Example:
def test_some_data(ndarrays_regression): points, values = some_function() ndarrays_regression.check( { 'points': points, # array with shape (100, 3) 'values': values, # array with shape (100,) }, default_tolerance=dict(atol=1e-8, rtol=1e-8) )
Parameters: - data_dict – dictionary of NumPy ndarrays containing data for regression check. The arrays can have any shape.
- basename – basename of the file to test/record. If not given the name of the test is used.
- fullpath – 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 mapping keys from the data_dict to tolerance settings for the given data. Example:
tolerances={'U': Tolerance(atol=1e-2)}
- default_tolerance –
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
andfullpath
are exclusive.