Structural coverage for Python
Project description
cfgcoverage
A Python package to analyze and verify structural coverage criteria for Python programs using control-flow graphs (CFGs).
V0.1 — This is a very early, highly experimental version.
Installation
pip install cfgcoverage
🚀 How to Use
Analyzes the file foo.py, builds its control-flow graphs, and stores the internal analysis data in foo.py.cfg.
python -m cfgcoverage foo.py
Executes foo.py with instrumentation and records covered blocks and edges.
python -m cfgcoverage --run foo.py
Executes foo.py with arguments ['bar', '1972'] and records the covered structural requirements.
python -m cfgcoverage --run --args "bar 1972" foo.py
Cumulatively runs foo.py and aggregates structural coverage results across multiple executions.
python -m cfgcoverage --run --append foo.py
Runs foo.py using the test cases defined in test_foo.py.
The --unittest argument can be used multiple times. The --append option is also supported here.
python -m cfgcoverage --unittest test_foo.py foo.py
python -m cfgcoverage --unittest tests/test_foo.py src/foo.py
python -m cfgcoverage --unittest test_a.py --unittest test_b.py foo.py
You can also use one or more --path <folder path> arguments to include additional folders in sys.path when executing unit tests. In this way, imports will also be searched in these folders.
python -m cfgcoverage --path src --unittest tests/test_foo.py src/foo.py
python -m cfgcoverage --path src --path tests --unittest tests/test_foo.py src/foo.py
Creates an HTML report in html/foo.py/index.html using the data stored in foo.py.cfg.
python -m cfgcoverage --html foo.py
## 🔍 Example
```bash
python3 -m cfgcoverage example.py
Example output:
Function: foo -- 1
Function: foo.inner -- 2
Run time: 0.00052
python3 -m cfgcoverage --run example.py
Example output:
Run time: 0.00071
python3 -m cfgcoverage --unittest test_example.py example.py
Example output:
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
Run time: 0.00110
python3 -m cfgcoverage --html example.py
Example output:
File generated at: html/example.py/index.html
📊 Coverage Criteria
The current HTML report includes the following criteria for each analyzed function:
- Blocks
- Edges
- Edge Pairs
📝 Notes
- The analysis stores its internal data in a file named
<source_file>.cfg. - HTML reports depend on previously generated
.cfgdata. - The tool analyzes functions and nested functions found in the source file.
- When using
--append, coverage data from previous executions is accumulated instead of replaced. - The HTML report is generated per source file and organized under the
html/folder.
👤 Author
Marcio Delamaro
📄 License
MIT
🤝 Contributions
Feel free to open issues or submit pull requests!
Project details
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 cfgcoverage-0.1.tar.gz.
File metadata
- Download URL: cfgcoverage-0.1.tar.gz
- Upload date:
- Size: 25.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b91e34e55e9cc0747e257863ba3e61255779c6acffc75df282af1a981630ddb
|
|
| MD5 |
a50e8829626a796c77fc66389a9a336b
|
|
| BLAKE2b-256 |
1853c1ef4dbc837aa93972953f461b3e1f063918d78fc76fb7995a9f35f9f127
|
File details
Details for the file cfgcoverage-0.1-py3-none-any.whl.
File metadata
- Download URL: cfgcoverage-0.1-py3-none-any.whl
- Upload date:
- Size: 27.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1732b123f05a6a89206e989861d0bba03aaddfe93b78b67e7b2385302a2bb6b1
|
|
| MD5 |
097e219436c4efc6185976fcb42bc56b
|
|
| BLAKE2b-256 |
bfe56ac6bbd9472e7dcd3b5ca7b671f01879840e3d50eff3f8f41c283c284878
|