MCPcopy Create free account
hub / github.com/ParzivalHack/PySpector / TestFileContentExclude

Class TestFileContentExclude

tests/unit/test_missing_rules.py:388–414  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

386# ============================================================
387# file_content_exclude — PY302/PY107 ruamel false positive fix
388# ============================================================
389
390class TestFileContentExclude:
391 def test_pyyaml_unsafe_fires(self):
392 # Plain PyYAML import with unsafe load — must fire
393 code = "import yaml\nyaml.load(data)"
394 # YAML001 (Critical) shares CWE-502 and wins the CWE-aware dedup (#56)
395 assert fires(code, "PY302") or fires(code, "YAML001"), \
396 "PY302/YAML001 must fire for PyYAML yaml.load() without Loader"
397
398 def test_ruamel_yaml_round_trip_not_flagged_yaml001(self):
399 # YAML001 shares CWE-502 with PY302 and must honour the same ruamel exclusion
400 code = "from ruamel.yaml import YAML\nyaml = YAML()\nyaml.load(stream)"
401 assert not_fires(code, "YAML001"), "YAML001 must NOT fire for ruamel YAML() round-trip"
402
403 def test_ruamel_yaml_suppressed(self, tmp_path):
404 # ruamel.yaml with YAML() round-trip is safe — must NOT fire
405 # file_content_exclude = "from ruamel.yaml|import ruamel" suppresses it
406 from pyspector._rust_core import run_scan
407 from pyspector.config import get_default_rules
408 import ast as _ast, json as _json, os, warnings
409 from pyspector.cli import AstEncoder
410
411 code = "from ruamel.yaml import YAML\nyaml = YAML()\nyaml.load(stream)"
412 filename = str(tmp_path / "settings.py")
413 with open(filename, "w") as f:
414 f.write(code)
415 rules_toml = get_default_rules()
416 tree = _ast.parse(code, filename=filename)
417 ast_json = _json.dumps(_ast.dump(tree), cls=AstEncoder)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected