code-covered 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- code_covered-0.5.0/LICENSE +21 -0
- code_covered-0.5.0/PKG-INFO +257 -0
- code_covered-0.5.0/README.md +225 -0
- code_covered-0.5.0/analyzer/__init__.py +43 -0
- code_covered-0.5.0/analyzer/coverage_gaps.py +809 -0
- code_covered-0.5.0/code_covered.egg-info/PKG-INFO +257 -0
- code_covered-0.5.0/code_covered.egg-info/SOURCES.txt +16 -0
- code_covered-0.5.0/code_covered.egg-info/dependency_links.txt +1 -0
- code_covered-0.5.0/code_covered.egg-info/entry_points.txt +2 -0
- code_covered-0.5.0/code_covered.egg-info/requires.txt +11 -0
- code_covered-0.5.0/code_covered.egg-info/top_level.txt +2 -0
- code_covered-0.5.0/mcp_code_covered/__init__.py +10 -0
- code_covered-0.5.0/mcp_code_covered/tool.py +345 -0
- code_covered-0.5.0/pyproject.toml +100 -0
- code_covered-0.5.0/setup.cfg +4 -0
- code_covered-0.5.0/tests/test_cli.py +101 -0
- code_covered-0.5.0/tests/test_coverage_gaps.py +594 -0
- code_covered-0.5.0/tests/test_mcp_tool.py +537 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 mcp-tool-shop
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: code-covered
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: Find coverage gaps and suggest what tests to write
|
|
5
|
+
Author-email: mcp-tool-shop <64996768+mcp-tool-shop@users.noreply.github.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/mcp-tool-shop/code-covered
|
|
8
|
+
Project-URL: Repository, https://github.com/mcp-tool-shop/code-covered
|
|
9
|
+
Project-URL: Issues, https://github.com/mcp-tool-shop/code-covered/issues
|
|
10
|
+
Keywords: coverage,testing,pytest,test-generation,code-coverage
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Software Development :: Testing
|
|
18
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
24
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
25
|
+
Requires-Dist: build>=1.2.2; extra == "dev"
|
|
26
|
+
Requires-Dist: twine>=5.1.0; extra == "dev"
|
|
27
|
+
Requires-Dist: pyright>=1.1.350; extra == "dev"
|
|
28
|
+
Requires-Dist: ruff>=0.3; extra == "dev"
|
|
29
|
+
Requires-Dist: pip-audit>=2.6; extra == "dev"
|
|
30
|
+
Provides-Extra: mcp
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# code-covered
|
|
34
|
+
|
|
35
|
+
[](https://github.com/mcp-tool-shop/code-covered/actions/workflows/ci.yml)
|
|
36
|
+
[](https://codecov.io/gh/mcp-tool-shop/code-covered)
|
|
37
|
+
[](https://pypi.org/project/code-covered/)
|
|
38
|
+
[](https://www.python.org/downloads/)
|
|
39
|
+
[](LICENSE)
|
|
40
|
+
|
|
41
|
+
**Find coverage gaps and suggest what tests to write.**
|
|
42
|
+
|
|
43
|
+
Coverage tools tell you *what* lines aren't tested. `code-covered` tells you *what tests to write*.
|
|
44
|
+
|
|
45
|
+
## The Problem
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
$ pytest --cov=myapp
|
|
49
|
+
Name Stmts Miss Cover
|
|
50
|
+
----------------------------------------
|
|
51
|
+
myapp/validator.py 47 12 74%
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
74% coverage. 12 lines missing. But *which* 12 lines? And what tests would cover them?
|
|
55
|
+
|
|
56
|
+
## The Solution
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
$ code-covered coverage.json
|
|
60
|
+
|
|
61
|
+
============================================================
|
|
62
|
+
code-covered
|
|
63
|
+
============================================================
|
|
64
|
+
Coverage: 74.5% (35/47 lines)
|
|
65
|
+
Files analyzed: 1 (1 with gaps)
|
|
66
|
+
|
|
67
|
+
Missing tests: 4
|
|
68
|
+
[!!] CRITICAL: 2
|
|
69
|
+
[!] HIGH: 2
|
|
70
|
+
|
|
71
|
+
Top suggestions:
|
|
72
|
+
1. [!!] test_validator_validate_input_handles_exception
|
|
73
|
+
In validate_input() lines 23-27 - when ValueError is raised
|
|
74
|
+
|
|
75
|
+
2. [!!] test_validator_parse_data_raises_error
|
|
76
|
+
In parse_data() lines 45-45 - raise ParseError
|
|
77
|
+
|
|
78
|
+
3. [! ] test_validator_validate_input_when_condition_false
|
|
79
|
+
In validate_input() lines 31-33 - when len(data) == 0 is False
|
|
80
|
+
|
|
81
|
+
4. [! ] test_validator_process_when_condition_true
|
|
82
|
+
In process() lines 52-55 - when config.strict is True
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Installation
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pip install code-covered
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Quick Start
|
|
92
|
+
|
|
93
|
+
### For Users
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# 1. Run your tests with coverage JSON output
|
|
97
|
+
pytest --cov=myapp --cov-report=json
|
|
98
|
+
|
|
99
|
+
# 2. Find what tests you're missing
|
|
100
|
+
code-covered coverage.json
|
|
101
|
+
|
|
102
|
+
# 3. Generate test stubs
|
|
103
|
+
code-covered coverage.json -o tests/test_gaps.py
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### For Developers
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# Clone the repository
|
|
110
|
+
git clone https://github.com/mcp-tool-shop/code-covered.git
|
|
111
|
+
cd code-covered
|
|
112
|
+
|
|
113
|
+
# Create and activate virtual environment
|
|
114
|
+
python -m venv .venv
|
|
115
|
+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
|
116
|
+
|
|
117
|
+
# Install in development mode with dev dependencies
|
|
118
|
+
pip install -e ".[dev]"
|
|
119
|
+
|
|
120
|
+
# Run tests
|
|
121
|
+
pytest -v
|
|
122
|
+
|
|
123
|
+
# Run with coverage
|
|
124
|
+
pytest --cov=analyzer --cov=mcp_code_covered --cov=cli --cov-report=term-missing
|
|
125
|
+
|
|
126
|
+
# Run linting
|
|
127
|
+
ruff check analyzer mcp_code_covered cli.py tests
|
|
128
|
+
|
|
129
|
+
# Run type checking
|
|
130
|
+
pyright analyzer mcp_code_covered cli.py tests
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Features
|
|
134
|
+
|
|
135
|
+
### Priority Levels
|
|
136
|
+
|
|
137
|
+
| Priority | What it means | Example |
|
|
138
|
+
|----------|---------------|---------|
|
|
139
|
+
| **Critical** | Exception handlers, raise statements | `except ValueError:` never triggered |
|
|
140
|
+
| **High** | Conditional branches | `if x > 0:` branch never taken |
|
|
141
|
+
| **Medium** | Function bodies, loops | Loop body never entered |
|
|
142
|
+
| **Low** | Other uncovered code | Module-level statements |
|
|
143
|
+
|
|
144
|
+
### Test Templates
|
|
145
|
+
|
|
146
|
+
Each suggestion includes a ready-to-use test template:
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
def test_validate_input_handles_exception():
|
|
150
|
+
"""Test that validate_input handles ValueError."""
|
|
151
|
+
# Arrange: Set up conditions to trigger ValueError
|
|
152
|
+
# TODO: Mock dependencies to raise ValueError
|
|
153
|
+
|
|
154
|
+
# Act
|
|
155
|
+
result = validate_input() # TODO: Add args
|
|
156
|
+
|
|
157
|
+
# Assert: Verify exception was handled correctly
|
|
158
|
+
# TODO: Add assertions
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Setup Hints
|
|
162
|
+
|
|
163
|
+
Detects common patterns and suggests what to mock:
|
|
164
|
+
|
|
165
|
+
```
|
|
166
|
+
Hints: Mock HTTP requests with responses or httpx, Use @pytest.mark.asyncio decorator
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## CLI Reference
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
# Basic usage
|
|
173
|
+
code-covered coverage.json
|
|
174
|
+
|
|
175
|
+
# Show full templates
|
|
176
|
+
code-covered coverage.json -v
|
|
177
|
+
|
|
178
|
+
# Filter by priority
|
|
179
|
+
code-covered coverage.json --priority critical
|
|
180
|
+
|
|
181
|
+
# Limit results
|
|
182
|
+
code-covered coverage.json --limit 5
|
|
183
|
+
|
|
184
|
+
# Write test stubs to file
|
|
185
|
+
code-covered coverage.json -o tests/test_missing.py
|
|
186
|
+
|
|
187
|
+
# Specify source root (if coverage paths are relative)
|
|
188
|
+
code-covered coverage.json --source-root ./src
|
|
189
|
+
|
|
190
|
+
# JSON output for CI pipelines
|
|
191
|
+
code-covered coverage.json --format json
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Exit Codes
|
|
195
|
+
|
|
196
|
+
| Code | Meaning |
|
|
197
|
+
|------|---------|
|
|
198
|
+
| 0 | Success (gaps found or no gaps) |
|
|
199
|
+
| 1 | Error (file not found, parse error) |
|
|
200
|
+
|
|
201
|
+
### JSON Output
|
|
202
|
+
|
|
203
|
+
Use `--format json` for CI integration:
|
|
204
|
+
|
|
205
|
+
```json
|
|
206
|
+
{
|
|
207
|
+
"coverage_percent": 74.5,
|
|
208
|
+
"files_analyzed": 3,
|
|
209
|
+
"files_with_gaps": 1,
|
|
210
|
+
"suggestions": [
|
|
211
|
+
{
|
|
212
|
+
"test_name": "test_validator_validate_input_handles_exception",
|
|
213
|
+
"test_file": "tests/test_validator.py",
|
|
214
|
+
"description": "In validate_input() lines 23-27 - when ValueError is raised",
|
|
215
|
+
"covers_lines": [23, 24, 25, 26, 27],
|
|
216
|
+
"priority": "critical",
|
|
217
|
+
"code_template": "def test_...",
|
|
218
|
+
"setup_hints": ["Mock HTTP requests"],
|
|
219
|
+
"block_type": "exception_handler"
|
|
220
|
+
}
|
|
221
|
+
],
|
|
222
|
+
"warnings": []
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Python API
|
|
227
|
+
|
|
228
|
+
```python
|
|
229
|
+
from analyzer import find_coverage_gaps, print_coverage_gaps
|
|
230
|
+
|
|
231
|
+
# Find gaps
|
|
232
|
+
suggestions, warnings = find_coverage_gaps("coverage.json")
|
|
233
|
+
|
|
234
|
+
# Print formatted output
|
|
235
|
+
print_coverage_gaps(suggestions)
|
|
236
|
+
|
|
237
|
+
# Or process programmatically
|
|
238
|
+
for s in suggestions:
|
|
239
|
+
print(f"{s.priority}: {s.test_name}")
|
|
240
|
+
print(f" Covers lines {s.covers_lines}")
|
|
241
|
+
print(f" Template:\n{s.code_template}")
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## How It Works
|
|
245
|
+
|
|
246
|
+
1. **Parse coverage.json** - Reads the JSON report from `pytest-cov`
|
|
247
|
+
2. **AST Analysis** - Parses source files to understand code structure
|
|
248
|
+
3. **Context Detection** - Identifies what each uncovered block does:
|
|
249
|
+
- Is it an exception handler?
|
|
250
|
+
- Is it a conditional branch?
|
|
251
|
+
- What function/class is it in?
|
|
252
|
+
4. **Template Generation** - Creates specific test templates based on context
|
|
253
|
+
5. **Prioritization** - Ranks by importance (error paths > branches > other)
|
|
254
|
+
|
|
255
|
+
## License
|
|
256
|
+
|
|
257
|
+
MIT
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# code-covered
|
|
2
|
+
|
|
3
|
+
[](https://github.com/mcp-tool-shop/code-covered/actions/workflows/ci.yml)
|
|
4
|
+
[](https://codecov.io/gh/mcp-tool-shop/code-covered)
|
|
5
|
+
[](https://pypi.org/project/code-covered/)
|
|
6
|
+
[](https://www.python.org/downloads/)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
9
|
+
**Find coverage gaps and suggest what tests to write.**
|
|
10
|
+
|
|
11
|
+
Coverage tools tell you *what* lines aren't tested. `code-covered` tells you *what tests to write*.
|
|
12
|
+
|
|
13
|
+
## The Problem
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
$ pytest --cov=myapp
|
|
17
|
+
Name Stmts Miss Cover
|
|
18
|
+
----------------------------------------
|
|
19
|
+
myapp/validator.py 47 12 74%
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
74% coverage. 12 lines missing. But *which* 12 lines? And what tests would cover them?
|
|
23
|
+
|
|
24
|
+
## The Solution
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
$ code-covered coverage.json
|
|
28
|
+
|
|
29
|
+
============================================================
|
|
30
|
+
code-covered
|
|
31
|
+
============================================================
|
|
32
|
+
Coverage: 74.5% (35/47 lines)
|
|
33
|
+
Files analyzed: 1 (1 with gaps)
|
|
34
|
+
|
|
35
|
+
Missing tests: 4
|
|
36
|
+
[!!] CRITICAL: 2
|
|
37
|
+
[!] HIGH: 2
|
|
38
|
+
|
|
39
|
+
Top suggestions:
|
|
40
|
+
1. [!!] test_validator_validate_input_handles_exception
|
|
41
|
+
In validate_input() lines 23-27 - when ValueError is raised
|
|
42
|
+
|
|
43
|
+
2. [!!] test_validator_parse_data_raises_error
|
|
44
|
+
In parse_data() lines 45-45 - raise ParseError
|
|
45
|
+
|
|
46
|
+
3. [! ] test_validator_validate_input_when_condition_false
|
|
47
|
+
In validate_input() lines 31-33 - when len(data) == 0 is False
|
|
48
|
+
|
|
49
|
+
4. [! ] test_validator_process_when_condition_true
|
|
50
|
+
In process() lines 52-55 - when config.strict is True
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install code-covered
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Quick Start
|
|
60
|
+
|
|
61
|
+
### For Users
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# 1. Run your tests with coverage JSON output
|
|
65
|
+
pytest --cov=myapp --cov-report=json
|
|
66
|
+
|
|
67
|
+
# 2. Find what tests you're missing
|
|
68
|
+
code-covered coverage.json
|
|
69
|
+
|
|
70
|
+
# 3. Generate test stubs
|
|
71
|
+
code-covered coverage.json -o tests/test_gaps.py
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### For Developers
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Clone the repository
|
|
78
|
+
git clone https://github.com/mcp-tool-shop/code-covered.git
|
|
79
|
+
cd code-covered
|
|
80
|
+
|
|
81
|
+
# Create and activate virtual environment
|
|
82
|
+
python -m venv .venv
|
|
83
|
+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
|
84
|
+
|
|
85
|
+
# Install in development mode with dev dependencies
|
|
86
|
+
pip install -e ".[dev]"
|
|
87
|
+
|
|
88
|
+
# Run tests
|
|
89
|
+
pytest -v
|
|
90
|
+
|
|
91
|
+
# Run with coverage
|
|
92
|
+
pytest --cov=analyzer --cov=mcp_code_covered --cov=cli --cov-report=term-missing
|
|
93
|
+
|
|
94
|
+
# Run linting
|
|
95
|
+
ruff check analyzer mcp_code_covered cli.py tests
|
|
96
|
+
|
|
97
|
+
# Run type checking
|
|
98
|
+
pyright analyzer mcp_code_covered cli.py tests
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Features
|
|
102
|
+
|
|
103
|
+
### Priority Levels
|
|
104
|
+
|
|
105
|
+
| Priority | What it means | Example |
|
|
106
|
+
|----------|---------------|---------|
|
|
107
|
+
| **Critical** | Exception handlers, raise statements | `except ValueError:` never triggered |
|
|
108
|
+
| **High** | Conditional branches | `if x > 0:` branch never taken |
|
|
109
|
+
| **Medium** | Function bodies, loops | Loop body never entered |
|
|
110
|
+
| **Low** | Other uncovered code | Module-level statements |
|
|
111
|
+
|
|
112
|
+
### Test Templates
|
|
113
|
+
|
|
114
|
+
Each suggestion includes a ready-to-use test template:
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
def test_validate_input_handles_exception():
|
|
118
|
+
"""Test that validate_input handles ValueError."""
|
|
119
|
+
# Arrange: Set up conditions to trigger ValueError
|
|
120
|
+
# TODO: Mock dependencies to raise ValueError
|
|
121
|
+
|
|
122
|
+
# Act
|
|
123
|
+
result = validate_input() # TODO: Add args
|
|
124
|
+
|
|
125
|
+
# Assert: Verify exception was handled correctly
|
|
126
|
+
# TODO: Add assertions
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Setup Hints
|
|
130
|
+
|
|
131
|
+
Detects common patterns and suggests what to mock:
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
Hints: Mock HTTP requests with responses or httpx, Use @pytest.mark.asyncio decorator
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## CLI Reference
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
# Basic usage
|
|
141
|
+
code-covered coverage.json
|
|
142
|
+
|
|
143
|
+
# Show full templates
|
|
144
|
+
code-covered coverage.json -v
|
|
145
|
+
|
|
146
|
+
# Filter by priority
|
|
147
|
+
code-covered coverage.json --priority critical
|
|
148
|
+
|
|
149
|
+
# Limit results
|
|
150
|
+
code-covered coverage.json --limit 5
|
|
151
|
+
|
|
152
|
+
# Write test stubs to file
|
|
153
|
+
code-covered coverage.json -o tests/test_missing.py
|
|
154
|
+
|
|
155
|
+
# Specify source root (if coverage paths are relative)
|
|
156
|
+
code-covered coverage.json --source-root ./src
|
|
157
|
+
|
|
158
|
+
# JSON output for CI pipelines
|
|
159
|
+
code-covered coverage.json --format json
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Exit Codes
|
|
163
|
+
|
|
164
|
+
| Code | Meaning |
|
|
165
|
+
|------|---------|
|
|
166
|
+
| 0 | Success (gaps found or no gaps) |
|
|
167
|
+
| 1 | Error (file not found, parse error) |
|
|
168
|
+
|
|
169
|
+
### JSON Output
|
|
170
|
+
|
|
171
|
+
Use `--format json` for CI integration:
|
|
172
|
+
|
|
173
|
+
```json
|
|
174
|
+
{
|
|
175
|
+
"coverage_percent": 74.5,
|
|
176
|
+
"files_analyzed": 3,
|
|
177
|
+
"files_with_gaps": 1,
|
|
178
|
+
"suggestions": [
|
|
179
|
+
{
|
|
180
|
+
"test_name": "test_validator_validate_input_handles_exception",
|
|
181
|
+
"test_file": "tests/test_validator.py",
|
|
182
|
+
"description": "In validate_input() lines 23-27 - when ValueError is raised",
|
|
183
|
+
"covers_lines": [23, 24, 25, 26, 27],
|
|
184
|
+
"priority": "critical",
|
|
185
|
+
"code_template": "def test_...",
|
|
186
|
+
"setup_hints": ["Mock HTTP requests"],
|
|
187
|
+
"block_type": "exception_handler"
|
|
188
|
+
}
|
|
189
|
+
],
|
|
190
|
+
"warnings": []
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Python API
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
from analyzer import find_coverage_gaps, print_coverage_gaps
|
|
198
|
+
|
|
199
|
+
# Find gaps
|
|
200
|
+
suggestions, warnings = find_coverage_gaps("coverage.json")
|
|
201
|
+
|
|
202
|
+
# Print formatted output
|
|
203
|
+
print_coverage_gaps(suggestions)
|
|
204
|
+
|
|
205
|
+
# Or process programmatically
|
|
206
|
+
for s in suggestions:
|
|
207
|
+
print(f"{s.priority}: {s.test_name}")
|
|
208
|
+
print(f" Covers lines {s.covers_lines}")
|
|
209
|
+
print(f" Template:\n{s.code_template}")
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## How It Works
|
|
213
|
+
|
|
214
|
+
1. **Parse coverage.json** - Reads the JSON report from `pytest-cov`
|
|
215
|
+
2. **AST Analysis** - Parses source files to understand code structure
|
|
216
|
+
3. **Context Detection** - Identifies what each uncovered block does:
|
|
217
|
+
- Is it an exception handler?
|
|
218
|
+
- Is it a conditional branch?
|
|
219
|
+
- What function/class is it in?
|
|
220
|
+
4. **Template Generation** - Creates specific test templates based on context
|
|
221
|
+
5. **Prioritization** - Ranks by importance (error paths > branches > other)
|
|
222
|
+
|
|
223
|
+
## License
|
|
224
|
+
|
|
225
|
+
MIT
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Code-Covered Analyzer
|
|
3
|
+
|
|
4
|
+
Tells you WHAT tests to write, not just what's uncovered.
|
|
5
|
+
|
|
6
|
+
Core components:
|
|
7
|
+
- CoverageParser: Reads coverage.py JSON output
|
|
8
|
+
- GapAnalyzer: Maps uncovered lines to specific test suggestions
|
|
9
|
+
- GapSuggestionGenerator: Creates actionable test templates
|
|
10
|
+
|
|
11
|
+
Usage:
|
|
12
|
+
from analyzer import find_coverage_gaps
|
|
13
|
+
|
|
14
|
+
suggestions, warnings = find_coverage_gaps("coverage.json")
|
|
15
|
+
for s in suggestions:
|
|
16
|
+
print(f"{s.priority}: {s.test_name}")
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from .coverage_gaps import (
|
|
20
|
+
CoverageParser,
|
|
21
|
+
CoverageReport,
|
|
22
|
+
FileCoverage,
|
|
23
|
+
GapAnalyzer,
|
|
24
|
+
GapSuggestion,
|
|
25
|
+
GapSuggestionGenerator,
|
|
26
|
+
UncoveredBlock,
|
|
27
|
+
find_coverage_gaps,
|
|
28
|
+
print_coverage_gaps,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
__all__ = [
|
|
32
|
+
# Main entry point
|
|
33
|
+
"find_coverage_gaps",
|
|
34
|
+
"print_coverage_gaps",
|
|
35
|
+
# Data structures
|
|
36
|
+
"CoverageParser",
|
|
37
|
+
"CoverageReport",
|
|
38
|
+
"FileCoverage",
|
|
39
|
+
"GapAnalyzer",
|
|
40
|
+
"GapSuggestion",
|
|
41
|
+
"GapSuggestionGenerator",
|
|
42
|
+
"UncoveredBlock",
|
|
43
|
+
]
|