@@ -61,6 +61,18 @@ def line_number_of(path: Path, case: dict[str, Any]) -> int:
6161 1 ,
6262 )
6363
64+ def extract_kind_and_spec (key : str ) -> (str , str ):
65+ """
66+ Extracts specification number and kind from the defined key
67+ """
68+ can_have_spec = ["rfc" , "iso" ]
69+ if not any (key .startswith (el ) for el in can_have_spec ):
70+ return key , ""
71+ number = re .search (r"\d+" , key )
72+ spec = "" if number is None else number .group (0 )
73+ kind = key .removesuffix (spec )
74+ return kind , spec
75+
6476
6577def main ():
6678 # Clear annotations which may have been emitted by a previous run.
@@ -82,20 +94,33 @@ def main():
8294 line = error .lineno ,
8395 col = error .pos + 1 ,
8496 title = str (error ),
97+ message = f"cannot load { path } "
8598 )
8699 sys .stdout .write (error )
100+ continue
87101
88102 for test_case in contents :
89103 specifications = test_case .get ("specification" )
90104 if specifications is not None :
91105 for each in specifications :
92106 quote = each .pop ("quote" , "" )
93- (kind , section ), = each .items ()
107+ (key , section ), = each .items ()
94108
95- number = re .search (r"\d+" , kind )
96- spec = "" if number is None else number .group (0 )
109+ (kind , spec ) = extract_kind_and_spec (key )
110+
111+ url_template = version_urls [kind ]
112+ if url_template is None :
113+ error = annotation (
114+ level = "error" ,
115+ path = path ,
116+ line = line_number_of (path , test_case ),
117+ title = f"unsupported template '{ kind } '" ,
118+ message = f"cannot find a URL template for '{ kind } '"
119+ )
120+ sys .stdout .write (error )
121+ continue
97122
98- url = version_urls [ kind ] .expand (
123+ url = url_template .expand (
99124 spec = spec ,
100125 section = section ,
101126 )
0 commit comments