33"""
44import os
55import re
6+ import typing as t
7+ from collections .abc import Callable , Sequence
68
79from click .testing import CliRunner
10+ from click .testing import Result as ClickTestResult
811
9- from code_annotations .base import BaseSearch , VerboseEcho
12+ from code_annotations .base import BaseSearch
1013from code_annotations .cli import entry_point
14+ from code_annotations .helpers import VerboseEcho
15+
16+ # Re-export Result for convenience
17+ Result = ClickTestResult
1118
1219EXIT_CODE_SUCCESS = 0
1320EXIT_CODE_FAILURE = 1
@@ -39,10 +46,10 @@ class FakeConfig:
3946 Simple config for testing without reading a config file.
4047 """
4148
42- annotations : dict [str , str ] = {}
49+ annotations : dict [str , t . Any ] = {}
4350 annotation_regexes : list [str ] = []
4451 annotation_tokens : list [str ] = []
45- groups : list [str ] = []
52+ groups : t . Union [ list [str ], dict [ str , list [ str ]] ] = []
4653 echo = VerboseEcho ()
4754
4855
@@ -51,13 +58,17 @@ class FakeSearch(BaseSearch):
5158 Simple test class for directly testing BaseSearch since it's abstract.
5259 """
5360
54- def search (self ):
61+ def search (self ) -> dict [ str , list [ dict [ str , t . Any ]]] :
5562 """
5663 Override for abstract base method.
64+
65+ Returns:
66+ Empty dict to satisfy the abstract method requirement
5767 """
68+ return {}
5869
5970
60- def delete_report_files (file_extension ) :
71+ def delete_report_files (file_extension : str ) -> None :
6172 """
6273 Delete all files with the given extension from the test_reports directory.
6374
@@ -76,7 +87,7 @@ def delete_report_files(file_extension):
7687 pass
7788
7889
79- def call_script (args_list , delete_test_reports = True , delete_test_docs = True ):
90+ def call_script (args_list : Sequence [ str ] , delete_test_reports : bool = True , delete_test_docs : bool = True ) -> Result :
8091 """
8192 Call the code_annotations script with the given params and a generic config file.
8293
@@ -108,11 +119,11 @@ def call_script(args_list, delete_test_reports=True, delete_test_docs=True):
108119
109120
110121def call_script_isolated (
111- args_list ,
112- test_filesystem_cb = None ,
113- test_filesystem_report_cb = None ,
114- fake_safelist_data = "{}"
115- ):
122+ args_list : list [ str ] ,
123+ test_filesystem_cb : Callable [[], None ] | None = None ,
124+ test_filesystem_report_cb : Callable [[ str ], None ] | None = None ,
125+ fake_safelist_data : str = "{}"
126+ ) -> Result :
116127 """
117128 Call the code_annotations script with the given params and a generic config file.
118129
@@ -122,9 +133,6 @@ def call_script_isolated(
122133 cleared. Use this if you need access to non-report files in the temp filesystem.
123134 test_filesystem_report_cb: Callback function, called after the command is run, before the temp filesystem
124135 is cleared. Callback is called with the raw text contents of the report file.
125- fake_safelist_data: Raw text to write to the safelist file before the command is called.
126- safelist_path: File path to write the safelist to. Used when writing a fake safelist, but not automatically
127- passed to the command.
128136
129137 Returns:
130138 click.testing.Result: Result from the `CliRunner.invoke()` call.
@@ -151,7 +159,9 @@ def call_script_isolated(
151159
152160 if test_filesystem_report_cb :
153161 try :
154- report_file = re .search (r'Generating report to (.*)' , result .output ).groups ()[0 ]
162+ report_match = re .search (r'Generating report to (.*)' , result .output )
163+ assert report_match is not None
164+ report_file = report_match .groups ()[0 ]
155165 with open (report_file ) as f :
156166 report_contents = f .read ()
157167
@@ -163,7 +173,7 @@ def call_script_isolated(
163173 return result
164174
165175
166- def get_report_filename_from_output (output ) :
176+ def get_report_filename_from_output (output : str ) -> str | None :
167177 """
168178 Find the report filename in a find_static or find_django output and return it.
169179
@@ -172,9 +182,10 @@ def get_report_filename_from_output(output):
172182
173183 Returns:
174184 Filename of the found report, or None of no name is found
175-
176185 """
186+ match = re .search (r'Generating report to (.*)' , output )
187+ assert match is not None
177188 try :
178- return re . search ( r'Generating report to (.*)' , output ) .groups ()[0 ]
189+ return match .groups ()[0 ]
179190 except IndexError :
180191 return None
0 commit comments