pyupcheck 0.4.2__tar.gz → 0.4.3__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.
- {pyupcheck-0.4.2/pyupcheck.egg-info → pyupcheck-0.4.3}/PKG-INFO +59 -1
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/README.md +58 -0
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/depshift/__init__.py +3 -3
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/depshift/apisurface.py +5 -2
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/depshift/changelog.py +2 -1
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/depshift/deps.py +8 -2
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/pyproject.toml +35 -35
- {pyupcheck-0.4.2 → pyupcheck-0.4.3/pyupcheck.egg-info}/PKG-INFO +59 -1
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/pyupcheck.egg-info/SOURCES.txt +5 -0
- pyupcheck-0.4.3/tests/test_cache.py +97 -0
- pyupcheck-0.4.3/tests/test_changelog.py +152 -0
- pyupcheck-0.4.3/tests/test_config.py +98 -0
- pyupcheck-0.4.3/tests/test_precise.py +122 -0
- pyupcheck-0.4.3/tests/test_report.py +149 -0
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/LICENSE +0 -0
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/depshift/analyzer.py +0 -0
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/depshift/cache.py +0 -0
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/depshift/cli.py +0 -0
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/depshift/config.py +0 -0
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/depshift/precise.py +0 -0
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/depshift/report.py +0 -0
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/depshift/scanner.py +0 -0
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/depshift/welcome.py +0 -0
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/pyupcheck.egg-info/dependency_links.txt +0 -0
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/pyupcheck.egg-info/entry_points.txt +0 -0
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/pyupcheck.egg-info/requires.txt +0 -0
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/pyupcheck.egg-info/top_level.txt +0 -0
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/setup.cfg +0 -0
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/tests/test_analyzer.py +0 -0
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/tests/test_apisurface.py +0 -0
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/tests/test_deps.py +0 -0
- {pyupcheck-0.4.2 → pyupcheck-0.4.3}/tests/test_scanner.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyupcheck
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.3
|
|
4
4
|
Summary: Check if upgrading a Python dependency will break your code
|
|
5
5
|
Author: AgbaDev
|
|
6
6
|
License-Expression: MIT
|
|
@@ -223,3 +223,61 @@ If you find a package whose changelog pyupcheck fails to parse correctly, open a
|
|
|
223
223
|
## License
|
|
224
224
|
|
|
225
225
|
MIT
|
|
226
|
+
|
|
227
|
+
## FAQ
|
|
228
|
+
|
|
229
|
+
**Q: How accurate is pyupcheck?**
|
|
230
|
+
|
|
231
|
+
Without `--deep`, accuracy depends on how well maintainers document breaking changes in their changelogs. Major well-maintained packages (Flask, Django, requests, click) have good changelogs and high detection rates. Smaller packages with poor changelogs may have misses.
|
|
232
|
+
|
|
233
|
+
With `--deep`, accuracy is much higher because it diffs the actual source code. It will catch any removed public function or deleted parameter regardless of whether the changelog mentioned it.
|
|
234
|
+
|
|
235
|
+
**Q: Why do I see "[FACT]" next to some findings?**
|
|
236
|
+
|
|
237
|
+
`[FACT]` means the finding came from a real API surface diff (via `--deep`), not changelog parsing. These are confirmed removals, not guesses.
|
|
238
|
+
|
|
239
|
+
**Q: How does pyupcheck handle packages that ship C extensions?**
|
|
240
|
+
|
|
241
|
+
The `--deep` mode downloads and parses Python source files. If a package ships only compiled C extensions with no Python stubs, extraction will fail gracefully and fall back to changelog-based detection.
|
|
242
|
+
|
|
243
|
+
**Q: Will pyupcheck send my code anywhere?**
|
|
244
|
+
|
|
245
|
+
No. Your code is never sent anywhere. pyupcheck only reads local files and makes outbound requests to PyPI and GitHub to fetch package metadata and changelogs.
|
|
246
|
+
|
|
247
|
+
**Q: How do I use it in CI without hitting GitHub rate limits?**
|
|
248
|
+
|
|
249
|
+
Set the `GITHUB_TOKEN` environment variable. In GitHub Actions this is available as `${{ secrets.GITHUB_TOKEN }}` automatically.
|
|
250
|
+
|
|
251
|
+
**Q: Can I ignore certain packages?**
|
|
252
|
+
|
|
253
|
+
Yes. Add them to `.pyupcheckignore` or `[tool.pyupcheck]` in your `pyproject.toml`:
|
|
254
|
+
|
|
255
|
+
```toml
|
|
256
|
+
[tool.pyupcheck]
|
|
257
|
+
ignore = ["my-internal-package", "legacy-lib"]
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
**Q: The version I want to check is not on PyPI yet. Can I still use pyupcheck?**
|
|
261
|
+
|
|
262
|
+
No. pyupcheck needs to download the package from PyPI. Pre-release or private packages are not supported.
|
|
263
|
+
|
|
264
|
+
## Comparison
|
|
265
|
+
|
|
266
|
+
| Tool | What it does | pyupcheck advantage |
|
|
267
|
+
|------|-------------|---------------------|
|
|
268
|
+
| `pip install --upgrade` | Upgrades blindly | pyupcheck checks first |
|
|
269
|
+
| `pip-audit` | Finds security vulnerabilities | pyupcheck finds API breaks |
|
|
270
|
+
| `safety` | Checks known CVEs | pyupcheck checks your specific usage |
|
|
271
|
+
| `pipdeptree` | Shows dependency tree | pyupcheck shows upgrade risk |
|
|
272
|
+
| Reading changelogs manually | Slow, easy to miss things | pyupcheck automates this |
|
|
273
|
+
|
|
274
|
+
## Roadmap
|
|
275
|
+
|
|
276
|
+
Items being actively considered for future versions:
|
|
277
|
+
|
|
278
|
+
- `--watch` mode: monitor your lockfile and alert when a new version would break your code
|
|
279
|
+
- pip-tools and conda-lock support
|
|
280
|
+
- VS Code extension: inline warnings on imports
|
|
281
|
+
- Jupyter notebook deep scan (currently scans cells for imports, not API calls inside them)
|
|
282
|
+
- `pyupcheck explain` with AI-assisted migration guidance
|
|
283
|
+
- Support for TypeScript / Node.js packages (npm ecosystem)
|
|
@@ -201,3 +201,61 @@ If you find a package whose changelog pyupcheck fails to parse correctly, open a
|
|
|
201
201
|
## License
|
|
202
202
|
|
|
203
203
|
MIT
|
|
204
|
+
|
|
205
|
+
## FAQ
|
|
206
|
+
|
|
207
|
+
**Q: How accurate is pyupcheck?**
|
|
208
|
+
|
|
209
|
+
Without `--deep`, accuracy depends on how well maintainers document breaking changes in their changelogs. Major well-maintained packages (Flask, Django, requests, click) have good changelogs and high detection rates. Smaller packages with poor changelogs may have misses.
|
|
210
|
+
|
|
211
|
+
With `--deep`, accuracy is much higher because it diffs the actual source code. It will catch any removed public function or deleted parameter regardless of whether the changelog mentioned it.
|
|
212
|
+
|
|
213
|
+
**Q: Why do I see "[FACT]" next to some findings?**
|
|
214
|
+
|
|
215
|
+
`[FACT]` means the finding came from a real API surface diff (via `--deep`), not changelog parsing. These are confirmed removals, not guesses.
|
|
216
|
+
|
|
217
|
+
**Q: How does pyupcheck handle packages that ship C extensions?**
|
|
218
|
+
|
|
219
|
+
The `--deep` mode downloads and parses Python source files. If a package ships only compiled C extensions with no Python stubs, extraction will fail gracefully and fall back to changelog-based detection.
|
|
220
|
+
|
|
221
|
+
**Q: Will pyupcheck send my code anywhere?**
|
|
222
|
+
|
|
223
|
+
No. Your code is never sent anywhere. pyupcheck only reads local files and makes outbound requests to PyPI and GitHub to fetch package metadata and changelogs.
|
|
224
|
+
|
|
225
|
+
**Q: How do I use it in CI without hitting GitHub rate limits?**
|
|
226
|
+
|
|
227
|
+
Set the `GITHUB_TOKEN` environment variable. In GitHub Actions this is available as `${{ secrets.GITHUB_TOKEN }}` automatically.
|
|
228
|
+
|
|
229
|
+
**Q: Can I ignore certain packages?**
|
|
230
|
+
|
|
231
|
+
Yes. Add them to `.pyupcheckignore` or `[tool.pyupcheck]` in your `pyproject.toml`:
|
|
232
|
+
|
|
233
|
+
```toml
|
|
234
|
+
[tool.pyupcheck]
|
|
235
|
+
ignore = ["my-internal-package", "legacy-lib"]
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
**Q: The version I want to check is not on PyPI yet. Can I still use pyupcheck?**
|
|
239
|
+
|
|
240
|
+
No. pyupcheck needs to download the package from PyPI. Pre-release or private packages are not supported.
|
|
241
|
+
|
|
242
|
+
## Comparison
|
|
243
|
+
|
|
244
|
+
| Tool | What it does | pyupcheck advantage |
|
|
245
|
+
|------|-------------|---------------------|
|
|
246
|
+
| `pip install --upgrade` | Upgrades blindly | pyupcheck checks first |
|
|
247
|
+
| `pip-audit` | Finds security vulnerabilities | pyupcheck finds API breaks |
|
|
248
|
+
| `safety` | Checks known CVEs | pyupcheck checks your specific usage |
|
|
249
|
+
| `pipdeptree` | Shows dependency tree | pyupcheck shows upgrade risk |
|
|
250
|
+
| Reading changelogs manually | Slow, easy to miss things | pyupcheck automates this |
|
|
251
|
+
|
|
252
|
+
## Roadmap
|
|
253
|
+
|
|
254
|
+
Items being actively considered for future versions:
|
|
255
|
+
|
|
256
|
+
- `--watch` mode: monitor your lockfile and alert when a new version would break your code
|
|
257
|
+
- pip-tools and conda-lock support
|
|
258
|
+
- VS Code extension: inline warnings on imports
|
|
259
|
+
- Jupyter notebook deep scan (currently scans cells for imports, not API calls inside them)
|
|
260
|
+
- `pyupcheck explain` with AI-assisted migration guidance
|
|
261
|
+
- Support for TypeScript / Node.js packages (npm ecosystem)
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"""depshift - Check if upgrading a Python dependency will break your code."""
|
|
2
|
-
|
|
3
|
-
__version__ = "0.4.
|
|
1
|
+
"""depshift - Check if upgrading a Python dependency will break your code."""
|
|
2
|
+
|
|
3
|
+
__version__ = "0.4.3"
|
|
@@ -63,7 +63,7 @@ def _find_sdist_or_wheel_url(package: str, version: str) -> Optional[Tuple[str,
|
|
|
63
63
|
try:
|
|
64
64
|
info = get_pypi_info(package)
|
|
65
65
|
except Exception:
|
|
66
|
-
cache_set(key,
|
|
66
|
+
cache_set(key, [])
|
|
67
67
|
return None
|
|
68
68
|
|
|
69
69
|
releases = info.get("releases", {})
|
|
@@ -84,7 +84,10 @@ def _find_sdist_or_wheel_url(package: str, version: str) -> Optional[Tuple[str,
|
|
|
84
84
|
sdist = (url, "sdist")
|
|
85
85
|
|
|
86
86
|
result = wheel or sdist
|
|
87
|
-
|
|
87
|
+
# Cache a "not found" result as [] rather than None: cache_get() cannot
|
|
88
|
+
# distinguish a cached None from a cache miss, so None here would defeat
|
|
89
|
+
# negative caching and re-trigger a network fetch on every call.
|
|
90
|
+
cache_set(key, list(result) if result else [])
|
|
88
91
|
return result
|
|
89
92
|
|
|
90
93
|
|
|
@@ -84,7 +84,8 @@ def extract_github_repo(pypi_info: dict) -> Optional[Tuple[str, str]]:
|
|
|
84
84
|
m = pattern.search(url)
|
|
85
85
|
if m:
|
|
86
86
|
owner, repo = m.group(1), m.group(2)
|
|
87
|
-
|
|
87
|
+
if repo.endswith(".git"):
|
|
88
|
+
repo = repo[: -len(".git")]
|
|
88
89
|
return owner, repo
|
|
89
90
|
return None
|
|
90
91
|
|
|
@@ -167,18 +167,24 @@ def parse_conda_env(path: str) -> List[Dependency]:
|
|
|
167
167
|
with open(path, "r", encoding="utf-8", errors="ignore") as f:
|
|
168
168
|
lines = f.readlines()
|
|
169
169
|
in_pip = False
|
|
170
|
+
pip_indent = None
|
|
170
171
|
for line in lines:
|
|
171
172
|
stripped = line.strip()
|
|
173
|
+
if not stripped:
|
|
174
|
+
continue
|
|
175
|
+
indent = len(line) - len(line.lstrip(" \t"))
|
|
172
176
|
if stripped == "- pip:":
|
|
173
177
|
in_pip = True
|
|
178
|
+
pip_indent = indent
|
|
174
179
|
continue
|
|
175
180
|
if in_pip:
|
|
176
|
-
|
|
181
|
+
# Only lines indented deeper than "- pip:" belong to the pip list.
|
|
182
|
+
if indent > pip_indent and stripped.startswith("-"):
|
|
177
183
|
raw = stripped.lstrip("- ").strip()
|
|
178
184
|
d = parse_requirement_line(raw, "environment.yml")
|
|
179
185
|
if d:
|
|
180
186
|
deps.append(d)
|
|
181
|
-
|
|
187
|
+
else:
|
|
182
188
|
in_pip = False
|
|
183
189
|
except OSError:
|
|
184
190
|
pass
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
[build-system]
|
|
2
|
-
requires = ["setuptools>=68.0", "wheel"]
|
|
3
|
-
build-backend = "setuptools.build_meta"
|
|
4
|
-
|
|
5
|
-
[project]
|
|
6
|
-
name = "pyupcheck"
|
|
7
|
-
version = "0.4.
|
|
8
|
-
description = "Check if upgrading a Python dependency will break your code"
|
|
9
|
-
readme = "README.md"
|
|
10
|
-
license = "MIT"
|
|
11
|
-
requires-python = ">=3.8"
|
|
12
|
-
authors = [{name = "AgbaDev"}]
|
|
13
|
-
keywords = ["cli", "dependency", "upgrade", "migration", "breaking-changes"]
|
|
14
|
-
classifiers = [
|
|
15
|
-
"Development Status :: 3 - Alpha",
|
|
16
|
-
"Environment :: Console",
|
|
17
|
-
"Intended Audience :: Developers",
|
|
18
|
-
"Programming Language :: Python :: 3",
|
|
19
|
-
"Topic :: Software Development :: Quality Assurance",
|
|
20
|
-
]
|
|
21
|
-
dependencies = [
|
|
22
|
-
"httpx>=0.24.0",
|
|
23
|
-
"rich>=13.0.0",
|
|
24
|
-
"click>=8.0.0",
|
|
25
|
-
]
|
|
26
|
-
|
|
27
|
-
[project.scripts]
|
|
28
|
-
pyupcheck = "depshift.cli:main"
|
|
29
|
-
|
|
30
|
-
[project.urls]
|
|
31
|
-
Homepage = "https://github.com/AgbaDev/pyupcheck"
|
|
32
|
-
Issues = "https://github.com/AgbaDev/pyupcheck/issues"
|
|
33
|
-
|
|
34
|
-
[tool.setuptools.packages.find]
|
|
35
|
-
include = ["depshift*"]
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pyupcheck"
|
|
7
|
+
version = "0.4.3"
|
|
8
|
+
description = "Check if upgrading a Python dependency will break your code"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.8"
|
|
12
|
+
authors = [{name = "AgbaDev"}]
|
|
13
|
+
keywords = ["cli", "dependency", "upgrade", "migration", "breaking-changes"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Environment :: Console",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
20
|
+
]
|
|
21
|
+
dependencies = [
|
|
22
|
+
"httpx>=0.24.0",
|
|
23
|
+
"rich>=13.0.0",
|
|
24
|
+
"click>=8.0.0",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.scripts]
|
|
28
|
+
pyupcheck = "depshift.cli:main"
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://github.com/AgbaDev/pyupcheck"
|
|
32
|
+
Issues = "https://github.com/AgbaDev/pyupcheck/issues"
|
|
33
|
+
|
|
34
|
+
[tool.setuptools.packages.find]
|
|
35
|
+
include = ["depshift*"]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyupcheck
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.3
|
|
4
4
|
Summary: Check if upgrading a Python dependency will break your code
|
|
5
5
|
Author: AgbaDev
|
|
6
6
|
License-Expression: MIT
|
|
@@ -223,3 +223,61 @@ If you find a package whose changelog pyupcheck fails to parse correctly, open a
|
|
|
223
223
|
## License
|
|
224
224
|
|
|
225
225
|
MIT
|
|
226
|
+
|
|
227
|
+
## FAQ
|
|
228
|
+
|
|
229
|
+
**Q: How accurate is pyupcheck?**
|
|
230
|
+
|
|
231
|
+
Without `--deep`, accuracy depends on how well maintainers document breaking changes in their changelogs. Major well-maintained packages (Flask, Django, requests, click) have good changelogs and high detection rates. Smaller packages with poor changelogs may have misses.
|
|
232
|
+
|
|
233
|
+
With `--deep`, accuracy is much higher because it diffs the actual source code. It will catch any removed public function or deleted parameter regardless of whether the changelog mentioned it.
|
|
234
|
+
|
|
235
|
+
**Q: Why do I see "[FACT]" next to some findings?**
|
|
236
|
+
|
|
237
|
+
`[FACT]` means the finding came from a real API surface diff (via `--deep`), not changelog parsing. These are confirmed removals, not guesses.
|
|
238
|
+
|
|
239
|
+
**Q: How does pyupcheck handle packages that ship C extensions?**
|
|
240
|
+
|
|
241
|
+
The `--deep` mode downloads and parses Python source files. If a package ships only compiled C extensions with no Python stubs, extraction will fail gracefully and fall back to changelog-based detection.
|
|
242
|
+
|
|
243
|
+
**Q: Will pyupcheck send my code anywhere?**
|
|
244
|
+
|
|
245
|
+
No. Your code is never sent anywhere. pyupcheck only reads local files and makes outbound requests to PyPI and GitHub to fetch package metadata and changelogs.
|
|
246
|
+
|
|
247
|
+
**Q: How do I use it in CI without hitting GitHub rate limits?**
|
|
248
|
+
|
|
249
|
+
Set the `GITHUB_TOKEN` environment variable. In GitHub Actions this is available as `${{ secrets.GITHUB_TOKEN }}` automatically.
|
|
250
|
+
|
|
251
|
+
**Q: Can I ignore certain packages?**
|
|
252
|
+
|
|
253
|
+
Yes. Add them to `.pyupcheckignore` or `[tool.pyupcheck]` in your `pyproject.toml`:
|
|
254
|
+
|
|
255
|
+
```toml
|
|
256
|
+
[tool.pyupcheck]
|
|
257
|
+
ignore = ["my-internal-package", "legacy-lib"]
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
**Q: The version I want to check is not on PyPI yet. Can I still use pyupcheck?**
|
|
261
|
+
|
|
262
|
+
No. pyupcheck needs to download the package from PyPI. Pre-release or private packages are not supported.
|
|
263
|
+
|
|
264
|
+
## Comparison
|
|
265
|
+
|
|
266
|
+
| Tool | What it does | pyupcheck advantage |
|
|
267
|
+
|------|-------------|---------------------|
|
|
268
|
+
| `pip install --upgrade` | Upgrades blindly | pyupcheck checks first |
|
|
269
|
+
| `pip-audit` | Finds security vulnerabilities | pyupcheck finds API breaks |
|
|
270
|
+
| `safety` | Checks known CVEs | pyupcheck checks your specific usage |
|
|
271
|
+
| `pipdeptree` | Shows dependency tree | pyupcheck shows upgrade risk |
|
|
272
|
+
| Reading changelogs manually | Slow, easy to miss things | pyupcheck automates this |
|
|
273
|
+
|
|
274
|
+
## Roadmap
|
|
275
|
+
|
|
276
|
+
Items being actively considered for future versions:
|
|
277
|
+
|
|
278
|
+
- `--watch` mode: monitor your lockfile and alert when a new version would break your code
|
|
279
|
+
- pip-tools and conda-lock support
|
|
280
|
+
- VS Code extension: inline warnings on imports
|
|
281
|
+
- Jupyter notebook deep scan (currently scans cells for imports, not API calls inside them)
|
|
282
|
+
- `pyupcheck explain` with AI-assisted migration guidance
|
|
283
|
+
- Support for TypeScript / Node.js packages (npm ecosystem)
|
|
@@ -21,5 +21,10 @@ pyupcheck.egg-info/requires.txt
|
|
|
21
21
|
pyupcheck.egg-info/top_level.txt
|
|
22
22
|
tests/test_analyzer.py
|
|
23
23
|
tests/test_apisurface.py
|
|
24
|
+
tests/test_cache.py
|
|
25
|
+
tests/test_changelog.py
|
|
26
|
+
tests/test_config.py
|
|
24
27
|
tests/test_deps.py
|
|
28
|
+
tests/test_precise.py
|
|
29
|
+
tests/test_report.py
|
|
25
30
|
tests/test_scanner.py
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""Tests for the local response cache."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import time
|
|
6
|
+
import tempfile
|
|
7
|
+
|
|
8
|
+
import pytest
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_cache_set_and_get(tmp_path, monkeypatch):
|
|
12
|
+
monkeypatch.setenv("PYUPCHECK_CACHE_DIR", str(tmp_path))
|
|
13
|
+
from importlib import reload
|
|
14
|
+
import depshift.cache as cache
|
|
15
|
+
reload(cache)
|
|
16
|
+
|
|
17
|
+
cache.cache_set("mykey", {"data": 42})
|
|
18
|
+
result = cache.cache_get("mykey")
|
|
19
|
+
assert result == {"data": 42}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_cache_miss_returns_none(tmp_path, monkeypatch):
|
|
23
|
+
monkeypatch.setenv("PYUPCHECK_CACHE_DIR", str(tmp_path))
|
|
24
|
+
from importlib import reload
|
|
25
|
+
import depshift.cache as cache
|
|
26
|
+
reload(cache)
|
|
27
|
+
|
|
28
|
+
result = cache.cache_get("nonexistent_key_xyz_999")
|
|
29
|
+
assert result is None
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_cache_ttl_expiry(tmp_path, monkeypatch):
|
|
33
|
+
monkeypatch.setenv("PYUPCHECK_CACHE_DIR", str(tmp_path))
|
|
34
|
+
from importlib import reload
|
|
35
|
+
import depshift.cache as cache
|
|
36
|
+
reload(cache)
|
|
37
|
+
|
|
38
|
+
cache.cache_set("expkey", "value")
|
|
39
|
+
# immediately get with ttl=0 should expire
|
|
40
|
+
result = cache.cache_get("expkey", ttl=0)
|
|
41
|
+
assert result is None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_cache_stores_various_types(tmp_path, monkeypatch):
|
|
45
|
+
monkeypatch.setenv("PYUPCHECK_CACHE_DIR", str(tmp_path))
|
|
46
|
+
from importlib import reload
|
|
47
|
+
import depshift.cache as cache
|
|
48
|
+
reload(cache)
|
|
49
|
+
|
|
50
|
+
cache.cache_set("str", "hello")
|
|
51
|
+
cache.cache_set("list", [1, 2, 3])
|
|
52
|
+
cache.cache_set("dict", {"a": "b"})
|
|
53
|
+
cache.cache_set("none_val", None)
|
|
54
|
+
|
|
55
|
+
assert cache.cache_get("str") == "hello"
|
|
56
|
+
assert cache.cache_get("list") == [1, 2, 3]
|
|
57
|
+
assert cache.cache_get("dict") == {"a": "b"}
|
|
58
|
+
assert cache.cache_get("none_val") is None
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_cache_clear(tmp_path, monkeypatch):
|
|
62
|
+
monkeypatch.setenv("PYUPCHECK_CACHE_DIR", str(tmp_path))
|
|
63
|
+
from importlib import reload
|
|
64
|
+
import depshift.cache as cache
|
|
65
|
+
reload(cache)
|
|
66
|
+
|
|
67
|
+
cache.cache_set("k1", 1)
|
|
68
|
+
cache.cache_set("k2", 2)
|
|
69
|
+
cache.cache_set("k3", 3)
|
|
70
|
+
count = cache.cache_clear()
|
|
71
|
+
assert count == 3
|
|
72
|
+
assert cache.cache_get("k1") is None
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_cache_disable(tmp_path, monkeypatch):
|
|
76
|
+
monkeypatch.setenv("PYUPCHECK_CACHE_DIR", str(tmp_path))
|
|
77
|
+
from importlib import reload
|
|
78
|
+
import depshift.cache as cache
|
|
79
|
+
reload(cache)
|
|
80
|
+
|
|
81
|
+
cache.disable_cache()
|
|
82
|
+
cache.cache_set("key", "value")
|
|
83
|
+
assert cache.cache_get("key") is None
|
|
84
|
+
# re-enable for subsequent tests by reloading
|
|
85
|
+
reload(cache)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def test_cache_key_collision_resistance(tmp_path, monkeypatch):
|
|
89
|
+
monkeypatch.setenv("PYUPCHECK_CACHE_DIR", str(tmp_path))
|
|
90
|
+
from importlib import reload
|
|
91
|
+
import depshift.cache as cache
|
|
92
|
+
reload(cache)
|
|
93
|
+
|
|
94
|
+
cache.cache_set("key:a", "value_a")
|
|
95
|
+
cache.cache_set("key:b", "value_b")
|
|
96
|
+
assert cache.cache_get("key:a") == "value_a"
|
|
97
|
+
assert cache.cache_get("key:b") == "value_b"
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"""Tests for changelog parsing."""
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from depshift.changelog import (
|
|
6
|
+
parse_changelog_text,
|
|
7
|
+
parse_sectioned_changelog,
|
|
8
|
+
extract_github_repo,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# ── parse_changelog_text ──────────────────────────────────────────────────────
|
|
13
|
+
|
|
14
|
+
def test_detects_removed():
|
|
15
|
+
entries = parse_changelog_text("- Removed `Session.get` method", "2.0")
|
|
16
|
+
assert any(e.kind == "removed" for e in entries)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def test_detects_deprecated():
|
|
20
|
+
entries = parse_changelog_text("- Deprecated `requests.packages` - use urllib3 instead", "2.0")
|
|
21
|
+
assert any(e.kind == "deprecated" for e in entries)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_detects_renamed():
|
|
25
|
+
entries = parse_changelog_text("- Renamed `old_func` to `new_func`", "2.0")
|
|
26
|
+
assert any(e.kind == "renamed" for e in entries)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_extracts_version():
|
|
30
|
+
entries = parse_changelog_text("- Removed `get` function", "3.1.0")
|
|
31
|
+
assert all(e.version == "3.1.0" for e in entries)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_empty_text_returns_empty():
|
|
35
|
+
entries = parse_changelog_text("", "2.0")
|
|
36
|
+
assert entries == []
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_no_breaking_text_returns_empty():
|
|
40
|
+
entries = parse_changelog_text("Fixed a bug with SSL handshakes", "2.0")
|
|
41
|
+
assert entries == []
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_multiple_entries_in_one_block():
|
|
45
|
+
text = """
|
|
46
|
+
- Removed `Session.get`
|
|
47
|
+
- Deprecated `packages.urllib3`
|
|
48
|
+
- Renamed `old_api` to `new_api`
|
|
49
|
+
"""
|
|
50
|
+
entries = parse_changelog_text(text, "2.0")
|
|
51
|
+
assert len(entries) >= 3
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_extracts_api_name_from_backticks():
|
|
55
|
+
entries = parse_changelog_text("- Removed `requests.get` in this version", "2.0")
|
|
56
|
+
apis = [e.api for e in entries]
|
|
57
|
+
assert any("requests" in a or "get" in a for a in apis)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_description_populated():
|
|
61
|
+
entries = parse_changelog_text("- Removed `get` function from Session", "2.0")
|
|
62
|
+
assert all(len(e.description) > 0 for e in entries)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# ── parse_sectioned_changelog ─────────────────────────────────────────────────
|
|
66
|
+
|
|
67
|
+
def test_sectioned_parses_version_headers():
|
|
68
|
+
text = """
|
|
69
|
+
## 2.0.0
|
|
70
|
+
|
|
71
|
+
- Removed `old_func`
|
|
72
|
+
|
|
73
|
+
## 1.9.0
|
|
74
|
+
|
|
75
|
+
- Fixed a bug
|
|
76
|
+
"""
|
|
77
|
+
entries = parse_sectioned_changelog(text, "mypkg")
|
|
78
|
+
assert any(e.version == "2.0.0" for e in entries)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_sectioned_v_prefix_header():
|
|
82
|
+
text = """
|
|
83
|
+
v3.0.0
|
|
84
|
+
------
|
|
85
|
+
|
|
86
|
+
- Deprecated `legacy_method`
|
|
87
|
+
"""
|
|
88
|
+
entries = parse_sectioned_changelog(text, "mypkg")
|
|
89
|
+
assert any(e.version == "3.0.0" for e in entries)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_sectioned_empty_returns_empty():
|
|
93
|
+
entries = parse_sectioned_changelog("", "mypkg")
|
|
94
|
+
assert entries == []
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def test_sectioned_no_version_headers_returns_empty():
|
|
98
|
+
text = "Just some text without version headers"
|
|
99
|
+
entries = parse_sectioned_changelog(text, "mypkg")
|
|
100
|
+
assert entries == []
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
# ── extract_github_repo ───────────────────────────────────────────────────────
|
|
104
|
+
|
|
105
|
+
def test_extracts_from_project_urls():
|
|
106
|
+
info = {
|
|
107
|
+
"info": {
|
|
108
|
+
"project_urls": {"Homepage": "https://github.com/psf/requests"},
|
|
109
|
+
"home_page": None,
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
result = extract_github_repo(info)
|
|
113
|
+
assert result == ("psf", "requests")
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def test_extracts_from_home_page():
|
|
117
|
+
info = {
|
|
118
|
+
"info": {
|
|
119
|
+
"project_urls": {},
|
|
120
|
+
"home_page": "https://github.com/pallets/flask",
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
result = extract_github_repo(info)
|
|
124
|
+
assert result == ("pallets", "flask")
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def test_strips_dot_git_suffix():
|
|
128
|
+
info = {
|
|
129
|
+
"info": {
|
|
130
|
+
"project_urls": {"Source": "https://github.com/org/repo.git"},
|
|
131
|
+
"home_page": None,
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
result = extract_github_repo(info)
|
|
135
|
+
assert result == ("org", "repo")
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def test_no_github_url_returns_none():
|
|
139
|
+
info = {
|
|
140
|
+
"info": {
|
|
141
|
+
"project_urls": {"Homepage": "https://example.com/myproject"},
|
|
142
|
+
"home_page": None,
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
result = extract_github_repo(info)
|
|
146
|
+
assert result is None
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def test_missing_project_urls_returns_none():
|
|
150
|
+
info = {"info": {"project_urls": None, "home_page": None}}
|
|
151
|
+
result = extract_github_repo(info)
|
|
152
|
+
assert result is None
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""Tests for config loading."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import tempfile
|
|
5
|
+
|
|
6
|
+
import pytest
|
|
7
|
+
|
|
8
|
+
from depshift.config import Config, load_config
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def write(path, content):
|
|
12
|
+
with open(path, "w") as f:
|
|
13
|
+
f.write(content)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_defaults_when_no_files():
|
|
17
|
+
with tempfile.TemporaryDirectory() as d:
|
|
18
|
+
cfg = load_config(d)
|
|
19
|
+
assert cfg.fail_on == "breaking"
|
|
20
|
+
assert cfg.min_severity == "warning"
|
|
21
|
+
assert cfg.cache is True
|
|
22
|
+
assert len(cfg.exclude_dirs) == 0
|
|
23
|
+
assert len(cfg.ignore_packages) == 0
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_pyproject_toml_section():
|
|
27
|
+
with tempfile.TemporaryDirectory() as d:
|
|
28
|
+
write(os.path.join(d, "pyproject.toml"), """
|
|
29
|
+
[tool.pyupcheck]
|
|
30
|
+
fail_on = "any"
|
|
31
|
+
min_severity = "deprecated"
|
|
32
|
+
cache = false
|
|
33
|
+
exclude = ["migrations", "legacy"]
|
|
34
|
+
ignore = ["internal-pkg"]
|
|
35
|
+
""")
|
|
36
|
+
cfg = load_config(d)
|
|
37
|
+
assert cfg.fail_on == "any"
|
|
38
|
+
assert cfg.min_severity == "deprecated"
|
|
39
|
+
assert cfg.cache is False
|
|
40
|
+
assert "migrations" in cfg.exclude_dirs
|
|
41
|
+
assert "legacy" in cfg.exclude_dirs
|
|
42
|
+
assert "internal-pkg" in cfg.ignore_packages
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_pyupcheckignore_directories():
|
|
46
|
+
with tempfile.TemporaryDirectory() as d:
|
|
47
|
+
write(os.path.join(d, ".pyupcheckignore"), "migrations/\nlegacy/\n")
|
|
48
|
+
cfg = load_config(d)
|
|
49
|
+
assert "migrations" in cfg.exclude_dirs
|
|
50
|
+
assert "legacy" in cfg.exclude_dirs
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_pyupcheckignore_packages():
|
|
54
|
+
with tempfile.TemporaryDirectory() as d:
|
|
55
|
+
write(os.path.join(d, ".pyupcheckignore"), "my-internal-pkg\n")
|
|
56
|
+
cfg = load_config(d)
|
|
57
|
+
assert "my-internal-pkg" in cfg.ignore_packages
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_pyupcheckignore_comments_ignored():
|
|
61
|
+
with tempfile.TemporaryDirectory() as d:
|
|
62
|
+
write(os.path.join(d, ".pyupcheckignore"), "# this is a comment\nmigrations/\n")
|
|
63
|
+
cfg = load_config(d)
|
|
64
|
+
assert "migrations" in cfg.exclude_dirs
|
|
65
|
+
assert len([d for d in cfg.exclude_dirs if d.startswith("#")]) == 0
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_pyupcheckignore_empty_lines_ignored():
|
|
69
|
+
with tempfile.TemporaryDirectory() as d:
|
|
70
|
+
write(os.path.join(d, ".pyupcheckignore"), "\n\nmigrations/\n\n")
|
|
71
|
+
cfg = load_config(d)
|
|
72
|
+
assert "migrations" in cfg.exclude_dirs
|
|
73
|
+
assert "" not in cfg.exclude_dirs
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def test_both_files_merged():
|
|
77
|
+
with tempfile.TemporaryDirectory() as d:
|
|
78
|
+
write(os.path.join(d, "pyproject.toml"), """
|
|
79
|
+
[tool.pyupcheck]
|
|
80
|
+
exclude = ["migrations"]
|
|
81
|
+
""")
|
|
82
|
+
write(os.path.join(d, ".pyupcheckignore"), "legacy/\n")
|
|
83
|
+
cfg = load_config(d)
|
|
84
|
+
assert "migrations" in cfg.exclude_dirs
|
|
85
|
+
assert "legacy" in cfg.exclude_dirs
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def test_ignore_packages_lowercased():
|
|
89
|
+
with tempfile.TemporaryDirectory() as d:
|
|
90
|
+
write(os.path.join(d, ".pyupcheckignore"), "MyPkg\n")
|
|
91
|
+
cfg = load_config(d)
|
|
92
|
+
assert "mypkg" in cfg.ignore_packages
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def test_nonexistent_dir_returns_defaults():
|
|
96
|
+
cfg = load_config("/tmp/definitely_does_not_exist_xyz_abc")
|
|
97
|
+
assert cfg.fail_on == "breaking"
|
|
98
|
+
assert cfg.cache is True
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""Tests for argument-level precise risk matching."""
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from depshift.scanner import Usage
|
|
6
|
+
from depshift.apisurface import APIChange
|
|
7
|
+
from depshift.precise import match_precise, _short_name, _usage_callable
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def make_usage(attr_chain: str, kwargs=None, usage_type="function_call") -> Usage:
|
|
11
|
+
return Usage(
|
|
12
|
+
file="test.py", line=1,
|
|
13
|
+
code=f"{attr_chain}()",
|
|
14
|
+
attr_chain=attr_chain,
|
|
15
|
+
usage_type=usage_type,
|
|
16
|
+
kwargs=kwargs or [],
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def make_change(kind: str, api: str, param=None) -> APIChange:
|
|
21
|
+
return APIChange(
|
|
22
|
+
kind=kind, api=api,
|
|
23
|
+
detail=f"{kind} {api}",
|
|
24
|
+
param=param,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# ── helpers ───────────────────────────────────────────────────────────────────
|
|
29
|
+
|
|
30
|
+
def test_short_name():
|
|
31
|
+
assert _short_name("requests.auth.HTTPBasicAuth", "requests") == "HTTPBasicAuth"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_usage_callable():
|
|
35
|
+
u = make_usage("requests.get")
|
|
36
|
+
assert _usage_callable(u, "requests") == "get"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# ── removed function ──────────────────────────────────────────────────────────
|
|
40
|
+
|
|
41
|
+
def test_removed_function_flagged():
|
|
42
|
+
usage = make_usage("requests.get")
|
|
43
|
+
change = make_change("removed_function", "requests.get")
|
|
44
|
+
risks = match_precise([usage], [change], "requests")
|
|
45
|
+
assert len(risks) == 1
|
|
46
|
+
assert risks[0].severity == "breaking"
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_removed_function_not_used_not_flagged():
|
|
50
|
+
usage = make_usage("requests.post")
|
|
51
|
+
change = make_change("removed_function", "requests.get")
|
|
52
|
+
risks = match_precise([usage], [change], "requests")
|
|
53
|
+
assert len(risks) == 0
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# ── removed parameter ─────────────────────────────────────────────────────────
|
|
57
|
+
|
|
58
|
+
def test_removed_param_flagged_when_kwarg_used():
|
|
59
|
+
usage = make_usage("requests.get", kwargs=["url", "verify"])
|
|
60
|
+
change = make_change("removed_param", "requests.get", param="verify")
|
|
61
|
+
risks = match_precise([usage], [change], "requests")
|
|
62
|
+
assert len(risks) == 1
|
|
63
|
+
assert risks[0].reason.startswith("You pass 'verify='")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def test_removed_param_not_flagged_when_kwarg_not_used():
|
|
67
|
+
usage = make_usage("requests.get", kwargs=["url", "timeout"])
|
|
68
|
+
change = make_change("removed_param", "requests.get", param="verify")
|
|
69
|
+
risks = match_precise([usage], [change], "requests")
|
|
70
|
+
assert len(risks) == 0
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def test_removed_param_not_flagged_when_no_kwargs():
|
|
74
|
+
usage = make_usage("requests.get", kwargs=[])
|
|
75
|
+
change = make_change("removed_param", "requests.get", param="verify")
|
|
76
|
+
risks = match_precise([usage], [change], "requests")
|
|
77
|
+
assert len(risks) == 0
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def test_multiple_removed_params_each_flagged():
|
|
81
|
+
usage = make_usage("requests.get", kwargs=["verify", "cert", "timeout"])
|
|
82
|
+
changes = [
|
|
83
|
+
make_change("removed_param", "requests.get", param="verify"),
|
|
84
|
+
make_change("removed_param", "requests.get", param="cert"),
|
|
85
|
+
]
|
|
86
|
+
risks = match_precise([usage], changes, "requests")
|
|
87
|
+
assert len(risks) == 2
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
# ── removed class ─────────────────────────────────────────────────────────────
|
|
91
|
+
|
|
92
|
+
def test_removed_class_flagged():
|
|
93
|
+
usage = make_usage("requests.Session", usage_type="attribute_access")
|
|
94
|
+
change = make_change("removed_class", "requests.Session")
|
|
95
|
+
risks = match_precise([usage], [change], "requests")
|
|
96
|
+
assert len(risks) == 1
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
# ── multiple usages ───────────────────────────────────────────────────────────
|
|
100
|
+
|
|
101
|
+
def test_multiple_usages_only_affected_flagged():
|
|
102
|
+
usages = [
|
|
103
|
+
make_usage("requests.get", kwargs=["verify"]),
|
|
104
|
+
make_usage("requests.post", kwargs=["json"]),
|
|
105
|
+
make_usage("requests.Session"),
|
|
106
|
+
]
|
|
107
|
+
changes = [make_change("removed_param", "requests.get", param="verify")]
|
|
108
|
+
risks = match_precise(usages, changes, "requests")
|
|
109
|
+
assert len(risks) == 1
|
|
110
|
+
assert risks[0].usage.attr_chain == "requests.get"
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def test_no_changes_no_risks():
|
|
114
|
+
usages = [make_usage("requests.get", kwargs=["verify"])]
|
|
115
|
+
risks = match_precise(usages, [], "requests")
|
|
116
|
+
assert len(risks) == 0
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def test_no_usages_no_risks():
|
|
120
|
+
changes = [make_change("removed_function", "requests.get")]
|
|
121
|
+
risks = match_precise([], changes, "requests")
|
|
122
|
+
assert len(risks) == 0
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"""Tests for HTML and Markdown report generation."""
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from depshift.report import render_markdown, render_html
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def make_result(breaking=0, deprecated=0, safe=5, package="flask", risks=None):
|
|
9
|
+
if risks is None:
|
|
10
|
+
risks = []
|
|
11
|
+
for i in range(breaking):
|
|
12
|
+
risks.append({
|
|
13
|
+
"file": f"src/file{i}.py", "line": i + 1,
|
|
14
|
+
"code": f"flask.removed_func{i}()",
|
|
15
|
+
"api": f"flask.removed_func{i}",
|
|
16
|
+
"severity": "breaking",
|
|
17
|
+
"change_kind": "removed",
|
|
18
|
+
"change_description": f"Removed function removed_func{i}",
|
|
19
|
+
"change_version": "2.0",
|
|
20
|
+
})
|
|
21
|
+
for i in range(deprecated):
|
|
22
|
+
risks.append({
|
|
23
|
+
"file": f"src/dep{i}.py", "line": i + 10,
|
|
24
|
+
"code": f"flask.old_api{i}()",
|
|
25
|
+
"api": f"flask.old_api{i}",
|
|
26
|
+
"severity": "deprecated",
|
|
27
|
+
"change_kind": "deprecated",
|
|
28
|
+
"change_description": f"Deprecated old_api{i}",
|
|
29
|
+
"change_version": "2.0",
|
|
30
|
+
})
|
|
31
|
+
return {
|
|
32
|
+
"package": package,
|
|
33
|
+
"current_version": "1.0",
|
|
34
|
+
"target_version": "2.0",
|
|
35
|
+
"risks": risks,
|
|
36
|
+
"safe_count": safe,
|
|
37
|
+
"breaking_count": breaking,
|
|
38
|
+
"deprecated_count": deprecated,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# ── markdown ──────────────────────────────────────────────────────────────────
|
|
43
|
+
|
|
44
|
+
def test_markdown_contains_package_name():
|
|
45
|
+
md = render_markdown([make_result()])
|
|
46
|
+
assert "flask" in md
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_markdown_empty_results():
|
|
50
|
+
md = render_markdown([])
|
|
51
|
+
assert "pyupcheck report" in md
|
|
52
|
+
assert "0" in md
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_markdown_breaking_status():
|
|
56
|
+
md = render_markdown([make_result(breaking=2)])
|
|
57
|
+
assert "BREAKING" in md
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_markdown_ok_status():
|
|
61
|
+
md = render_markdown([make_result(breaking=0, deprecated=0)])
|
|
62
|
+
assert "OK" in md
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_markdown_deprecated_status():
|
|
66
|
+
md = render_markdown([make_result(deprecated=1)])
|
|
67
|
+
assert "DEPRECATED" in md
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_markdown_pipe_chars_escaped():
|
|
71
|
+
result = make_result(risks=[{
|
|
72
|
+
"file": "a|b.py", "line": 1, "code": "x | y",
|
|
73
|
+
"api": "pkg.f", "severity": "breaking",
|
|
74
|
+
"change_kind": "removed",
|
|
75
|
+
"change_description": "removed | this",
|
|
76
|
+
"change_version": "2.0",
|
|
77
|
+
}], breaking=1, safe=0)
|
|
78
|
+
md = render_markdown([result])
|
|
79
|
+
assert "\\|" in md
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_markdown_multiple_packages():
|
|
83
|
+
results = [make_result(package="flask"), make_result(package="requests")]
|
|
84
|
+
md = render_markdown(results)
|
|
85
|
+
assert "flask" in md
|
|
86
|
+
assert "requests" in md
|
|
87
|
+
assert "2" in md # 2 packages checked
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def test_markdown_has_table():
|
|
91
|
+
md = render_markdown([make_result(breaking=1)])
|
|
92
|
+
assert "|" in md
|
|
93
|
+
assert "---" in md
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_markdown_safe_count_shown():
|
|
97
|
+
md = render_markdown([make_result(safe=13)])
|
|
98
|
+
assert "13" in md
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
# ── html ──────────────────────────────────────────────────────────────────────
|
|
102
|
+
|
|
103
|
+
def test_html_valid_structure():
|
|
104
|
+
html = render_html([make_result()])
|
|
105
|
+
assert "<!DOCTYPE html>" in html
|
|
106
|
+
assert "<html" in html
|
|
107
|
+
assert "</html>" in html
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def test_html_package_name_escaped():
|
|
111
|
+
result = make_result(package="<script>alert(1)</script>")
|
|
112
|
+
html = render_html([result])
|
|
113
|
+
assert "<script>" not in html
|
|
114
|
+
assert "<script>" in html
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def test_html_breaking_badge():
|
|
118
|
+
html = render_html([make_result(breaking=1)])
|
|
119
|
+
assert "BREAKING" in html
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def test_html_ok_badge():
|
|
123
|
+
html = render_html([make_result(breaking=0)])
|
|
124
|
+
assert "OK" in html
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def test_html_empty_results():
|
|
128
|
+
html = render_html([])
|
|
129
|
+
assert "<!DOCTYPE html>" in html
|
|
130
|
+
assert "0" in html
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def test_html_contains_table():
|
|
134
|
+
html = render_html([make_result(breaking=1)])
|
|
135
|
+
assert "<table" in html
|
|
136
|
+
assert "</table>" in html
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def test_html_risk_description_escaped():
|
|
140
|
+
result = make_result(risks=[{
|
|
141
|
+
"file": "a.py", "line": 1, "code": "f()",
|
|
142
|
+
"api": "pkg.f", "severity": "breaking",
|
|
143
|
+
"change_kind": "removed",
|
|
144
|
+
"change_description": "<img src=x onerror=alert(1)>",
|
|
145
|
+
"change_version": "2.0",
|
|
146
|
+
}], breaking=1, safe=0)
|
|
147
|
+
html = render_html([result])
|
|
148
|
+
assert "<img" not in html
|
|
149
|
+
assert "<img" in html
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|