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.

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

Class diagram orchestrata_tools.models.test_models

Dependency diagram

Dependency diagram orchestrata_tools.models.test_models

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

Permalink: https://gitlab.com/MSamy/orchestrata-ultimate-architecture/-/blob/a4cbc2bdf/src/orchestrata_tools/models/test_models.py

"""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)