testplan.common.exporters package

Submodules

testplan.common.exporters.constants module

testplan.common.exporters.pdf module

Utilities for generating pdf files via Reportlab.

class testplan.common.exporters.pdf.RowData(num_columns, start=0, content=None, style=None)[source]

Bases: object

Container object that represents one or more Table rows.

Manages row index implicitly, supports custom styling via RowStyle objects.

append(content, style=None)[source]

Append one or more rows to the current row data, with the given styles.

>>> # Let's say we have 2 more rows created previously.
>>> row_data = RowData(start=2, num_columns=4)
>>> # # create new row data with red text.
>>> row_data.append('hello', style=RowStyle(text_color=colors.red))
>>> row_data.append(
        content=[
            [
                'first column',
                'second column',
                'third column',
                'fourth column'
            ],
            [
                'second line first column',
                '',
                '',
                'second line fourth column']
            ],
        style=[
            # Applies to all columns
            RowStyle(font=('Helvetica', 8)),
            # Applies to last column only (0, 1, 2, [3])
            RowStyle(text_color=colors.green, start_column=3)
        ]
    )
Parameters:
  • content – Row(s) to be added.
  • style (RowStyle or list of RowStyle) – Style context for the given content.
Returns:

None

Return type:

NoneType

end

End index of the current row data, will keep increasing as more content is added.

start

Start index of the current row data.

style

Return Reportlab compatible styles (commands) from the RowStyle objects.

class testplan.common.exporters.pdf.RowStyle(start_column: int = 0, end_column: int = -1, start_row: int = None, end_row: int = None, **style_props)[source]

Bases: object

Helper class for managing styles for table rows.

In Reportlab, table rows are styled using commands like:

[
    (
        'BOTTOMPADDING',
        (<start_column>, <start_row>),
        (<end_column>, <end_row>),
        5
    ),
    (
        'FONT',
        (<start_column>, <start_row>),
        (<end_column>, <end_row>),
        'Helvetica',
        12
    ),
    (
        'LEFTPADDING',
        (<start_column>, <start_row>),
        (<end_column>, <end_row>),
        5
    )
]

This gets messy as we have to repeat row & column indexes for each command. For the styling example above, the equivalent declaration would be:

>>> row_style = RowStyle(
        bottom_padding=5,
        font=('Helvetica', 12),
        left_padding=5,
        start_column=<start_column>,
        end_column=<end_column>
    )
>>> row_style.start_row = 10  # This is set by row data later
>>> row_style.end_row = 15  # This is set by row data later
>>> row_style.get_commands()

Normally we’ll just provide the column indexes and row indexes will be provided implicitly by the RowData object that makes use of this style.

More info: https://www.reportlab.com/docs/reportlab-userguide.pdf

end_column
end_row
get_commands() → tuple[source]

Return Reportlab compliant styling commands.

>>> row_style = RowStyle(
  bottom_padding=5, start_column=1, end_column=3)
>>> row_style.start_row, row_style.end_row = 10, 20
>>> row_style.get_commands()
(('BOTTOMPADDING', (1, 10), (3, 20), 5))
start_column
start_row
testplan.common.exporters.pdf.create_base_tables(data, style, col_widths, max_rows=1000)[source]

Create tables for the specified data and style commands, partitioning where necessary.

Parameters:
  • data (list of list) – the table data
  • style (list of tuple) – the style commands
  • col_widths (iterable) – column widths for the new tables
  • max_rows (int) – the maximum number of rows in each table
Returns:

a list of new tables

Return type:

list of Table

testplan.common.exporters.pdf.create_table(table, columns, row_indices, display_index, max_width, style, colour_matrix=None)[source]

Create a ReportLab table from a serialized entry. Table features are:

  • Cell values (rows and columns) cannot exceed the maximum number of characters (constanst.CELL_STRING_LENGTH). Values will stop before this maximum and be appended with ‘…’.
  • If the number of rows exceeds the maximum (constants.NUM_DISPLAYED_ROWS) show the first half of the allowed rows, then a row of ‘…’, then the last half of the allowed rows. Also set the display_index parameter to True.
  • If the table is too wide to fit onto the page, split the tables columns into multiple rows. Also set the display_index parameter to True.
Parameters:
  • table (list of dict) – The table containing all the data.
  • columns (list of str) – List of the column names, maintains the display order.
  • row_indices (list of int) – List of row indices for each row in the table.
  • display_index (bool) – If True display the row indices. This will automatically be set to True if the rows exceed the maximum allowed to display or the table is too wide (too many columns) to fit in a single table.
  • max_width (int) – The maximum allowed width the table can be.
  • style (list of tuple) – The style of the ReportLab table.
  • colour_matrix (list of list) – A matrix listing whether each cell has passed (P), failed (F) or ignored (I) which will result in the cell text being green, red or black respectively. If no matrix is passed all cells will be black.
Returns:

The formatted ReportLab table.

Return type:

list

testplan.common.exporters.pdf.format_cell_data(data, limit)[source]

Change the str representation of values in data if they represent regex or lambda functions. Also limit the length of these strings.

Parameters:
  • data (list) – List of values to be formatted.
  • limit (int) – The number of characters allowed in each string.
Returns:

List of formatted and limited strings.

Return type:

list

testplan.common.exporters.pdf.format_table_style(table_styles)[source]

Convert table style into a format ReportLab will accept.

Parameters:table_styles (list of testplan.common.exporters.pdf.RowStyle) – List of RowStyle objects defining the style of the ReportLab table.
Returns:List of styles formatted into tuples.
Return type:list of tuple

Module contents

TODO.

class testplan.common.exporters.BaseExporter(name=None, **options)[source]

Bases: testplan.common.config.base.Configurable

Base exporter class.

CONFIG

alias of ExporterConfig

cfg

Exporter configuration.

export(source: testplan.report.testing.base.TestReport, export_context: testplan.common.exporters.ExportContext) → Optional[Dict[KT, VT]][source]

Pseudo export function.

Param:source: Testplan report export
Param:export_context: information about other exporters
Returns:dictionary containing the possible output
name
class testplan.common.exporters.ExportContext(results: List[testplan.common.exporters.ExporterResult] = <factory>)[source]

Bases: object

Dataclass for storing information about exporters.

class testplan.common.exporters.ExporterConfig(**options)[source]

Bases: testplan.common.config.base.Config

Configuration object for BaseExporter object.

classmethod get_options()[source]

Override this classmethod to provide extra config arguments.

class testplan.common.exporters.ExporterResult(exporter: 'BaseExporter', result: Dict = None, traceback: str = None, uid: str = '8165200e-4b0e-45d4-ad13-d361b9d089e5', start_time: datetime.datetime = datetime.datetime(2024, 4, 19, 2, 2, 23, 5904, tzinfo=<UTC>), end_time: datetime.datetime = None)[source]

Bases: object

end_time = None
result = None
classmethod run_exporter(exporter, source, type)[source]

Putting this back for compatibility reasons

start_time = datetime.datetime(2024, 4, 19, 2, 2, 23, 5904, tzinfo=<UTC>)
success
traceback = None
uid = '8165200e-4b0e-45d4-ad13-d361b9d089e5'
testplan.common.exporters.run_exporter(exporter: testplan.common.exporters.BaseExporter, source: testplan.report.testing.base.TestReport, export_context: testplan.common.exporters.ExportContext) → testplan.common.exporters.ExporterResult[source]

Wraps an exporter run and handles exceptions.

Parameters:
  • exporter – exporter to run
  • source – Testplan report to export
  • export_context – ExportContext object for storing information about other exporters
testplan.common.exporters.verify_export_context(exporter: testplan.common.exporters.BaseExporter, export_context: Optional[testplan.common.exporters.ExportContext]) → testplan.common.exporters.ExportContext[source]

Verifies whether export context is present and creates an empty one if not.

Param:exporter: actual exporter being run
Param:export_context: information about other exporters
Returns:ExportContext object containing information about exporters