Developer tools dump stack traces, exit codes, and jargon. Figuring out *what to do next* often means searching the same Stack Overflow answers again.
| 1 | """Python rule tests.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import pytest |
| 6 | |
| 7 | from why_failed.matcher import analyze |
| 8 | |
| 9 | CASES = [ |
| 10 | ("ModuleNotFoundError: No module named 'requests'", "python.module_not_found"), |
| 11 | ("ImportError: cannot import name 'foo' from 'bar'", "python.import_error"), |
| 12 | ("ERROR: No matching distribution found for some-pkg==99.0", "python.no_matching_distribution"), |
| 13 | ("error: externally-managed-environment", "python.externally_managed"), |
| 14 | ("SyntaxError: invalid syntax", "python.syntax_error"), |
| 15 | ("IndentationError: unexpected indent", "python.indentation_error"), |
| 16 | ("ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/", "python.pip_dependency_conflict"), |
| 17 | ("ERROR: Package 'x' requires a different Python: 3.11.0 not in '>=3.12'", "python.version_incompatible"), |
| 18 | ] |
| 19 | |
| 20 | |
| 21 | @pytest.mark.parametrize("text,rule_id", CASES) |
| 22 | def test_python_rules(text: str, rule_id: str) -> None: |
| 23 | result = analyze(text) |
| 24 | assert result.match is not None |
| 25 | assert result.match.rule_id == rule_id |