flitsr.spectrumBuilder.SpectrumBuilder

class flitsr.spectrumBuilder.SpectrumBuilder(collapse_methods: bool = False, allow_duplicates: DuplicateStrategy | None = None)

Bases: object

Builds a Spectrum object.

__init__(collapse_methods: bool = False, allow_duplicates: DuplicateStrategy | None = None)

Constructs a SpectrumBuilder object to facilitate building a Spectrum.

Parameters:

collapse_methods – bool: (Default value = False) Whether to form a method level spectrum.

Methods

__init__([collapse_methods, allow_duplicates])

Constructs a SpectrumBuilder object to facilitate building a Spectrum.

addElement(details, faults[, index])

Add a new element to the spectrum, with the given details and faults.

addExecution(test, elem)

Mark the specified element as executed in the given test.

addNonExecution(test, elem)

Mark the specified element as not executed in the given test.

addTest(name, outcome[, index])

Add a new test to the spectrum with the given name, index, and outcome.

form_groups()

Given one test pertaining to a row in the spectrum, split the groups according to the coverage.

getElement(index)

Retreive the element with the specified index.

get_spectrum()

Return the spectrum from this SpectrumBuilder.

get_tests()

Return the current list of Tests.

addElement(details: Details | List[str], faults: List[Any], index: int = None) Element

Add a new element to the spectrum, with the given details and faults. Note: the allow_duplicates parameter to the __init__ method will determine if duplicates are retained.

Parameters:
  • details

    The details of the element, either as a flitsr.spectrum.Details object, or a List of strings. The list of strings, if given, MUST contain at least one string, and conform to one of the following:

    [<name>]
    [<path>, <method>]
    [<path>, <line num>]
    [<path>, <method>, <line num>]
    

  • faults – The list of faults that this element pertains to, or an empty list if this element does not pertain to any faults.

  • index – The (optional) index of this element.

Returns:

The created element.

Changed in version 2.5: Added the option to use the flitsr.spectrum.Details object for the details parameter

addExecution(test: Test | int, elem: Element | int)

Mark the specified element as executed in the given test.

Parameters:
  • test – Union[Spectrum.Test, int]: The test to add the execution to. Can be either a Test object OR an integer representing a valid index of a Test.

  • elem – Union[Spectrum.Element, int]: The element to add the execution for. Can be either an Element object OR an integer representing a valid Element index.

Raises:
  • TestKeyError – When test is an int and does not refer to a valid test index.

  • ElemKeyError – When elem is an int and does not refer to a valid element index.

addNonExecution(test: Test, elem: Element)

Mark the specified element as not executed in the given test. NOTE: Adding non-executions is not required for the spectrum (non-execution is assumed by default), thus this method does not do anything.

Deprecated since version 2.2: There is no need to call this function anymore as non-executions are not stored by default.

Parameters:
  • test – Spectrum.Test: The Test to add the non-execution to.

  • elem – Spectrum.Element: The Element to add to non-execution of.

addTest(name: str, outcome: Outcome, index: int = None)

Add a new test to the spectrum with the given name, index, and outcome.

Parameters:
  • name – The name of the test.

  • index – (Default value = None) A unique identifier for this test.

  • outcome – The outcome (pass/fail) of the test.

form_groups() List[Group]

Given one test pertaining to a row in the spectrum, split the groups according to the coverage. The split will potentially split each group in half, based on those elements that are executed in the test, and those that are not.

getElement(index: int)

Retreive the element with the specified index.

Parameters:

index – int: The index of the element to retrieve.

Returns:

The Element corresponding to the index given.

Raises:

KeyError – If the index does not correspond to an element.

get_spectrum() Spectrum

Return the spectrum from this SpectrumBuilder.

get_tests() List[Test]

Return the current list of Tests.