scistag.vislog.visual_log_test_helper.VisualLogTestHelper¶
- class VisualLogTestHelper(builder)[source]¶
Bases:
objectDefines helper functions to write VisualLog based regression and unit tests
- Parameters
builder (
VisualLogBuilder) – The actual logging writer object we use to write the document
Methods
Computes a hash value from the difference of the single output targets (html, md, txt) and the new state and compares it to a provided value.
Asserts the integrity of a dataframe
Adds a figure to the log and verifies its content to a checksum
Assert an image object and verifies it's hash value matches the object's hash.
Asserts a nunpy array for validity and logs it
Asserts a text for validity and logs it
Asserts a text for validity and logs it
Defines the beginning of a test :type text:
str:param text: The name to log :rtype:VisualLogBuilder:return: The log builderCreates a checkpoint of the current data
Verifies a hash and adds the outcome of a hash check to the output
Loads the data reference
Writes the image to disk for manual verification (if enabled in the test_config) and returns it's hash.
Saves a new data reference
Attributes
__dict____doc____module____weakref__list of weak references to the object (if defined)
Data from the last checkpoints
- assert_cp_diff(hash_val)[source]¶
Computes a hash value from the difference of the single output targets (html, md, txt) and the new state and compares it to a provided value.
- Parameters
hash_val (
str) – The hash value to compare to. Upon failure verify the different manually and copy & paste the hash value once the result was verified.
- assert_df(name, df, dump=False, hash_val=None)[source]¶
Asserts the integrity of a dataframe
- Parameters
name (str) – The name
df (pd.DataFrame) – The data frame’s part to verify
dump (bool) – Defines if the data frame shall be dumped to disk. To this once for a new data frame to create a reference
hash_val (str | None) – If specified the dataframe will get dumped as csv of which the hash value is compared to the one passed.
- assert_figure(name, figure, hash_val, alt_text=None)[source]¶
Adds a figure to the log and verifies its content to a checksum
- Parameters
name (str) – The figure’s name
figure (plt.Figure | plt.Axes | Figure | Plot) – The figure to log
alt_text (str | None) – An alternative text to display if the figure can not be displayed.
hash_val (str) – The hash value to compare to (a checksum of all pixels). The correct will be logged via an assertion upon failure and can then be copies & pasted.
- assert_image(name, source, hash_val, scaling=1.0, alt_text=None)[source]¶
Assert an image object and verifies it’s hash value matches the object’s hash.
- Parameters
name (str) – The name of the object
hash_val (str) – The hash value to compare to (a checksum of all pixels). The correct will be logged via an assertion upon failure and can then be copies & pasted.
scaling (float) – The factor by which the image shall be scaled
alt_text (str | None) – An alternative text to display if the image can not be displayed.
- assert_np(name, data, variance_abs=None, dump=False, rounded=None, hash_val=None)[source]¶
Asserts a nunpy array for validity and logs it
- Parameters
name (str) – The assertion’s name
data (np.ndarray) – The data
variance_abs (float | None) – The maximum, absolute variance to the original, 0.0 by default.
dump (bool) –
Defines if the current dump shall be overwritten. Set this once to true when you on purpose changed the data and
verified it.
rounded (int) –
Pass this if you want to hash floating point arrays where a rounded integer precision is enough.
rounded defines how many digits behind the comma are relevant, so 0 rounds to full ints, +1 rounds to 0.1, +2 rounds to 0.01 etc. pp.
hash_val (bool | None) –
The hash value to use as orientation.
Do not use this for floating point data types due to platform dependent (slight) data discrepancies.
- begin(text)[source]¶
Defines the beginning of a test :type text:
str:param text: The name to log :rtype:VisualLogBuilder:return: The log builder
- hash_check_log(value, assumed)[source]¶
Verifies a hash and adds the outcome of a hash check to the output
- Parameters
value – The hash value
assumed – The assumed value
- log_and_hash_image(name, data, alt_text=None, scaling=1.0)[source]¶
Writes the image to disk for manual verification (if enabled in the test_config) and returns it’s hash.
- Parameters
- Return type
- Returns
The image’s hash for consistency checks
- checkpoint_backups¶
Data from the last checkpoints