@@ -194,99 +194,93 @@ def test_v2_to_v3_conversion():
194194 codetfv2 = CodeTF .model_validate_json (f .read ())
195195 codetf = from_v2 (codetfv2 )
196196
197- # run
198- assert codetf .run
199- assert codetf .run .vendor == codetfv2 .run .vendor
200- assert codetf .run .tool == codetfv2 .run .tool
201- assert codetf .run .version == codetfv2 .run .version
202- assert codetf .run .elapsed == codetfv2 .run .elapsed
197+ # run
198+ assert codetf .run
199+ assert codetf .run .vendor == codetfv2 .run .vendor
200+ assert codetf .run .tool == codetfv2 .run .tool
201+ assert codetf .run .version == codetfv2 .run .version
202+ assert codetf .run .elapsed == codetfv2 .run .elapsed
203+
204+ assert (
205+ codetf .run .projectmetadata
206+ and "directory" in codetf .run .projectmetadata .keys ()
207+ and codetf .run .projectmetadata ["directory" ] == codetfv2 .run .directory
208+ )
209+ assert (
210+ codetf .run .projectmetadata
211+ and "projectName" not in codetf .run .projectmetadata .keys ()
212+ and not codetfv2 .run .projectName
213+ )
214+
215+ assert (
216+ codetf .run .inputmetadata
217+ and "commandLine" in codetf .run .inputmetadata .keys ()
218+ and codetf .run .inputmetadata ["commandLine" ] == codetfv2 .run .commandLine
219+ )
220+ assert not codetfv2 .run .sarifs
221+ assert codetf .run .inputmetadata and "sarifs" not in codetf .run .inputmetadata .keys ()
222+ # results
223+ v2_unfixed = [f for r in codetfv2 .results for f in r .unfixedFindings or []]
224+ v2_fixed = [
225+ f
226+ for r in codetfv2 .results
227+ for cs in r .changeset
228+ for c in cs .changes
229+ for f in c .fixedFindings or []
230+ ]
231+ unfixed = [
232+ fr for fr in codetf .results if fr .fixStatus .status == FixStatusType .failed
233+ ]
234+ fixed = [fr for fr in codetf .results if fr .fixStatus .status == FixStatusType .fixed ]
235+
236+ # length
237+ assert len (codetf .results ) == len (v2_unfixed ) + len (v2_fixed ) == 3
238+ assert len (unfixed ) == len (v2_unfixed ) == 1
239+ assert len (fixed ) == len (v2_fixed ) == 2
240+
241+ assert len (codetfv2 .results ) == 1
242+ assert len (codetfv2 .results [0 ].changeset ) == 1
243+ v2result = codetfv2 .results [0 ]
244+ v2changeset = codetfv2 .results [0 ].changeset [0 ]
245+ v2_finding_to_change = {
246+ f : c
247+ for r in codetfv2 .results
248+ for cs in r .changeset
249+ for c in cs .changes
250+ for f in c .fixedFindings or []
251+ }
203252
253+ for f in fixed :
254+ # fix metadata
204255 assert (
205- codetf . run . projectmetadata
206- and "directory" in codetf . run . projectmetadata . keys ()
207- and codetf . run . projectmetadata [ "directory" ] == codetfv2 . run . directory
256+ f . fixMetadata
257+ and f . fixMetadata . generation
258+ and f . fixMetadata . generation . ai == v2changeset . ai
208259 )
209260 assert (
210- codetf .run .projectmetadata
211- and "projectName" not in codetf .run .projectmetadata .keys ()
212- and not codetfv2 .run .projectName
261+ f .fixMetadata and f .fixMetadata .id and f .fixMetadata .id == v2result .codemod
213262 )
214-
215263 assert (
216- codetf . run . inputmetadata
217- and "commandLine" in codetf . run . inputmetadata . keys ()
218- and codetf . run . inputmetadata [ "commandLine" ] == codetfv2 . run . commandLine
264+ f . fixMetadata
265+ and f . fixMetadata . summary
266+ and f . fixMetadata . summary == v2result . summary
219267 )
220- assert not codetfv2 .run .sarifs
221268 assert (
222- codetf .run .inputmetadata and "sarifs" not in codetf .run .inputmetadata .keys ()
269+ f .fixMetadata
270+ and f .fixMetadata .description
271+ and f .fixMetadata .description == v2result .description
223272 )
224- # results
225- v2_unfixed = [f for r in codetfv2 .results for f in r .unfixedFindings or []]
226- v2_fixed = [
227- f
228- for r in codetfv2 .results
229- for cs in r .changeset
230- for c in cs .changes
231- for f in c .fixedFindings or []
232- ]
233- unfixed = [
234- fr for fr in codetf .results if fr .fixStatus .status == FixStatusType .failed
235- ]
236- fixed = [
237- fr for fr in codetf .results if fr .fixStatus .status == FixStatusType .fixed
273+
274+ # correctly associates findings to the change
275+ assert f .changeSets and f .changeSets [0 ].path == v2changeset .path
276+ assert f .changeSets and f .changeSets [0 ].diff == v2changeset .diff
277+ assert isinstance (f .finding , Finding ) and f .changeSets [0 ].changes == [
278+ v2_finding_to_change [f .finding ].to_common ()
238279 ]
239280
240- # length
241- assert len (codetf .results ) == len (v2_unfixed ) + len (v2_fixed ) == 3
242- assert len (unfixed ) == len (v2_unfixed ) == 1
243- assert len (fixed ) == len (v2_fixed ) == 2
244-
245- assert len (codetfv2 .results ) == 1
246- assert len (codetfv2 .results [0 ].changeset ) == 1
247- v2result = codetfv2 .results [0 ]
248- v2changeset = codetfv2 .results [0 ].changeset [0 ]
249- v2_finding_to_change = {
250- f : c
251- for r in codetfv2 .results
252- for cs in r .changeset
253- for c in cs .changes
254- for f in c .fixedFindings or []
255- }
256-
257- for f in fixed :
258- # fix metadata
259- assert (
260- f .fixMetadata
261- and f .fixMetadata .generation
262- and f .fixMetadata .generation .ai == v2changeset .ai
263- )
264- assert (
265- f .fixMetadata
266- and f .fixMetadata .id
267- and f .fixMetadata .id == v2result .codemod
268- )
269- assert (
270- f .fixMetadata
271- and f .fixMetadata .summary
272- and f .fixMetadata .summary == v2result .summary
273- )
274- assert (
275- f .fixMetadata
276- and f .fixMetadata .description
277- and f .fixMetadata .description == v2result .description
278- )
279-
280- # correctly associates findings to the change
281- assert f .changeSets and f .changeSets [0 ].path == v2changeset .path
282- assert f .changeSets and f .changeSets [0 ].diff == v2changeset .diff
283- assert isinstance (f .finding , Finding ) and f .changeSets [0 ].changes == [
284- v2_finding_to_change [f .finding ].to_common ()
285- ]
286-
287- # unfixed metadata
288- assert (
289- unfixed [0 ].fixStatus .reason
290- and unfixed [0 ].fixStatus .reason == v2_unfixed [0 ].reason
291- )
292- assert unfixed [0 ].finding == v2_unfixed [0 ]
281+ # unfixed metadata
282+ assert (
283+ unfixed [0 ].fixStatus .reason
284+ and unfixed [0 ].fixStatus .reason == v2_unfixed [0 ].reason
285+ )
286+ assert unfixed [0 ].finding == v2_unfixed [0 ]
0 commit comments