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

Method test_to_sarif

tests/unit/reporting_test.py:75–121  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

73 # ------------------------------------------------------------------ #
74
75 def test_to_sarif(self):
76 reporter = Reporter([self.test_issue], "sarif")
77 output = reporter.to_sarif()
78
79 output_json = json.loads(output)
80
81 # Check top level SARIF fields
82 self.assertEqual(output_json.get("version"), "2.1.0")
83 self.assertEqual(
84 output_json.get("schema_uri"),
85 "https://raw.githubusercontent.com/oasis-tcs/"
86 "sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
87 )
88
89 # Check runs
90 self.assertIn("runs", output_json)
91 self.assertIsInstance(output_json["runs"], list)
92 self.assertEqual(len(output_json["runs"]), 1)
93
94 # Check unique single run
95 run = output_json["runs"][0]
96 self.assertEqual(run["tool"]["driver"]["name"], "PySpector")
97
98 # Check run results
99 self.assertIn("results", run)
100 self.assertIsInstance(run["results"], list)
101 self.assertEqual(len(run["results"]), 1)
102
103 # Check single run result
104 result = run["results"][0]
105
106 # Check rule id
107 self.assertEqual(result.get("rule_id"), self.test_issue.rule_id)
108
109 # Check description
110 self.assertIn("message", result)
111 self.assertEqual(result["message"].get("text"), self.test_issue.description)
112
113 # Check file_path
114 self.assertIn("locations", result)
115 self.assertIsInstance(result["locations"], list)
116 location = result["locations"][0]
117 self.assertIn("physical_location", location)
118 physical = location["physical_location"]
119 self.assertIn("artifact_location", physical)
120 artifact = physical["artifact_location"]
121 self.assertEqual(artifact.get("uri"), self.test_issue.file_path)
122
123 def test_to_sarif_result_has_level_field(self):
124 reporter = Reporter([self.test_issue], "sarif")

Callers

nothing calls this directly

Calls 2

to_sarifMethod · 0.95
ReporterClass · 0.90

Tested by

no test coverage detected