attach_table_custom_colormap

typhoon.test.reporting.tables.attach_table_custom_colormap(df, threshold, allure_title='', caption='', colormaps=None, attach_as_step=False, center_at=None)

Adds HTML table with a specific colormap applied in the table’s background to the allure report. Based on the minimum and maximum table values, as well as in threshold the table can have different green color tons (for good values - below the threshold) and red color tons (for bad values - above the threshold). These colors are set by default and can be changed by setting different values to the colormaps dictionary. For more information about colormaps access https://matplotlib.org/3.3.1/tutorials/colors/colormaps.html

This type of table can be used to show data in different scenarios:
  • THD and wTHD

  • TRD

  • RMS Value

  • Power (Active, Reactive and Apparent)

Parameters:
  • df (pandas.DataFrame) – Dataframe with the table content.

  • threshold (float-like) – The border value used to define if the table values pass or fail in the test. If the value is below defined value, the test case passed; otherwise, it failed.

  • allure_title (string) – It is an empty string (“”) by default. The title presented in the allure report.

  • caption (string) – It is an empty string (“”) by default. Table title attached directly to HTML code.

  • colormaps (dict - defaults to None) – A dictionary with the colormap to color the table. If not specified, green color tons are used for passed cases, while red is used for failed. The pass key is for the colormap to the pass results and the fail key is for the colormap to the fail results. The colormaps available can be checked in matplotlib documentation. https://matplotlib.org/tutorials/colors/colormaps.html

  • attach_as_step (bool - default False) – If set to False, table is added at the end of the report, no matter when in test it is actually attached. This is default allure behaviour, all the attachments are added at the end of the report. To overwrite this behaviour and place attachment in the report chronologically in the moment when it is added, it must be added in the separate report step. This is achieved by setting this argument to True.

  • center_at (float-like) – It is a None by default. If None the table will be colorized as discussed in the introduction of the docstring. If set up with an integer or float value this will be the expected value and the threshold option will configure a range of acceptable values below and above the center_at value. So the table values will pass if (center_at - threshold) < values < (center_at + threshold), out of this range the values will be considered failed.

Returns:

result – HTML code of the table.

Return type:

string

Examples

>>> from typhoon.test.reporting.tables import attach_table_custom_colormap
>>> import pandas as pd
>>> from pathlib import Path
>>> # filenames used to save the tables in html format
>>> html_file = str(Path(__file__).parent / "attached_table_colormap.html")
>>> html_file2 = str(Path(__file__).parent / "attached_table_colormap_new_colors.html")
>>> html_file3 = str(Path(__file__).parent / "attached_table_colormap_center_at.html")
>>> threshold = 220  # Threshold used to the first two tables
>>> threshold3 = 10  # Threshold used to the third table
>>> # Center valued is used to build the table and to render the third one
>>> center_at_value = threshold
>>> df_tmp = pd.DataFrame()
>>> for i in range(11):
>>>     for j in range(11):
>>>         df_tmp.loc[i, j] = center_at_value + 2 * (i + j - (11 - 1))
>>> df = pd.DataFrame(df_tmp, dtype=int)
>>> # table 1 - attach html table with default colormap - green color for pass, red color for fail
>>> html_code = attach_table_custom_colormap(
>>>     df, threshold,
>>>     allure_title='Green and red table',
>>>     caption='Detailed table with green and red colors')
>>> # table 1 - write resulting table code to html file
>>> with open(html_file, 'w') as fhtml:
>>>     fhtml.write(html_code)
>>> # table 2 - create a second table, with changed colors - blue color for pass, orange for fail
>>> html_code = attach_table_custom_colormap(
>>>     df, threshold,
>>>     allure_title='Blue and orange table',
>>>     caption='Detailed table with blue and orange colors',
>>>     colormaps={'pass': 'Blues', 'fail': 'Oranges'})
>>> # table 2 - write resulting table code to html file
>>> with open(html_file2, 'w') as fhtml:
>>>     fhtml.write(html_code)
>>> # table 3 - create a thirth table, with colormap application centered - green color for pass, red color for fail
>>> html_code = attach_table_custom_colormap(
>>>     df, threshold3,
>>>     allure_title='Green and red center at table',
>>>     caption='Detailed table with green and red colors center at',
>>>     center_at=center_at_value)
>>> # table 3 - write resulting table code to html file
>>> with open(html_file3, 'w') as fhtml:
>>>     fhtml.write(html_code)