1+ """Generate verification.rst from test files with @verifies tags."""
2+
13import os
2- import re
34from pathlib import Path
5+ import re
46
57# Determine workspace root relative to this script
68# Script is in <workspace>/scripts/generate_verification.py
1113
1214
1315def parse_cpp_file (file_path ):
16+ """Parse C++ test file for @verifies tags."""
1417 with open (file_path , "r" , encoding = "utf-8" ) as f :
1518 content = f .read ()
1619
@@ -21,7 +24,6 @@ def parse_cpp_file(file_path):
2124 tests = []
2225
2326 for match in test_pattern .finditer (content ):
24- suite_name = match .group (1 )
2527 test_name = match .group (2 )
2628 start_index = match .end ()
2729
@@ -30,7 +32,7 @@ def parse_cpp_file(file_path):
3032 lines = search_window .split ("\n " )
3133
3234 # Auto-generate ID and Title
33- test_id = f "TEST_{ test_name } "
35+ test_id = "TEST_" + test_name
3436 test_title = test_name
3537
3638 verifies_reqs = []
@@ -51,7 +53,7 @@ def parse_cpp_file(file_path):
5153 comment_content = line [2 :].strip ()
5254
5355 # Parse tags
54- # Support " @verifies REQ_..." (list) or " Links to: REQ_..."
56+ # Support ' @verifies REQ_...' (list) or ' Links to: REQ_...'
5557 tag_match = re .match (
5658 r"(?:@verifies|Links to:|Verifies:)\s*(.*)" , comment_content
5759 )
@@ -81,6 +83,7 @@ def parse_cpp_file(file_path):
8183
8284
8385def parse_py_file (file_path ):
86+ """Parse Python test file for @verifies tags."""
8487 with open (file_path , "r" , encoding = "utf-8" ) as f :
8588 content = f .read ()
8689
@@ -99,7 +102,7 @@ def parse_py_file(file_path):
99102 lines = search_window .split ("\n " )
100103
101104 # Auto-generate ID and Title
102- test_id = f "TEST_{ test_name } "
105+ test_id = "TEST_" + test_name
103106 test_title = test_name
104107
105108 verifies_reqs = []
@@ -108,7 +111,7 @@ def parse_py_file(file_path):
108111 in_docstring = False
109112 docstring_lines = []
110113
111- for i , line in enumerate ( lines ) :
114+ for line in lines :
112115 stripped = line .strip ()
113116 if not stripped :
114117 continue
@@ -189,6 +192,7 @@ def parse_py_file(file_path):
189192
190193
191194def generate_rst (tests ):
195+ """Generate RST content from parsed tests."""
192196 lines = [
193197 "Verification" ,
194198 "============" ,
@@ -199,18 +203,19 @@ def generate_rst(tests):
199203 ]
200204
201205 for test in tests :
202- lines .append (f ".. test:: { test [' title' ] } " )
203- lines .append (f " :id: { test ['id' ] } " )
204- lines .append (f " :status: verified" )
206+ lines .append (".. test:: " + test [" title" ] )
207+ lines .append (" :id: " + test ["id" ] )
208+ lines .append (" :status: verified" )
205209 if test ["verifies" ]:
206- lines .append (f " :verifies: { ', ' .join (test [' verifies' ]) } " )
210+ lines .append (" :verifies: " + ", " .join (test [" verifies" ]) )
207211 lines .append ("" )
208212 if test ["description" ]:
209- lines .append (f " { test [' description' ] } " )
213+ lines .append (" " + test [" description" ] )
210214 lines .append ("" )
211215
212216 lines .append (
213- f" **Implementation:** ``{ test ['file' ]} `` (Test: ``{ test ['test_func' ]} ``)"
217+ " **Implementation:** ``" + test ["file" ] + "`` "
218+ "(Test: ``" + test ["test_func" ] + "``)"
214219 )
215220 lines .append ("" )
216221 lines .append ("" )
@@ -225,9 +230,10 @@ def generate_rst(tests):
225230
226231
227232def main ():
233+ """Scan tests and generate verification.rst."""
228234 all_tests = []
229235 if not SRC_DIR .exists ():
230- print (f "Source directory { SRC_DIR } does not exist." )
236+ print ("Source directory " + str ( SRC_DIR ) + " does not exist." )
231237 return
232238
233239 for root , dirs , files in os .walk (SRC_DIR ):
@@ -246,7 +252,7 @@ def main():
246252 with open (OUTPUT_FILE , "w" , encoding = "utf-8" ) as f :
247253 f .write (rst_content )
248254
249- print (f "Generated { OUTPUT_FILE } with { len (all_tests )} tests." )
255+ print ("Generated " + str ( OUTPUT_FILE ) + " with " + str ( len (all_tests )) + " tests." )
250256
251257
252258if __name__ == "__main__" :
0 commit comments