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
orlist
ofRowStyle
) – Style context for the given content.
- Returns:
None
- Return type:
NoneType
- property end
End index of the current row data, will keep increasing as more content is added.
- property start
Start index of the current row data.
- property 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
- property end_column: int
- property end_row: int
- 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))
- property start_column: int
- property start_row: int
- 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
oflist
) – the table datastyle (
list
oftuple
) – the style commandscol_widths (
iterable
) – column widths for the new tablesmax_rows (
int
) – the maximum number of rows in each table
- Returns:
a list of new tables
- Return type:
list
ofTable
- 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
ofdict
) – The table containing all the data.columns (
list
ofstr
) – List of the column names, maintains the display order.row_indices (
list
ofint
) – 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
oftuple
) – The style of the ReportLab table.colour_matrix (
list
oflist
) – 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_table_style(table_styles)[source]
Convert table style into a format ReportLab will accept.
- Parameters:
table_styles (
list
oftestplan.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
oftuple
- testplan.common.exporters.pdf.split_line(line, max_width, get_width_func=None)[source]
Split line into multi-lines if width exceeds max_width.
- Parameters:
line – Line to be split.
max_width – Maximum length of each line (unit: px).
get_width_func – A function which computes width of string according to font and font size.
- Returns:
list of lines
- testplan.common.exporters.pdf.split_text(text, font_name, font_size, max_width, keep_leading_whitespace=False)[source]
Wraps text within given max_width limit (measured in px), keeping initial indentation of each line (and generated lines) if keep_leading_whitespace is True.
- Parameters:
text – Text to be split.
font_name – Font name.
font_size – Font size.
max_width – Maximum length of each line (unit: px).
keep_leading_whitespace – each split line keeps the leading whitespace.
- Returns:
list of lines
Module contents
TODO.
- class testplan.common.exporters.BaseExporter(name=None, **options)[source]
Bases:
Configurable
Base exporter class.
- CONFIG
alias of
ExporterConfig
- property cfg
Exporter configuration.
- export(source: TestReport, export_context: ExportContext) Dict | None [source]
Pseudo export function.
- Param:
source: Testplan report export
- Param:
export_context: information about other exporters
- Returns:
dictionary containing the possible output
- property name
- class testplan.common.exporters.ExportContext(results: ~typing.List[~testplan.common.exporters.ExporterResult] = <factory>)[source]
Bases:
object
Dataclass for storing information about exporters.
- results: List[ExporterResult]
- class testplan.common.exporters.ExporterConfig(**options)[source]
Bases:
Config
Configuration object for
BaseExporter
object.
- class testplan.common.exporters.ExporterResult(exporter: 'BaseExporter', result: Dict = None, traceback: str = None, uid: str = '21769bfb-c824-45b6-99d6-a2fe94637ef2', start_time: datetime.datetime = datetime.datetime(2025, 2, 11, 3, 27, 59, 836839, tzinfo=datetime.timezone.utc), end_time: datetime.datetime = None)[source]
Bases:
object
- end_time: datetime = None
- exporter: BaseExporter
- result: Dict = None
- classmethod run_exporter(exporter, source, type)[source]
Putting this back for compatibility reasons
- start_time: datetime = datetime.datetime(2025, 2, 11, 3, 27, 59, 836839, tzinfo=datetime.timezone.utc)
- property success: bool
- traceback: str = None
- uid: str = '21769bfb-c824-45b6-99d6-a2fe94637ef2'
- testplan.common.exporters.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.run_exporter(exporter: BaseExporter, source: TestReport, export_context: ExportContext) 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: BaseExporter, export_context: ExportContext | None) 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