Software Design

Class Diagram

@startuml
class WarningsPlugin {
    #checkerList : WarningsChecker
    +__init__(sphinx=False, doxygen=False, junit=False, verbose=False)
}

class WarningsChecker {
    #min_count = 0
    #max_count = 0
    #count = 0
    #verbose = False

    #{abstract} __init__(name, verbose=False)
    +set_limits(min_count=0, max_count=0,
    +{abstract}check(content)
    +get_count()
}

class RegexChecker {
    #{abstract} __init__(name, regex, verbose=False)
    +check(content)
}

class SphinxChecker {
    #{static} String name
    #{static} String regex
    +__init__(verbose=False)
}

class DoxyChecker {
    #{static} String name
    #{static} String regex
    +__init__(verbose=False)
}

class JUnitChecker {
    #{static} String name
    +__init__(verbose=False)
    +check(content)
}

WarningsPlugin o-- WarningsChecker
WarningsChecker <|-- RegexChecker
RegexChecker <|-- SphinxChecker
RegexChecker <|-- DoxyChecker
WarningsChecker <|-- JUnitChecker

@enduml

String Handling

Convention is to use plain python strings everywhere. Where needed the strings can be converted to anything else.

Example: junitparser expects byte array objects, so we encode our string right before passing it to junitparser.

Instrument Module

Melexis fork of warnings plugin

class mlx.warnings.CoverityChecker(verbose=False)[source]

Bases: RegexChecker

CLASSIFICATION = 'Unclassified'
check(content)[source]

Function for counting the number of warnings, but adopted for Coverity output

Parameters:

content (str) – The content to parse

name = 'coverity'
pattern = re.compile('(?:((?:[/.]|[A-Za-z]).+?):(-?\\d+):) (CID) \\d+ \\(#(?P<curr>\\d+) of (?P<max>\\d+)\\): (?P<checker>.+\\)): (?P<classification>\\w+), *(.+)\\n?')
class mlx.warnings.DoxyChecker(verbose=False)[source]

Bases: RegexChecker

name = 'doxygen'
pattern = re.compile('(?:(?P<path1>(?:[/.]|[A-Za-z]).+?):(?P<line1>-?\\d+):\\s*(?P<severity1>[Ww]arning|[Ee]rror)|<.+>:(?P<line2>-?\\d+)(?::\\s*(?P<severity2>[Ww]arning|[Ee]rror))?): (?P<description1>.+(?:(?!\\s*([Nn]otic)
class mlx.warnings.JUnitChecker(verbose=False)[source]

Bases: WarningsChecker

check(content)[source]

Function for counting the number of JUnit failures in a specific text

Parameters:

content (str) – The content to parse

name = 'junit'
static prepare_tree(root_input)[source]

Prepares the tree element by adding a testsuites element as root when missing (to please JUnitXml)

Parameters:

root_input (lxml.etree._Element/xml.etree.ElementTree.Element) – Top-level XML element from input file

Returns:

lxml.etree._Element/xml.etree.ElementTree.Element – Top-level XML element with testsuites tag

class mlx.warnings.RobotChecker(verbose=False)[source]

Bases: WarningsChecker

check(content)[source]

Function for counting the number of failures in a specific Robot Framework test suite

Parameters:

content (str) – The content to parse

checkers = []
property counted_warnings

list of counted warnings (str)

Type:

List

get_maximum()[source]

Gets the highest minimum amount of warnings

Returns:

int – the highest maximum for warnings

get_minimum()[source]

Gets the lowest minimum amount of warnings

Returns:

int – the lowest minimum for warnings

name = 'robot'
parse_config(config)[source]
return_check_limits()[source]

Function for checking whether the warning count is within the configured limits

Returns:

int

0 if the amount of warnings is within limits, the count of warnings otherwise

(or 1 in case of a count of 0 warnings)

return_count()[source]

Getter function for the amount of warnings found

Returns:

int – Number of warnings found

set_maximum(maximum)[source]

Setter function for the maximum amount of warnings

Parameters:

maximum (int) – maximum amount of warnings allowed

set_minimum(minimum)[source]

Setter function for the minimum amount of warnings

Parameters:

minimum (int) – minimum amount of warnings allowed

class mlx.warnings.RobotSuiteChecker(name, check_suite_name=False, **kwargs)[source]

Bases: JUnitChecker

check(content)[source]

Function for counting the number of JUnit failures in a specific text

The test cases with a classname that does not end with the name class attribute are ignored.

Parameters:

content (str) – The content to parse

Raises:

SystemExit – No suite with name self.name found. Returning error code -1.

return_count()[source]

Getter function for the amount of warnings found

Returns:

int – Number of warnings found

class mlx.warnings.SphinxChecker(verbose=False)[source]

Bases: RegexChecker

include_sphinx_deprecation()[source]

Adds the pattern for sphinx_deprecation_regex to the list patterns to include and alters the main pattern

name = 'sphinx'
pattern = re.compile('(?m)^(?:((?P<path1>.+?):(?P<line1>\\d+|None)?):?\\s*)?(?P<severity1>DEBUG|INFO|WARNING|ERROR|SEVERE|CRITICAL):\\s*(?P<description1>.+)$', re.MULTILINE)
sphinx_deprecation_regex = '(?m)^(?:(.+?:(?:\\d+|None)?):?\\s*)?(DEBUG|INFO|WARNING|ERROR|SEVERE|(?:\\w+Sphinx\\d+Warning)):\\s*(.+)$'
sphinx_deprecation_regex_in_match = 'RemovedInSphinx\\d+Warning'
class mlx.warnings.WarningsChecker(verbose=False)[source]

Bases: object

add_patterns(regexes, pattern_container)[source]

Adds regexes as patterns to the specified container

Parameters:
  • regexes (list[str]|None) – List of regexes to add

  • pattern_container (list[re.Pattern]) – Target storage container for patterns

abstract check(content)[source]

Function for counting the number of warnings in a specific text

Parameters:

content (str) – The content to parse

property counted_warnings

list of counted warnings (str)

Type:

List

property cq_description_template

string.Template instance based on the configured template string

Type:

Template

get_maximum()[source]

Getter function for the maximum amount of warnings

Returns:

int – Maximum amount of warnings

get_minimum()[source]

Getter function for the minimum amount of warnings

Returns:

int – Minimum amount of warnings

name = 'checker'
parse_config(config)[source]
print_when_verbose(message)[source]

Prints message only when verbose mode is enabled.

Parameters:

message (str) – Message to conditionally print

return_check_limits()[source]

Function for checking whether the warning count is within the configured limits

Returns:

int

0 if the amount of warnings is within limits, the count of warnings otherwise

(or 1 in case of a count of 0 warnings)

return_count()[source]

Getter function for the amount of warnings found

Returns:

int – Number of warnings found

set_maximum(maximum)[source]

Setter function for the maximum amount of warnings

Parameters:

maximum (int) – maximum amount of warnings allowed

Raises:

ValueError – Invalid argument (min limit higher than max limit)

set_minimum(minimum)[source]

Setter function for the minimum amount of warnings

Parameters:

minimum (int) – minimum amount of warnings allowed

Raises:

ValueError – Invalid argument (min limit higher than max limit)

exception mlx.warnings.WarningsConfigError[source]

Bases: Exception

class mlx.warnings.WarningsPlugin(verbose=False, config_file=None, cq_enabled=False)[source]

Bases: object

activate_checker(checker)[source]

Activate additional checkers after initialization

Parameters:

checker (WarningsChecker) – checker object

activate_checker_name(name)[source]

Activates checker by name

Parameters:

name (str) – checker name

Returns:

WarningsChecker – activated checker object, or None when no checker with the given name exists

check(content)[source]

Function for counting the number of warnings in a specific text

Parameters:

content (str) – The text to parse

config_parser(config)[source]

Parsing configuration dict extracted by previously opened JSON file

Parameters:

config (dict) – Content of configuration file

get_checker(name)[source]

Get checker by name

Parameters:

name (str) – checker name

Returns:

checker object (WarningsChecker)

return_check_limits(name=None)[source]

Function for determining the return value of the script

If the name parameter is set, this function will check (and return) the return value of that checker. If not, this function checks whether the warnings for each registered checker are within the configured limits.

Parameters:

name (WarningsChecker) – The checker for which to check the return value

Returns:

int

0 if the amount of warnings is within limits, the count of warnings otherwise

(or 1 in case of a count of 0 warnings)

return_count(name=None)[source]

Getter function for the amount of found warnings

If the name parameter is set, this function will return the amount of warnings found by that checker. If not, the function will return the sum of the warnings found by all registered checkers.

Parameters:

name (WarningsChecker) – The checker for which to return the amount of warnings (if set)

Returns:

int – Amount of found warnings

set_maximum(maximum)[source]

Setter function for the maximum amount of warnings

Parameters:

maximum (int) – maximum amount of warnings allowed

set_minimum(minimum)[source]

Setter function for the minimum amount of warnings

Parameters:

minimum (int) – minimum amount of warnings allowed

toggle_printout(printout)[source]

Toggle printout of all the parsed content

Useful for command input where we want to print content as well

Parameters:

printout (bool) – True enables the printout, False provides more silent mode

write_code_quality_report(out_file)[source]

Generates the Code Quality report artifact as a JSON file that implements a subset of the Code Climate spec

Parameters:

out_file (str) – Location for the output file

write_counted_warnings(out_file)[source]

Writes counted warnings to the given file

Parameters:

out_file (str) – Location for the output file

class mlx.warnings.XMLRunnerChecker(verbose=False)[source]

Bases: RegexChecker

name = 'xmlrunner'
pattern = re.compile('(\\s*(?P<severity1>ERROR|FAILED) (\\[\\d+\\.\\d{3}s\\]: \\s*(?P<description1>.+)))\\n?')
mlx.warnings.warnings_wrapper(args)[source]