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

Class TestGlobalDefaults

tests/unit/test_false_positive_reductions.py:313–345  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

311# ===========================================================================
312
313class TestGlobalDefaults:
314 def test_global_exclusion_suppresses_any_rule_in_tests(self):
315 """
316 The [defaults] exclude_file_patterns applies to ALL rules without
317 needing to repeat exclude_file_pattern on each rule individually.
318
319 PY305 (exec) has NO per-rule exclude_file_pattern, yet it must be
320 suppressed in test files because [defaults] excludes *tests*.
321 """
322 code = "exec(user_input)\n"
323 # In tests/ dir → global default should suppress PY305
324 assert findings_for_rule(code, "PY305", in_tests_dir=True) == [], \
325 "PY305 must be suppressed in tests/ via global [defaults], no per-rule config needed"
326
327 def test_global_exclusion_does_not_suppress_production_code(self):
328 """Global defaults only exclude test files, not production code."""
329 code = "exec(user_input)\n"
330 assert findings_for_rule(code, "PY305", filename="runner.py", in_tests_dir=False) != [], \
331 "PY305 must still fire in production code"
332
333 def test_pickle_not_suppressed_by_global_defaults(self):
334 """
335 pickle.loads is a TRUE POSITIVE even in test files — it should still
336 fire because the [defaults] deliberately excludes test paths, and
337 pickle is a legitimate critical finding anywhere.
338
339 NOTE: if a project adds pickle to a test mock intentionally and wants
340 to suppress, they can use # noqa or a per-file override.
341 """
342 # pickle in a non-test file must still fire
343 code = "import pickle\nvalue = pickle.loads(data)\n"
344 assert findings_for_rule(code, "PY002", filename="cache.py", in_tests_dir=False) != [], \
345 "PY002 (pickle.loads) must fire in production code"
346
347
348# ===========================================================================

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected