A unified interface for various code coverage tools (JaCoCo, dotnet-coverage)
Project description
CrossFit Coverage Tools
CrossFit is a Python package designed to provide a unified interface for various code coverage tools. It wraps the functionality of different coverage CLI tools, allowing developers to use a consistent API regardless of which underlying tool they prefer.
Installation
To install CrossFit, run:
pip install crossfit
Prerequisites
Before using CrossFit, ensure you have the following installed:
- Python 3.7 or higher
- Java Runtime Environment (JRE) - Required for JaCoCo integration
- The specific coverage tools you intend to use (e.g., JaCoCo, dotnet-coverage)
Supported Tools
CrossFit currently supports the following coverage tools:
- JaCoCo - Java-based code coverage tool
- dotnet-coverage - .NET coverage tool
- dotnet-reportgenerator - .NET report generation tool
Usage
CrossFit provides a unified interface for managing code coverage across different tools. Here's how to use it:
Basic Usage
from crossfit.tools.jacoco import Jacoco
# Initialize the JaCoCo tool
jacoco = Jacoco(tool_path="/path/to/jacoco")
# Save coverage report
result = jacoco.save_report(
coverage_files=["coverage.exec"],
target_dir="/output/directory",
sourcecode_dir="/source/code"
)
Key Features
- Unified Interface: Consistent API across different coverage tools
- Command Building: Automatic validation of required flags
- Coverage Management: Merge, snapshot, and save coverage data
- Error Handling: Comprehensive logging and error reporting
- Multiple Report Formats: Support for CSV, HTML, XML, and Cobertura formats
Example Workflow
from crossfit.tools.jacoco import Jacoco
from crossfit.models.tool_models import ReportFormat
# Initialize JaCoCo tool
jacoco = Jacoco(tool_path="/path/to/jacoco")
# Merge coverage files
merge_result = jacoco.merge_coverage(
coverage_files=["coverage1.exec", "coverage2.exec"],
target_dir="/output",
target_file="merged.exec"
)
# Generate HTML report
report_result = jacoco.save_report(
coverage_files=["merged.exec"],
target_dir="/reports",
sourcecode_dir="/src",
report_format=ReportFormat.Html
)
Package Structure
The package follows a modular structure:
crossfit/tools/jacoco.py: Implementation of JaCoCo tool wrappercrossfit/tools/dotnet_coverage.py: Implementation of .NET coverage tool wrappercrossfit/tools/tool.py: Base tool class and abstract methodscrossfit/models/tool_models.py: Enum definitions for tool types and report formatscrossfit/models/command_models.py: Command result models and command typescrossfit/commands/command.py: Command building and execution utilities
Core Components
Tool Models (crossfit/models/tool_models.py)
Defines the core enumerations used throughout the package:
-
ToolType: Enum representing supported tools
JacocoDotnetCoverageDotnetReportGenerator
-
ReportFormat: Enum representing supported report formats
CsvHtmlXmlCobertura
Command Models (crossfit/models/command_models.py)
Provides structured representations of command results:
-
CommandType: Enum defining command types
SaveReportSnapshotCoverageMergeCoverageResetCoverage
-
CommandResult: Pydantic model for command execution results with fields:
code: Exit code from command executioncommand: The executed command stringoutput: Standard output from commandtarget: Target path/file of operationerror: Error output from command
Command Builder (crossfit/commands/command.py)
Provides utilities for building and executing shell commands:
- Command: Class for constructing shell commands with:
- Execution call (e.g.,
java -jar) - Command keywords (e.g.,
dump,merge,report) - Options and arguments
- Path validation
- Delimiter handling for option-value pairs
- Execution call (e.g.,
Tool Implementations
JaCoCo Tool (crossfit/tools/jacoco.py)
Implements the JaCoCo coverage tool with methods:
save_report(): Generate coverage reports in various formatssnapshot_coverage(): Take coverage snapshotsmerge_coverage(): Merge multiple coverage files_get_command(): Build validated JaCoCo commands with required flag checking
DotNet Coverage Tool (crossfit/tools/dotnet_coverage.py)
Implements the .NET coverage tool with methods:
save_report(): Generate reports from coverage filesmerge_coverage(): Merge coverage datasnapshot_coverage(): Capture coverage snapshotsreset_coverage(): Reset coverage data
Advanced Usage
Working with Multiple Report Formats
from crossfit.tools.jacoco import Jacoco
from crossfit.models.tool_models import ReportFormat
jacoco = Jacoco(tool_path="/path/to/jacoco")
# Generate multiple report formats
result = jacoco.save_report(
coverage_files=["coverage.exec"],
target_dir="/reports",
sourcecode_dir="/src",
report_formats=[ReportFormat.Html, ReportFormat.Xml, ReportFormat.Cobertura]
)
Custom Command Arguments
from crossfit.tools.jacoco import Jacoco
jacoco = Jacoco(tool_path="/path/to/jacoco")
# Pass custom arguments to commands
result = jacoco.merge_coverage(
["coverage1.exec", "coverage2.exec"],
"/output", "merged.exec",
*["--format", "xml"] # Custom arguments
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file smokecrossfit-1.0.0a1.tar.gz.
File metadata
- Download URL: smokecrossfit-1.0.0a1.tar.gz
- Upload date:
- Size: 557.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
521a6acf700bbae97b22913c9f73193fe1394f8dc76dba409df129691b354a4a
|
|
| MD5 |
b4ab69f7f127dbe6d1da07088c2493a5
|
|
| BLAKE2b-256 |
0b59cf741bee561038ad26aa6180f2b78209aab61bb1c4637c49298552ea7136
|
Provenance
The following attestation bundles were made for smokecrossfit-1.0.0a1.tar.gz:
Publisher:
ci.yml on TheSmokeTeam/qaas-crossfit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smokecrossfit-1.0.0a1.tar.gz -
Subject digest:
521a6acf700bbae97b22913c9f73193fe1394f8dc76dba409df129691b354a4a - Sigstore transparency entry: 910279004
- Sigstore integration time:
-
Permalink:
TheSmokeTeam/qaas-crossfit@3dc0fbf3c37a1aba61143b6c543894f49ac66da4 -
Branch / Tag:
refs/tags/v1.0.0a1 - Owner: https://github.com/TheSmokeTeam
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@3dc0fbf3c37a1aba61143b6c543894f49ac66da4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file smokecrossfit-1.0.0a1-py3-none-any.whl.
File metadata
- Download URL: smokecrossfit-1.0.0a1-py3-none-any.whl
- Upload date:
- Size: 547.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23a16345106d1a5501dbaa0c48fcad37a8bfc99d091f5a9347024c51c5855e54
|
|
| MD5 |
85ce8ebe064a1c1d103ade40d8c577d0
|
|
| BLAKE2b-256 |
7c4e52f7379c9762870db03561aaa5fc5d93b6382cb778eaa9936a8850af5812
|
Provenance
The following attestation bundles were made for smokecrossfit-1.0.0a1-py3-none-any.whl:
Publisher:
ci.yml on TheSmokeTeam/qaas-crossfit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smokecrossfit-1.0.0a1-py3-none-any.whl -
Subject digest:
23a16345106d1a5501dbaa0c48fcad37a8bfc99d091f5a9347024c51c5855e54 - Sigstore transparency entry: 910279007
- Sigstore integration time:
-
Permalink:
TheSmokeTeam/qaas-crossfit@3dc0fbf3c37a1aba61143b6c543894f49ac66da4 -
Branch / Tag:
refs/tags/v1.0.0a1 - Owner: https://github.com/TheSmokeTeam
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@3dc0fbf3c37a1aba61143b6c543894f49ac66da4 -
Trigger Event:
push
-
Statement type: