scistag.vislog.visual_log_test_helper.VisualLogTestHelper

class VisualLogTestHelper(builder)[source]

Bases: object

Defines 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

assert_cp_diff

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.

assert_df

Asserts the integrity of a dataframe

assert_figure

Adds a figure to the log and verifies its content to a checksum

assert_image

Assert an image object and verifies it's hash value matches the object's hash.

assert_np

Asserts a nunpy array for validity and logs it

assert_text

Asserts a text for validity and logs it

assert_val

Asserts a text for validity and logs it

begin

Defines the beginning of a test :type text: str :param text: The name to log :rtype: VisualLogBuilder :return: The log builder

checkpoint

Creates a checkpoint of the current data

hash_check_log

Verifies a hash and adds the outcome of a hash check to the output

load_ref

Loads the data reference

log_and_hash_image

Writes the image to disk for manual verification (if enabled in the test_config) and returns it's hash.

save_ref

Saves a new data reference

Attributes

__dict__

__doc__

__module__

__weakref__

list of weak references to the object (if defined)

checkpoint_backups

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

  • source (Image | Canvas) – The data to log

  • 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.

assert_text(name, text, hash_val)[source]

Asserts a text for validity and logs it

Parameters
  • name (str) – The assertion’s name

  • text (str) – The text data

  • hash_val (str) – The assumed hash value

assert_val(name, data, hash_val=None)[source]

Asserts a text for validity and logs it

Parameters
  • name (str) – The assertion’s name

  • data (dict | list | str | Image | Figure | pd.DataFrame) – The data

  • hash_val (str | None) – The assumed hash value (not required for data w/ reference)

begin(text)[source]

Defines the beginning of a test :type text: str :param text: The name to log :rtype: VisualLogBuilder :return: The log builder

checkpoint()[source]

Creates a checkpoint of the current data

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

load_ref(name)[source]

Loads the data reference

Parameters

name (str) – The reference’s unique name

Return type

bytes | None

Returns

The data. None if no reference could be found

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
  • name (str) – The name of the test. Will result in a file named logs/TEST_DIR/test_name.png

  • data (Image | Canvas) – The image object

  • alt_text (str | None) – An alternative text to display if the image can not be displayed.

  • scaling (float) – The factor by which the image shall be scaled

Return type

str

Returns

The image’s hash for consistency checks

save_ref(name, data)[source]

Saves a new data reference

Parameters
  • name (str) – The reference’s unique name

  • data (bytes) – The data to store

checkpoint_backups

Data from the last checkpoints