def test_try_parse_with_bad_file(self): """Should raise XMLSyntaxError: file exists but content is not valid.""" xml_path = os.path.join(self.cwd, "test_try_parse.xml") self.tidy_file = xml_path with open(xml_path, "w") as xml_file: xml_file.write("not valid xml :(") with self.assertRaises(ParseError): _try_parse(xml_path)
def test_try_parse_with_path(self): """Should return root node from XML file path.""" xml_path = os.path.join(self.cwd, "test_try_parse.xml") self.tidy_file = xml_path with open(xml_path, "w") as xml_file: xml_file.write(self.xml) root = _try_parse(xml_path) self.assertEqual("a", root.tag)
def test_try_parse_with_bad_string(self): """Should raise IOError: string parse failed and its not a path.""" with self.assertRaises(IOError): _try_parse("not valid xml :(")
def test_try_parse_with_bad_path(self): """Should raise IOError: file doesn't exist.""" xml_path = os.path.join(self.cwd, "not_a_real_file.xyz") with self.assertRaises(IOError): _try_parse(xml_path)
def test_try_parse_with_string(self): """Should return root node from XML string.""" root = _try_parse(self.xml) self.assertEqual("a", root.tag)