def test_same_test_appears_twice(self): """If the same test appears twice, its information should be appended. This is not the typical, expected layout of the file, but it should be handled correctly in case the file is written this way. """ contents = """<?xml version= "1.0"?> <expectedFails version="1.1"> <test name="my.test.1"> <phase name="RUN"> <status>FAIL</status> <issue>#404</issue> </phase> </test> <test name="my.test.1"> <phase name="COMPARE_base_rest"> <status>PEND</status> <issue>#404</issue> <comment>Because of the RUN failure, this phase is listed as PEND</comment> </phase> </test> </expectedFails> """ with open(self._xml_filepath, 'w') as xml_file: xml_file.write(contents) expected_fails_file = ExpectedFailsFile(self._xml_filepath) xfails = expected_fails_file.get_expected_fails() expected_test1 = ExpectedFails() expected_test1.add_failure('RUN', 'FAIL') expected_test1.add_failure('COMPARE_base_rest', 'PEND') expected = {'my.test.1': expected_test1} self.assertEqual(xfails, expected)
def test_basic(self): """Basic test of the parsing of an expected fails file""" contents = """<?xml version= "1.0"?> <expectedFails version="1.1"> <test name="my.test.1"> <phase name="RUN"> <status>FAIL</status> <issue>#404</issue> </phase> <phase name="COMPARE_base_rest"> <status>PEND</status> <issue>#404</issue> <comment>Because of the RUN failure, this phase is listed as PEND</comment> </phase> </test> <test name="my.test.2"> <phase name="GENERATE"> <status>FAIL</status> <issue>ESMCI/cime#2917</issue> </phase> <phase name="BASELINE"> <status>FAIL</status> <issue>ESMCI/cime#2917</issue> </phase> </test> </expectedFails> """ with open(self._xml_filepath, 'w') as xml_file: xml_file.write(contents) expected_fails_file = ExpectedFailsFile(self._xml_filepath) xfails = expected_fails_file.get_expected_fails() expected_test1 = ExpectedFails() expected_test1.add_failure('RUN', 'FAIL') expected_test1.add_failure('COMPARE_base_rest', 'PEND') expected_test2 = ExpectedFails() expected_test2.add_failure('GENERATE', 'FAIL') expected_test2.add_failure('BASELINE', 'FAIL') expected = {'my.test.1': expected_test1, 'my.test.2': expected_test2} self.assertEqual(xfails, expected)
def test_same_test_appears_twice(self): """If the same test appears twice, its information should be appended. This is not the typical, expected layout of the file, but it should be handled correctly in case the file is written this way. """ contents = """<?xml version= "1.0"?> <expectedFails version="1.1"> <test name="my.test.1"> <phase name="RUN"> <status>FAIL</status> <issue>#404</issue> </phase> </test> <test name="my.test.1"> <phase name="COMPARE_base_rest"> <status>PEND</status> <issue>#404</issue> <comment>Because of the RUN failure, this phase is listed as PEND</comment> </phase> </test> </expectedFails> """ with open(self._xml_filepath, "w") as xml_file: xml_file.write(contents) expected_fails_file = ExpectedFailsFile(self._xml_filepath) xfails = expected_fails_file.get_expected_fails() expected_test1 = ExpectedFails() expected_test1.add_failure("RUN", "FAIL") expected_test1.add_failure("COMPARE_base_rest", "PEND") expected = {"my.test.1": expected_test1} self.assertEqual(xfails, expected)
def get_expected_fails(self): """Returns a dictionary of ExpectedFails objects, where the keys are test names""" xfails = {} test_nodes = self.get_children("test") for tnode in test_nodes: test_name = self.attrib(tnode)["name"] phase_nodes = self.get_children("phase", root=tnode) for pnode in phase_nodes: phase_name = self.attrib(pnode)["name"] status_node = self.get_child("status", root=pnode) status = self.resolved_text(status_node) # issue and comment elements are not currently parsed if test_name not in xfails: xfails[test_name] = ExpectedFails() xfails[test_name].add_failure(phase_name, status) return xfails