attach_table_custom_colormap_by_column

typhoon.test.reporting.tables.attach_table_custom_colormap_by_column(df, thresholds, allure_title='', caption='', colormaps=None, attach_as_step=False)

Adds html table to allure report in the same way as the attach_table_custom_colormap with only difference that the threshold value is unique for each column; the user can repeat the threshold values, but threshold value is needed for every column. Same as there, if colormap is not specified, tons of green color are used for pass, while red is used for fail cases. This behaviour is overwritten by seting 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 for example:
  • Measurements in specific harmonic components

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

  • threshold (dict) – Dictionary for setting the border values which define if test passed or failed, specific for every column. For this type of table, it’s necessary to offer one threshold for each column in a dictionary.

  • 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) – It is None by default. As said earlier, if not specified, green color is used for pass, while red is used for fail test cases. A dictionary with the colormap to color the table. 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.

Returns:

result – HTML code of the table.

Return type:

string

Examples

>>> from typhoon.test.reporting.tables import attach_table_custom_colormap_by_column
>>> import pandas as pd
>>> import numpy as np
>>> from pathlib import Path
>>> columns = np.linspace(0, 9, 10)
>>> thresholds = {0: .1, 1: .2, 2: .3, 3: .4, 4: .5,
>>>               5: .6, 6: .7, 7: .8, 8: .9, 9: 1.}
>>> # create table for the harmonics from 0 to 9 with default colors
>>> df = pd.DataFrame(np.random.random(size=(10, 10)), columns=columns)
>>> html_code = attach_table_custom_colormap_by_column(
>>>     df, thresholds,
>>>     allure_title='Random Integer Values',
>>>     caption='Harmonic table with Random Integer Values')
>>> html_file = str(Path(__file__).parent / "harmonics_table.html")
>>> with open(html_file, 'w') as fhtml:
>>>     fhtml.write(html_code)
>>> # create same  table with blue color for passed and orange color for failed cases
>>> html_code = attach_table_custom_colormap_by_column(
>>>     df, thresholds,
>>>     allure_title='Random Integer Values',
>>>     caption='Harmonic table with Random Integer Values',
>>>     colormaps={'pass': 'Blues', 'fail': 'Oranges'})
>>> html_file = str(Path(__file__).parent / "harmonics_table_new_colors.html")
>>> with open(html_file, 'w') as fhtml:
>>>     fhtml.write(html_code)