3333root_dir = os .path .abspath (os .path .join (current_dir , ".." ))
3434spec_file_path = os .path .join (root_dir , "spec" , "tests" , "spec" , "specification-test.json" )
3535
36- valid_purl_types_file = os .path .join (root_dir , "spec" , "purl-types-index.json" )
37-
38-
3936with open (spec_file_path , "r" , encoding = "utf-8" ) as f :
4037 test_cases = json .load (f )
4138
42- with open (valid_purl_types_file , "r" , encoding = "utf-8" ) as f :
43- valid_purl_types = json .load (f )
44-
4539tests = test_cases ["tests" ]
4640
4741parse_tests = [t for t in tests if t ["test_type" ] == "parse" ]
4842build_tests = [t for t in tests if t ["test_type" ] == "build" ]
4943
5044
45+ def load_spec_files (spec_dir ):
46+ """
47+ Load all JSON files from the given directory into a dictionary.
48+ Key = filename, Value = parsed JSON content
49+ """
50+ spec_data = {}
51+ for filename in os .listdir (spec_dir ):
52+ if filename .endswith ("-test.json" ):
53+ filepath = os .path .join (spec_dir , filename )
54+ with open (filepath , "r" , encoding = "utf-8" ) as f :
55+ try :
56+ data = json .load (f )
57+ spec_data [filename ] = data ["tests" ]
58+ except json .JSONDecodeError as e :
59+ print (f"Error parsing { filename } : { e } " )
60+ return spec_data
61+
62+
63+ SPEC_DIR = os .path .join (os .path .dirname (__file__ ), ".." , "spec" , "tests" , "types" )
64+ spec_dict = load_spec_files (SPEC_DIR )
65+
66+ flattened_cases = []
67+ for filename , cases in spec_dict .items ():
68+ for case in cases :
69+ flattened_cases .append ((filename , case ["description" ], case ))
70+
71+
5172@pytest .mark .parametrize (
5273 "description, input_str, expected_output, expected_failure" ,
5374 [
@@ -59,7 +80,6 @@ def test_parse(description, input_str, expected_output, expected_failure):
5980 if expected_failure :
6081 with pytest .raises (Exception ):
6182 PackageURL .from_string (input_str )
62- # assert None ==PackageURL.from_string(input_str)
6383 else :
6484 result = PackageURL .from_string (input_str )
6585 assert result .to_string () == expected_output
@@ -90,33 +110,6 @@ def test_build(description, input_dict, expected_output, expected_failure):
90110 assert purl .to_string () == expected_output
91111
92112
93- def load_spec_files (spec_dir ):
94- """
95- Load all JSON files from the given directory into a dictionary.
96- Key = filename, Value = parsed JSON content
97- """
98- spec_data = {}
99- for filename in os .listdir (spec_dir ):
100- if filename .endswith ("-test.json" ):
101- filepath = os .path .join (spec_dir , filename )
102- with open (filepath , "r" , encoding = "utf-8" ) as f :
103- try :
104- data = json .load (f )
105- spec_data [filename ] = data ["tests" ]
106- except json .JSONDecodeError as e :
107- print (f"Error parsing { filename } : { e } " )
108- return spec_data
109-
110-
111- SPEC_DIR = os .path .join (os .path .dirname (__file__ ), ".." , "spec" , "tests" , "types" )
112- spec_dict = load_spec_files (SPEC_DIR )
113-
114- flattened_cases = []
115- for filename , cases in spec_dict .items ():
116- for case in cases :
117- flattened_cases .append ((filename , case ["description" ], case ))
118-
119-
120113@pytest .mark .parametrize ("filename,description,test_case" , flattened_cases )
121114def test_package_type_case (filename , description , test_case ):
122115 test_type = test_case ["test_type" ]
0 commit comments