Result Parsers

Table of Contents

Result Parsers

This module contains the base Result Parser plugin class.

class pavilion.result_parsers.ResultParser(name, description, open_mode='r', priority=10)

Bases: yapsy.IPlugin.IPlugin

Base class for creating a result parser plugin. These are essentially a callable that implements operations on the test or test files. The arguments for the callable are provided automatically via the test config. The doc string of result parser classes is used as the user help text for that class, along with the help from the config items.

KEY_REGEX_STR = '^[a-zA-Z0-9_-]+$'
PRIO_COMMON = 10
PRIO_CORE = 0
PRIO_USER = 20
__call__(test, file, **kwargs)

This is where the result parser is actually implemented.

Parameters:
  • test (pavilion.test_run.TestRun) – The test run object.
  • file – This will be a file object or a string, depending on the parser’s ‘open_mode’ setting in __init__.
  • kwargs (dict) – The arguments are the config values from the the test’s result config section for this parser. These should be explicitly defined in your result parser class.
Raises:

ResultParserError – When something goes wrong.

__init__(name, description, open_mode='r', priority=10)

Initialize the plugin object

Parameters:
  • name (str) – The name of this plugin.
  • description (str) – A short description of this result parser.
  • None] open_mode (Union[str,) – How to open each file handed to the parser. None denotes that a path rather than a file object is expected.
  • priority (int) – The priority of this plugin, compared to plugins of the same name. Higher priority plugins will supersede others.
__module__ = 'pavilion.result_parsers'
_check_args(**kwargs)

Override this to add custom checking of the arguments at test kickoff time. This prevents errors in your arguments from causing a problem in the middle of a test run. The yaml_config module handles structural checking (and can handle more). This should raise a descriptive ResultParserError if any issues are found.

Parameters:kwargs – Child result parsers should override these with specific kwargs for their arguments. They should all default to and rely on the config parser to set their defaults.
Raises:ResultParserError – If there are bad arguments.
activate()

Yapsy runs this when adding the plugin.

In this case it:

  • Adds the config section (from get_config_items()) to the test config format.
  • Adds the result parser to the list of known result parsers.
check_args(**kwargs)

Check the arguments for any errors at test kickoff time, if they don’t contain deferred variables. We can’t check tests with deferred args. On error, should raise a ResultParserError.

Parameters:kwargs (dict) – The arguments from the config.
Raises:ResultParserError – When bad arguments are given.
deactivate()

Yapsy calls this to remove this plugin. We only ever do this in unittests.

get_config_items()

Get the config for this result parser. This should be a list of yaml_config.ConfigElement instances that will be added to the test config format at plugin activation time. The simplest format is a list of yaml_config.StrElem objects, but any structure is allowed as long as the leaf elements are StrElem type.

The config values will be passed as the keyword arguments to the result parser when it’s run and when its arguments are checked. The base implementation provides several arguments that must be present for every result parser. See the implementation of this method in result_parser.py for more info on those arguments and what they do.

Example:

config_items = super().get_config_items()
config_items.append(
    yaml_config.StrElem('token', default='PASSED',
        help="The token to search for in the file."
)
return config_items
help()

Return a formatted help string for the parser.

path

The path to the file containing this result parser plugin.

exception pavilion.result_parsers.ResultParserError

Bases: RuntimeError

Error thrown when the result parser fails.

pavilion.result_parsers.check_args(parser_configs)

Make sure the result parsers are sensible.

  • No duplicated key names.
  • Sensible keynames: /[a-z0-9_-]+/
  • No reserved key names.
Raises:TestRunError – When a config breaks the rules.
pavilion.result_parsers.get_plugin(name)

Get the result plugin parser called name.

Parameters:name (str) – The name of the result parser plugin to return.
Return type:ResultParser
pavilion.result_parsers.list_plugins()

Return a list of result parser plugin names.

pavilion.result_parsers.parse_results(test, results)

Parse the results of the given test using all the result parsers configured for that test.

  • Find the result parser
  • Parse results for each found file via the ‘files’ attr.
  • Save those results (for each file) according to the ‘action’ attr.
  • Combine file results into a single object with the ‘per_file’ attr and add them to the results dict.
Parameters:
  • test (pavilion.test_run.TestRun) – The pavilion test run to gather results for.
  • results (dict) – The dictionary of default result values.
Returns:

The final results dictionary.