flitsr.spectrum.Spectrum¶
- class flitsr.spectrum.Spectrum(elements: List[Spectrum.Element], groups: List[Spectrum.Group], tests: List[Spectrum.Test], executions: Dict[Test, Set[Spectrum.Element]])¶
Bases:
objectAn implementation for a program spectrum.
- __init__(elements: List[Spectrum.Element], groups: List[Spectrum.Group], tests: List[Spectrum.Test], executions: Dict[Test, Set[Spectrum.Element]])¶
Methods
__init__(elements, groups, tests, executions)elements()Get a list of a all the elements in this spectrum
failing()Get a list of a all the failing tests in this spectrum
get_executed_elements(test)Return the set of elements that are executed in the given
test.get_executed_groups(test)Return the set of groups that are executed in the given
test.Returns a dictionary of all the faults in this spectrum, with the values being all the locations of each fault.
get_group(element)Given an element, return the
Spectrum.Groupwith identical coverage from this spectrum that this element is apart of.get_removed_tests([bucket])Return a copy of all the removed tests in a particular bucket.
get_tests(entity[, only_failing, remove, bucket])Finds all the test cases executing the given element, and (optionally) removes them from the spectrum.
groups()Get a list of a all the groups in this spectrum
locs()Get the number of groups in this spectrum
remove_execution(test, ent[, hard])Remove the execution of the given
Spectrum.Entityintest.remove_group(group[, bucket])Remove the given group from the spectrum, and store it in the given bucket.
remove_test(test[, bucket])Remove the given test from this spectrum.
reset([bucket])Re-activates removed tests and recomputes counts.
reset_single_test(test[, bucket])Reset a single test that was stored in the given bucket.
search_elements(name_part[, groups])Searches for any element that matches the partial element name name_part.
search_tests(name_part[, incl_removed])Searches for any test that matches the partial test name name_part.
tests()Get a list of a all the tests (passing and failing) in this spectrum
Converts the current spectrum into a numpy matrix and error vector.
- class Element(details: List[str], index: int, faults: List[Any])¶
Bases:
EntityAn element object holds information pertaining to a single spectral element (line, method, class, etc…).
- faults¶
- hash¶
- index() int¶
Returns the index of this
Spectrum.Element
- isFaulty() bool¶
Returns whether or not this
Spectrum.Elementpertains to a fault
- line¶
- method¶
- output_str(type_: InputType, incl_faults=True) str¶
Returns the string representation of this
Spectrum.Elementthat can be used when writing out the spectrum in the given input type.- Parameters:
type – ‘InputType’: The input type to render the output string for.
incl_faults – (Default value = True) Whether to include fault indicators in the output string
- Returns:
The string representation of this
Spectrum.Element
- path¶
- semantic_eq(other) bool¶
Variant of the __eq__ method for an
Spectrum.Elementthat checks whether two elements are semantically equivalent.- Parameters:
other – The element to compare to
- Returns:
True if this
Spectrum.Elementis equal to other, False otherwise.
- tup¶
- class Entity¶
Bases:
ABC,IterableA generic spectrum
Spectrum.Entity. This is the base class forSpectrum.ElementandSpectrum.Groupin the spectrum.- abstractmethod index() int¶
The index of this
Spectrum.Entity
- abstractmethod isFaulty() bool¶
Returns whether or not this
Spectrum.Entitypertains to a fault
- class Execution(test: Test, spectrum: Spectrum)¶
Bases:
objectThe Execution object holds all of the spectral information pertaining to the execution of a particular test.
- element_get(elem: Element, default: bool = False) bool¶
Similar to the
getmethod, but takes anSpectrum.Elementinstead of aSpectrum.Group.- Parameters:
elem – Spectrum.Element: The
Spectrum.Elementto lookup.default – bool: (Default value = False) The default value if
Spectrum.Execution. (elem has no execution information in this)
- Returns:
The execution information for elem if the
Spectrum.Groupof elem is found, default otherwise.
- exec¶
- get(group: Group, default: bool = False) bool¶
Return the execution for the given group if it is available, else default.
- Parameters:
group – Spectrum.Group: The
Spectrum.Groupto lookup.default – bool: (Default value = False) The default value if group has no execution information in this
Spectrum.Execution.
- Returns:
The execution information for group if group is found, default otherwise.
- test¶
- class Group(elems: List[Element] | None = None, index: int | None = None)¶
Bases:
EntityA spectral group is a collection of spectral elements which have identical spectra.
- index() int¶
Get the index of this Group if available, otherwise raise an
UnboundLocalError.
- isFaulty() bool¶
Returns whether or not an element in this
Spectrum.Grouppertains to a fault
- is_subgroup(group: Group) bool¶
Return whether the given group is a subgroup of this
Spectrum.Group. :param group: Spectrum.Group: The group to check.- Returns:
True if group is a subgroup of this
Spectrum.Group, False otherwise.
- set_index(index: int)¶
Set the index of this group. Used for spectrum execution lookup. NOTE: the group index MUST be unique for each group in a given spectrum. :param index: int: The integer
- sort_elems(key: Callable)¶
Sort the elements in this group by the given key. :param key: Callable: The key to sort by
- class Test(name: str, index: int, outcome: Outcome)¶
Bases:
objectA test object holds information pertaining to a particular test.
- index¶
- name¶
- outcome¶
- get_executed_elements(test: Test) Set[Element]¶
Return the set of elements that are executed in the given
test.- Parameters:
test – Spectrum.Test: The test whose executed elements to return.
- Returns:
The set of
Spectrum.Elementthat are executed in the giventest.
- get_executed_groups(test: Test) Set[Group]¶
Return the set of groups that are executed in the given
test.- Parameters:
test – Spectrum.Test: The test whose executed groups to return.
- Returns:
The set of
Spectrum.Groupthat are executed in the giventest.
- get_faults() Dict[Any, Set[Element]]¶
Returns a dictionary of all the faults in this spectrum, with the values being all the locations of each fault.
- get_group(element: Element) Group¶
Given an element, return the
Spectrum.Groupwith identical coverage from this spectrum that this element is apart of.- Parameters:
element – Spectrum.Element: The
Spectrum.Elementto find theSpectrum.Groupof.- Returns:
The group that the element belongs to.
- Raises:
KeyError – If the element does not belong to any group in this spectrum.
- get_removed_tests(bucket='default') List[Test]¶
Return a copy of all the removed tests in a particular bucket. If bucket is None, all removed tests from all buckets are returned.
- Parameters:
bucket – (Default value = ‘default’) The bucket to look for removed tests to return.
- Returns:
A
Listof all theSpectrum.Testthat were in the given bucket, or in all buckets if bucket is None.
- get_tests(entity: Entity, only_failing=False, remove=False, bucket='default') Set[Test]¶
Finds all the test cases executing the given element, and (optionally) removes them from the spectrum. If removing tests from the spectrum, an optional bucket name may also be given.
- Parameters:
entity – Spectrum.Entity: The entity to find tests for.
only_failing – (Default value = False) Whether to return only tests that are failing.
remove – (Default value = False) Whether to remove the found tests from the spectrum before returning them.
bucket – (Default value = ‘default’) The bucket to add the tests to if they are removed from the spectrum.
- Returns:
The set of
Spectrum.Testthat entity is executed in.
- locs() int¶
Get the number of groups in this spectrum
- remove_execution(test: Test, ent: Entity, hard=True)¶
Remove the execution of the given
Spectrum.Entityintest.- Parameters:
test – Spectrum.Test: The test to remove the execution of ent from.
ent – Spectrum.Entity: The
Spectrum.Entitywhose execution to remove.hard – (Default value = True) Whether to remove this execution fully, i.e. even from the underlying spectrum
- remove_group(group: Group, bucket='default')¶
Remove the given group from the spectrum, and store it in the given bucket. See
Spectrum.remove_testfor a description of buckets.- Parameters:
group – Spectrum.Group: The
Spectrum.Groupto remove.bucket – (Default value = ‘default’) The bucket to store the group in for later retrieval.
- remove_test(test: Test, bucket='default')¶
Remove the given test from this spectrum. All removed tests are stored so that they may be added back to the spectrum at a later point. By default, removed tests are stored in the ‘default’ bucket, but a different bucket name may be optionally given. Setting the bucket to be None will completely remove the test from the spectrum (NOTE: this does not save much memory, but only prevents the test from being restored by subsequent calls to reset).
- Parameters:
test – Spectrum.Test: The
Spectrum.Testto remove.bucket – (Default value = ‘default’) The bucket to store the removed tests in.
- reset(bucket: None | str | List[str] = None)¶
Re-activates removed tests and recomputes counts. By default, or if bucket is None, all buckets are emptied and their removed tests reactivated. A bucket name (or Iterable of bucket names) may optionally be given to only reset the given name(s).
- Parameters:
bucket – Union[None: str: List[str]]: (Default value = None) The bucket to reset.
- reset_single_test(test: Test, bucket: str | None = None)¶
Reset a single test that was stored in the given bucket. See the
Spectrum.resetmethod, which is the iterative form of this one.- Parameters:
test – Spectrum.Test: The
Spectrum.Testto reset.bucket – Optional[str]: (Default value = None) The bucket that
testis in, orNoneto check all buckets.
- Raises:
KeyError – If the test could not be found in the given bucket.
- search_elements(name_part, groups=False) List[Element | Group]¶
Searches for any element that matches the partial element name name_part. Returns a list of all the matches.
- Parameters:
name_part – The partial name of an entity to search for.
groups – (Default value = False) Whether to search for
Spectrum.GrouporSpectrum.Element.
- Returns:
A list of all the entitied that match name_part.
- search_tests(name_part, incl_removed=False) List[Test]¶
Searches for any test that matches the partial test name name_part. Returns a list of all the matches.
- Parameters:
name_part – The partial name of a test to search for.
incl_removed – (Default value = False) Whether to include tests that have been removed.
- Returns:
A list of all the tests that match name_part.
- tf: int¶
- to_matrix() Tuple[ndarray, ndarray]¶
Converts the current spectrum into a numpy matrix and error vector.
- Returns:
A numpy matrix representing the spectrum, and numpy array representing the error vector.
- tp: int¶