mlrl.testbed.format module

Author: Michael Rapp (michael.rapp.ml@gmail.com)

Provides utility functions for creating textual representations.

class mlrl.testbed.format.Formatter(option: str, name: str, percentage: bool = False)

Bases: object

Allows to create textual representations of values.

format(value, **kwargs) str

Creates and returns a textual representation of a given value.

Parameters:

value – The value

Returns:

The textual representation that has been created

mlrl.testbed.format.filter_formatters(formatters: List[Formatter], options: List[Options]) List[Formatter]

Allows to filter a list of Formatter objects.

Parameters:
  • formatters – A list of Formatter objects

  • options – A list of Options objects that should be used for filtering

Returns:

A filtered list of the given Formatter objects

mlrl.testbed.format.format_duration(duration: float) str

Creates and returns a textual representation of a duration.

Parameters:

duration – The duration in seconds

Returns:

The textual representation that has been created

mlrl.testbed.format.format_float(value: float, decimals: int = 2) str

Creates and returns a textual representation of a floating point value using a specific number of decimals.

Parameters:
  • value – The value

  • decimals – The number of decimals to be used or 0, if the number of decimals should not be restricted

Returns:

The textual representation that has been created

mlrl.testbed.format.format_percentage(value: float, decimals: int = 2) str

Creates and returns a textual representation of a percentage using a specific number of decimals.

Parameters:
  • value – The percentage

  • decimals – The number of decimals to be used or 0, if the number of decimals should not be restricted

Returns:

The textual representation that has been created

mlrl.testbed.format.format_table(rows, header=None, alignment=None) str

Creates and returns a textual representation of tabular data.

Parameters:
  • rows – A list of lists that stores the tabular data

  • header – A list that stores the header columns

  • alignment – A list of strings that specify the alignment of the corresponding colum as either ‘left’, ‘center’, or ‘right’

Returns:

The textual representation that has been created