firecrown.fctools.coverage_to_tsv
Convert pytest-cov JSON coverage data to TSV format.
This script reads a coverage.json file generated by pytest-cov and extracts key information into a tab-separated values (TSV) file for easy analysis.
Attributes
Classes
Structure for holding coverage data for a single function. |
Functions
|
Parse timing data from pytest --durations output or JSON file. |
|
Try to match a test name to a function for timing correlation. |
|
Extract coverage information from the JSON data, optionally including timing. |
|
Write the extracted data to a TSV file. |
|
Convert pytest-cov JSON coverage data to TSV format. |
Module Contents
- class firecrown.fctools.coverage_to_tsv.CoverageRecord[source]
Bases:
NamedTuple
Structure for holding coverage data for a single function.
- file_path: str
- function_name: str
- covered_lines: int
- total_statements: int
- percent_covered: float
- missing_lines: int
- excluded_lines: int
- num_branches: int
- covered_branches: int
- missing_branches: int
- num_partial_branches: int
- percent_covered_display: str
- file_total_statements: int
- file_covered_lines: int
- file_percent_covered: float
- test_duration: float | None = None
- firecrown.fctools.coverage_to_tsv.parse_timing_data(console, timing_file)[source]
Parse timing data from pytest –durations output or JSON file.
- Args:
console: The rich console object. timing_file: Path to timing data file (JSON or text output)
- Returns:
Dictionary mapping test names to duration in seconds
- Parameters:
console (rich.console.Console)
timing_file (pathlib.Path | None)
- Return type:
dict[str, float]
- firecrown.fctools.coverage_to_tsv.match_test_to_function(test_name, function_name, file_path)[source]
Try to match a test name to a function for timing correlation.
- Args:
test_name: Full test identifier (like “tests/test_mod.py::test_method”) function_name: Function name from coverage data file_path: File path from coverage data
- Returns:
Relevance score (0.0 to 1.0) for the match
- Parameters:
test_name (str)
function_name (str)
file_path (str)
- Return type:
float
- firecrown.fctools.coverage_to_tsv.extract_coverage_data(coverage_data, timing_data=None)[source]
Extract coverage information from the JSON data, optionally including timing.
- Args:
coverage_data: The loaded JSON coverage data timing_data: Optional dictionary of test timing data
- Returns:
List of CoverageRecord objects containing detailed coverage information
- Parameters:
coverage_data (dict[str, Any])
timing_data (dict[str, float] | None)
- Return type:
list[CoverageRecord]
- firecrown.fctools.coverage_to_tsv.write_tsv_file(data, output_file)[source]
Write the extracted data to a TSV file.
- Args:
data: List of CoverageRecord objects with coverage data output_file: Path to output TSV file
- Parameters:
data (list[CoverageRecord])
output_file (pathlib.Path)
- Return type:
None
- firecrown.fctools.coverage_to_tsv.app
- firecrown.fctools.coverage_to_tsv.main(input_file=typer.Argument(..., exists=True, file_okay=True, dir_okay=False, readable=True, resolve_path=True, help='Path to the input JSON coverage file'), output_file=typer.Argument('coverage_data.tsv', help='Path to the output TSV file', writable=True, resolve_path=True), timing=typer.Option(None, '--timing', exists=True, file_okay=True, dir_okay=False, readable=True, resolve_path=True, help='Optional path to timing data file (JSON from pytest-json-report or text from pytest --durations)'))[source]
Convert pytest-cov JSON coverage data to TSV format.
This tool reads a JSON file containing pytest-cov coverage data and converts it to a tab-separated values (TSV) format. The output includes details about file coverage, function coverage, and missing line information.
Examples: coverage_to_tsv.py coverage.json
coverage_to_tsv.py coverage.json output.tsv
coverage_to_tsv.py coverage.json output.tsv –timing timing.txt
coverage_to_tsv.py /path/to/coverage.json /path/to/output.tsv \ –timing timing.json
- Parameters:
input_file (pathlib.Path)
output_file (pathlib.Path)
timing (pathlib.Path)
- Return type:
None