test

test#


SNAPSHOT_FLOAT_DECIMALS_DEFAULT = 6#

The default number of float decimal places to consider when converting to a snapshot. Overwrite this constant in user code if you want to change the default for all calls to snapshot_compatible

SNAPSHOT_SIGNIFICANT_DIGITS_DEFAULT = 12#

The (maximum) number of significant digits to consider when converting to a snapshot. Overwrite this constant in user code if you want to change the default for all calls to snapshot_compatible

snapshot_compatible(obj, float_decimals: Optional[int] = None, significant_digits: Optional[int] = None)[source]#

Renders an object snapshot-compatible by appropriately converting nested types and reducing float precision to a level that is likely to not cause problems when testing snapshots for equivalence on different platforms. Works with many standard python, numpy and pandas objects, including arrays and data frames.

Parameters:
  • obj – the object to convert

  • float_decimals – the number of float decimal places to consider, by default it is 6 (see SNAPSHOT_FLOAT_DECIMALS_DEFAULT)

  • significant_digits – the (maximum) number of significant digits to consider, by default it is 12 (see SNAPSHOT_SIGNIFICANT_DIGITS_DEFAULT)

Returns:

the converted object

reduce_float_precision(f, decimals, significant_digits)[source]#
convert_floats(o, float_decimals, significant_digits)[source]#
json_mapper(o)[source]#

Maps the given data object to a representation that is JSON-compatible. Currently, the supported object types include, in particular, numpy arrays as well as pandas Series and DataFrames.

Parameters:

o – the object to convert

Returns:

the converted object