orchestrata_tools.models.test_models
Reference › orchestrata_tools › models › test_models
This module holds the data classes for test analysis and coverage reporting, produced by matcher and coverage.
MatchStrategyis a string enum naming how a test was tied to a source method. Its twelve members areclass_exact,global_exact,suffix_prefix,compound_exact,compound_substring,substring,word_level,import_word,prefix_stripped,import_substring,global_substringandbody_call, each documented by an example name pattern.TestEntryis one test function or method, with module, name and optional class;target_namestrips thetest_prefix.TestMatchlinks aTestEntryto aMethodInfowith a strategy and a confidence from 1 to 10.CoverageGapis an untested method with its module, class and a suggested test name.CoverageReportholds totals, method and class coverage percentages, the gaps, and per-module coverage.
At a glance
| Source | src/orchestrata_tools/models/test_models.py |
| Lines of code | 76 |
| Classes | 5 |
| Functions | 0 |
| Imports (internal) | orchestrata_tools.models.ast_models |
| Imported by | orchestrata_tools.models, orchestrata_tools.test_analyzer.coverage, orchestrata_tools.test_analyzer.matcher |
| Tests that import it | tests/test_orchestrata_tools.py, tests/test_orchestrata_tools_matcher.py |
Class diagram
Dependency diagram
API
Classes
MatchStrategy (enum)
Bases: StrEnum · Line 13
Strategy used to match a test to a source method.
| Member | Value |
|---|---|
CLASS_EXACT |
'class_exact' |
GLOBAL_EXACT |
'global_exact' |
SUFFIX_PREFIX |
'suffix_prefix' |
COMPOUND_EXACT |
'compound_exact' |
COMPOUND_SUBSTRING |
'compound_substring' |
SUBSTRING |
'substring' |
WORD_LEVEL |
'word_level' |
IMPORT_WORD |
'import_word' |
PREFIX_STRIPPED |
'prefix_stripped' |
IMPORT_SUBSTRING |
'import_substring' |
GLOBAL_SUBSTRING |
'global_substring' |
BODY_CALL |
'body_call' |
TestEntry (dataclass)
Decorators: dataclass · Line 33
A single test function or method.
| Attribute | Type | Default |
|---|---|---|
name |
str |
|
module |
str |
|
class_name |
str | None |
None |
| Method | Signature | Summary |
|---|---|---|
target_name property |
target_name() -> str |
The part after 'test_'. |
TestMatch (dataclass)
Decorators: dataclass · Line 47
A match between a test and a source method.
| Attribute | Type | Default |
|---|---|---|
test_entry |
TestEntry |
|
method |
MethodInfo |
|
strategy |
MatchStrategy |
|
confidence |
int |
CoverageGap (dataclass)
Decorators: dataclass · Line 57
An untested method with context.
| Attribute | Type | Default |
|---|---|---|
method |
MethodInfo |
|
module_path |
str |
|
class_name |
str |
|
suggested_test_name |
str |
'' |
CoverageReport (dataclass)
Decorators: dataclass · Line 67
Overall coverage metrics.
| Attribute | Type | Default |
|---|---|---|
total_methods |
int |
0 |
tested_methods |
int |
0 |
untested_methods |
int |
0 |
method_coverage_pct |
float |
0.0 |
class_coverage_pct |
float |
0.0 |
gaps |
list[CoverageGap] |
field(default_factory=list) |
module_coverage |
dict[str, float] |
field(default_factory=dict) |
Source
"""Models for test analysis and coverage reporting."""
from __future__ import annotations
from dataclasses import dataclass, field
from enum import StrEnum
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from orchestrata_tools.models.ast_models import MethodInfo
class MatchStrategy(StrEnum):
"""Strategy used to match a test to a source method."""
CLASS_EXACT = "class_exact" # test_foo in TestClass -> foo in Class
GLOBAL_EXACT = "global_exact" # test_foo -> foo (import-filtered)
SUFFIX_PREFIX = "suffix_prefix" # test_foo_bar -> foo in Class
COMPOUND_EXACT = "compound_exact" # test_save_and_load -> save + load
COMPOUND_SUBSTRING = (
"compound_substring" # test_save_and_load -> save_thread + load_thread
)
SUBSTRING = "substring" # test_history -> get_dispatch_history
WORD_LEVEL = "word_level" # test_stats_empty -> get_session_stats
IMPORT_WORD = "import_word" # top-level test with imported class word match
PREFIX_STRIPPED = "prefix_stripped" # test_grpc_client_send -> send
IMPORT_SUBSTRING = "import_substring"
GLOBAL_SUBSTRING = "global_substring"
BODY_CALL = "body_call" # Test body calls source method directly
@dataclass
class TestEntry:
"""A single test function or method."""
name: str
module: str
class_name: str | None = None
@property
def target_name(self) -> str:
"""The part after 'test_'."""
return self.name[5:] if self.name.startswith("test_") else self.name
@dataclass
class TestMatch:
"""A match between a test and a source method."""
test_entry: TestEntry
method: MethodInfo
strategy: MatchStrategy
confidence: int # 1-10, higher is more confident
@dataclass
class CoverageGap:
"""An untested method with context."""
method: MethodInfo
module_path: str
class_name: str
suggested_test_name: str = ""
@dataclass
class CoverageReport:
"""Overall coverage metrics."""
total_methods: int = 0
tested_methods: int = 0
untested_methods: int = 0
method_coverage_pct: float = 0.0
class_coverage_pct: float = 0.0
gaps: list[CoverageGap] = field(default_factory=list)
module_coverage: dict[str, float] = field(default_factory=dict)