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

Class TestAI202

tests/unit/test_ai_rules.py:179–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

177 """
178 assert not fires(code, "AI204")
179class TestAI202:
180 def test_rule_metadata(self):
181 rule = _ai_rule("AI202")
182 assert rule["severity"] == "High"
183 assert rule["cwe"] == "CWE-502"
184 assert rule["pattern"] == r"torch\.load\s*\("
185 assert rule["exclude_pattern"] == r"^\s*#|weights_only\s*=\s*True"
186
187 @pytest.mark.parametrize(
188 "code",
189 [
190 'model = torch.load("model.pt")',
191 "checkpoint = torch.load(path, map_location='cpu')",
192 ],
193 )
194 def test_pattern_matches_torch_load_calls(self, code):
195 rule = _ai_rule("AI202")
196 assert re.search(rule["pattern"], code)
197 assert not re.search(rule["exclude_pattern"], code)
198
199 @pytest.mark.parametrize(
200 "code",
201 [
202 '# model = torch.load("model.pt")',
203 'model = torch.load("model.pt", weights_only=True)',
204 'model = torch.load("model.pt", weights_only = True)',
205 ],
206 )
207 def test_exclude_pattern_suppresses_safe_or_comment_cases(self, code):
208 rule = _ai_rule("AI202")
209 assert re.search(rule["pattern"], code)
210 assert re.search(rule["exclude_pattern"], code)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected