66from types import ModuleType
77
88import git
9+ import jsonschema
910
1011from codemodder import __version__ , registry
1112
@@ -99,7 +100,8 @@ def _assert_results_fields(self, results, output_path):
99100 result = results [0 ]
100101 assert result ["codemod" ] == self .codemod_instance .id
101102 assert result ["references" ] == [
102- ref .to_json () for ref in self .codemod_instance .references
103+ ref .model_dump (exclude_none = True )
104+ for ref in self .codemod_instance .references
103105 ]
104106
105107 # TODO: once we add description for each url.
@@ -118,15 +120,15 @@ def _assert_results_fields(self, results, output_path):
118120
119121 assert len (change ["changes" ]) == self .num_changes
120122 line_change = change ["changes" ][0 ]
121- assert line_change ["lineNumber" ] == str (self .expected_line_change )
123+ assert line_change ["lineNumber" ] == int (self .expected_line_change )
122124 assert line_change ["description" ] == self .change_description
123- assert line_change ["packageActions" ] == []
124- assert line_change ["properties" ] == {}
125125
126- def _assert_codetf_output (self ):
126+ def _assert_codetf_output (self , codetf_schema ):
127127 with open (self .output_path , "r" , encoding = "utf-8" ) as f :
128128 codetf = json .load (f )
129129
130+ jsonschema .validate (codetf , codetf_schema )
131+
130132 assert sorted (codetf .keys ()) == ["results" , "run" ]
131133 run = codetf ["run" ]
132134 self ._assert_run_fields (run , self .output_path )
@@ -149,7 +151,7 @@ def check_code_after(self) -> ModuleType:
149151 path = self .code_path , allowed_exceptions = self .allowed_exceptions
150152 )
151153
152- def test_file_rewritten (self ):
154+ def test_file_rewritten (self , codetf_schema ):
153155 """
154156 Tests that file is re-written correctly with new code and correct codetf output.
155157
@@ -183,7 +185,7 @@ def test_file_rewritten(self):
183185
184186 self .check_code_after ()
185187 self .check_dependencies_after ()
186- self ._assert_codetf_output ()
188+ self ._assert_codetf_output (codetf_schema )
187189 pathlib .Path (self .output_path ).unlink (missing_ok = True )
188190 self ._run_idempotency_chec (command )
189191
0 commit comments