@@ -68,12 +68,21 @@ def _write_test_xml(
6868
6969
7070@pytest .fixture
71- def tmp_xml_dirs (tmp_path : Path ) -> Callable [..., tuple [Path , Path , Path ]]:
72- def _tmp_xml_dirs (test_folder : str = "bazel-testlogs" ) -> tuple [Path , Path , Path ]:
71+ def tmp_xml_dirs (
72+ tmp_path : Path ,
73+ ) -> Callable [..., tuple [Path , Path , Path , Path , Path ]]:
74+ def _tmp_xml_dirs (
75+ test_folder : str = "bazel-testlogs" ,
76+ ) -> tuple [Path , Path , Path , Path , Path ]:
7377 root = tmp_path / test_folder
74- dir1 , dir2 = root / "with_props" , root / "no_props"
78+ dir1 , dir2 , dir3 , dir4 = (
79+ root / "with_props" ,
80+ root / "no_props" ,
81+ root / "with_extra_props" ,
82+ root / "missing_props" ,
83+ )
7584
76- for d in (dir1 , dir2 ):
85+ for d in (dir1 , dir2 , dir3 , dir4 ):
7786 d .mkdir (parents = True , exist_ok = True )
7887
7988 # File with properties
@@ -95,7 +104,42 @@ def _tmp_xml_dirs(test_folder: str = "bazel-testlogs") -> tuple[Path, Path, Path
95104 # File without properties
96105 _write_test_xml (dir2 / "test.xml" , name = "tc_no_props" , file = "path2" , line = 20 )
97106
98- return root , dir1 , dir2
107+ # File with some properties that we don't care about
108+ _write_test_xml (
109+ dir3 / "test.xml" ,
110+ name = "tc_with_extra_props" ,
111+ result = "failed" ,
112+ file = "path1" ,
113+ line = 10 ,
114+ props = {
115+ # Properties we do not parse should not throw an error
116+ "PartiallyVerifies" : "REQ1" ,
117+ "FullyVerifies" : "" ,
118+ "TestType" : "type" ,
119+ "DerivationTechnique" : "tech" ,
120+ "Description" : "desc" ,
121+ "ASIL" : "B" ,
122+ "important" : "yes" ,
123+ },
124+ )
125+
126+ # File with some properties missing
127+ _write_test_xml (
128+ dir4 / "test.xml" ,
129+ name = "tc_with_missing_props" ,
130+ result = "failed" ,
131+ file = "path1" ,
132+ line = 10 ,
133+ props = {
134+ # derivation_technique and test_type are missing
135+ # This should not make a 'valid' testlink
136+ "PartiallyVerifies" : "REQ1" ,
137+ "FullyVerifies" : "" ,
138+ "Description" : "desc" ,
139+ },
140+ )
141+
142+ return root , dir1 , dir2 , dir3 , dir4
99143
100144 return _tmp_xml_dirs
101145
@@ -105,48 +149,62 @@ def _tmp_xml_dirs(test_folder: str = "bazel-testlogs") -> tuple[Path, Path, Path
105149 test_type = "requirements-based" ,
106150 derivation_technique = "requirements-analysis" ,
107151)
108- def test_find_xml_files (tmp_xml_dirs : Callable [..., tuple [Path , Path , Path ]]):
152+ def test_find_xml_files (
153+ tmp_xml_dirs : Callable [..., tuple [Path , Path , Path , Path , Path ]],
154+ ):
109155 """Ensure xml files are found as expected if bazel-testlogs is used"""
110156 root : Path
111157 dir1 : Path
112158 dir2 : Path
113- root , dir1 , dir2 = tmp_xml_dirs ()
159+ root , dir1 , dir2 , dir3 , dir4 = tmp_xml_dirs ()
114160 found = xml_parser .find_xml_files (root )
115- expected : set [Path ] = {dir1 / "test.xml" , dir2 / "test.xml" }
161+ expected : set [Path ] = {
162+ dir1 / "test.xml" ,
163+ dir2 / "test.xml" ,
164+ dir3 / "test.xml" ,
165+ dir4 / "test.xml" ,
166+ }
116167 assert set (found ) == expected
117168
118169
119- def test_find_xml_folder (tmp_xml_dirs : Callable [..., tuple [Path , Path , Path ]]):
170+ def test_find_xml_folder (
171+ tmp_xml_dirs : Callable [..., tuple [Path , Path , Path , Path , Path ]],
172+ ):
120173 """Ensure xml files are found as expected if bazel-testlogs is used"""
121174 root : Path
122- root , _ , _ = tmp_xml_dirs ()
175+ root , _ , _ , _ , _ = tmp_xml_dirs ()
123176 found = xml_parser .find_test_folder (base_path = root .parent )
124177 assert found is not None
125178 assert found == root
126179
127180
128181def test_find_xml_folder_test_reports (
129- tmp_xml_dirs : Callable [..., tuple [Path , Path , Path ]],
182+ tmp_xml_dirs : Callable [..., tuple [Path , Path , Path , Path , Path ]],
130183):
131184 # root is the 'tests-report' folder inside tmp_path
132- root , _ , _ = tmp_xml_dirs (test_folder = "tests-report" )
185+ root , _ , _ , _ , _ = tmp_xml_dirs (test_folder = "tests-report" )
133186 # We pass the PARENT of 'tests-report' as the workspace root
134187 found = xml_parser .find_test_folder (base_path = root .parent )
135188 assert found is not None
136189 assert found == root
137190
138191
139192def test_find_xml_files_test_reports (
140- tmp_xml_dirs : Callable [..., tuple [Path , Path , Path ]],
193+ tmp_xml_dirs : Callable [..., tuple [Path , Path , Path , Path , Path ]],
141194):
142195 """Ensure xml files are found as expected if tests-report is used"""
143196 root : Path
144197 dir1 : Path
145198 dir2 : Path
146- root , dir1 , dir2 = tmp_xml_dirs (test_folder = "tests-report" )
199+ root , dir1 , dir2 , dir3 , dir4 = tmp_xml_dirs (test_folder = "tests-report" )
147200 found = xml_parser .find_xml_files (dir = root )
148201 assert found is not None
149- expected : set [Path ] = {root / dir1 / "test.xml" , root / dir2 / "test.xml" }
202+ expected : set [Path ] = {
203+ root / dir1 / "test.xml" ,
204+ root / dir2 / "test.xml" ,
205+ root / dir3 / "test.xml" ,
206+ root / dir4 / "test.xml" ,
207+ }
150208 assert set (found ) == expected
151209
152210
@@ -204,23 +262,42 @@ def test_parse_properties():
204262 test_type = "requirements-based" ,
205263 derivation_technique = "requirements-analysis" ,
206264)
207- def test_read_test_xml_file (tmp_xml_dirs : Callable [..., tuple [Path , Path , Path ]]):
265+ def test_read_test_xml_file (
266+ tmp_xml_dirs : Callable [..., tuple [Path , Path , Path , Path , Path ]],
267+ ):
208268 """Ensure a whole pre-defined xml file is parsed correctly"""
209269 _ : Path
210270 dir1 : Path
211271 dir2 : Path
212- _ , dir1 , dir2 = tmp_xml_dirs ()
213-
214- needs1 , no_props1 = xml_parser . read_test_xml_file ( dir1 / "test.xml" )
272+ _ , dir1 , dir2 , dir3 , dir4 = tmp_xml_dirs ()
273+ needs1 , no_props1 , missing_props1 = xml_parser . read_test_xml_file ( dir1 / "test.xml" )
274+ # Should parse the properties and create a 'valid' testlink
215275 assert isinstance (needs1 , list ) and len (needs1 ) == 1
216276 tcneed = needs1 [0 ]
217277 assert isinstance (tcneed , DataOfTestCase )
218278 assert tcneed .result == "failed"
219279 assert no_props1 == []
280+ assert missing_props1 == []
220281
221- needs2 , no_props2 = xml_parser .read_test_xml_file (dir2 / "test.xml" )
282+ # No properties at all => Should not be a 'valid' testlink
283+ needs2 , no_props2 , missing_props2 = xml_parser .read_test_xml_file (dir2 / "test.xml" )
222284 assert needs2 == []
223285 assert no_props2 == ["tc_no_props" ]
286+ assert missing_props2 == []
287+
288+ # Extra Properties => Should not cause an error
289+ needs3 , no_props3 , missing_props3 = xml_parser .read_test_xml_file (dir3 / "test.xml" )
290+ assert isinstance (needs1 , list ) and len (needs1 ) == 1
291+ tcneed3 = needs3 [0 ]
292+ assert isinstance (tcneed3 , DataOfTestCase )
293+ assert no_props3 == []
294+ assert missing_props3 == []
295+
296+ # Missing some properties => Should not be a 'valid' testlink
297+ needs4 , no_props4 , missing_props4 = xml_parser .read_test_xml_file (dir4 / "test.xml" )
298+ assert needs4 == []
299+ assert no_props4 == []
300+ assert missing_props4 == ["tc_with_missing_props" ]
224301
225302
226303@add_test_properties (
0 commit comments