@@ -62,8 +62,14 @@ def setup_class(cls):
6262
6363 def setup_method (self ):
6464 try :
65- self .codemod_wrapper = self .codemod_registry .match_codemods (
66- codemod_include = [self .codemod .name ()]
65+ name = (
66+ self .codemod ().name
67+ if isinstance (self .codemod , type )
68+ else self .codemod .name
69+ )
70+ # This is how we ensure that the codemod is actually in the registry
71+ self .codemod_instance = self .codemod_registry .match_codemods (
72+ codemod_include = [name ]
6773 )[0 ]
6874 except IndexError as exc :
6975 raise IndexError (
@@ -77,16 +83,18 @@ def _assert_run_fields(self, run, output_path):
7783 assert run ["elapsed" ] != ""
7884 assert (
7985 run ["commandLine" ]
80- == f"codemodder { SAMPLES_DIR } --output { output_path } --codemod-include={ self .codemod_wrapper .name } --path-include={ self .code_path } "
86+ == f"codemodder { SAMPLES_DIR } --output { output_path } --codemod-include={ self .codemod_instance .name } --path-include={ self .code_path } "
8187 )
8288 assert run ["directory" ] == os .path .abspath (SAMPLES_DIR )
8389 assert run ["sarifs" ] == []
8490
8591 def _assert_results_fields (self , results , output_path ):
8692 assert len (results ) == 1
8793 result = results [0 ]
88- assert result ["codemod" ] == self .codemod_wrapper .id
89- assert result ["references" ] == self .codemod_wrapper .references
94+ assert result ["codemod" ] == self .codemod_instance .id
95+ assert result ["references" ] == [
96+ ref .to_json () for ref in self .codemod_instance .references
97+ ]
9098
9199 # TODO: once we add description for each url.
92100 for reference in result ["references" ]:
@@ -147,7 +155,7 @@ def test_file_rewritten(self):
147155 SAMPLES_DIR ,
148156 "--output" ,
149157 self .output_path ,
150- f"--codemod-include={ self .codemod_wrapper .name } " ,
158+ f"--codemod-include={ self .codemod_instance .name } " ,
151159 f"--path-include={ self .code_path } " ,
152160 ]
153161
0 commit comments