def test_assertXmlEquivalentOutputs_namespaces(self): """Asserts assertXmlEquivalentOutputs raises when comparison failed. Assertion with different namespaces: the namespace URI is the same, but the prefix is different. In this case, the two XML are equivalents. """ test_case = XmlTestCase(methodName='assertXmlEquivalentOutputs') # Same XML, but with different namespace prefixes data = b"""<?xml version="1.0" encoding="UTF-8" ?> <root xmlns:foo="mynamespace"> <foo:tag>foo</foo:tag> </root>""" expected = b"""<?xml version="1.0" encoding="UTF-8" ?> <root xmlns:bar="mynamespace"> <bar:tag>foo</bar:tag> </root>""" test_case.assertXmlEquivalentOutputs(data, expected) wrong_namespace = b"""<?xml version="1.0" encoding="UTF-8" ?> <root xmlns:foo="not_the_same_namespace"> <foo:tag>foo</foo:tag> </root> """ with self.assertRaises(test_case.failureException): test_case.assertXmlEquivalentOutputs(wrong_namespace, expected)
def test_assertXmlEquivalentOutputs_namespaces(self): """Asserts assertXmlEquivalentOutputs raises when comparison failed. Assertion with different namespaces: the namespace URI is the same, but the prefix is different. In this case, the two XML are equivalents. """ test_case = XmlTestCase(methodName='assertXmlEquivalentOutputs') # Same XML, but with different namespace prefixes data = b"""<?xml version="1.0" encoding="UTF-8" ?> <root xmlns:foo="mynamespace"> <foo:tag>foo</foo:tag> </root>""" expected = b"""<?xml version="1.0" encoding="UTF-8" ?> <root xmlns:bar="mynamespace"> <bar:tag>foo</bar:tag> </root>""" test_case.assertXmlEquivalentOutputs(data, expected) wrong_namespace = b"""<?xml version="1.0" encoding="UTF-8" ?> <root xmlns:foo="not_the_same_namespace"> <foo:tag>foo</foo:tag> </root> """ with self.assertRaises(test_case.failureException): test_case.assertXmlEquivalentOutputs(wrong_namespace, expected)
def test_assertXmlEquivalentOutputs(self): """Asserts assertXmlEquivalentOutputs raises when comparison failed. Basic assertion: same document, with different order of attributes, text with useless spaces, etc. """ test_case = XmlTestCase(methodName='assertXmlEquivalentOutputs') # Same XML (with different spacings placements and attrs order) data = b"""<?xml version="1.0" encoding="UTF-8" ?> <root> <tag foo="bar" bar="foo">foo</tag> </root>""" expected = b"""<?xml version="1.0" encoding="UTF-8" ?> <root><tag bar="foo" foo="bar"> foo </tag></root>""" test_case.assertXmlEquivalentOutputs(data, expected) # Not the right element given wrong_element = b"""<?xml version="1.0" encoding="UTF-8" ?> <root> <notTag foo="bar" bar="foo">foo</notTag> </root>""" with self.assertRaises(test_case.failureException): test_case.assertXmlEquivalentOutputs(wrong_element, expected) # Too many tag elements data = b"""<?xml version="1.0" encoding="UTF-8" ?> <root> <tag foo="bar" bar="foo">foo</tag> <tag foo="bar" bar="foo">foo</tag> </root>""" with self.assertRaises(test_case.failureException): test_case.assertXmlEquivalentOutputs(wrong_element, expected)
def test_assertXmlEquivalentOutputs(self): """Asserts assertXmlEquivalentOutputs raises when comparison failed. Basic assertion: same document, with different order of attributes, text with useless spaces, etc. """ test_case = XmlTestCase(methodName='assertXmlEquivalentOutputs') # Same XML (with different spacings placements and attrs order) data = b"""<?xml version="1.0" encoding="UTF-8" ?> <root> <tag foo="bar" bar="foo">foo</tag> </root>""" expected = b"""<?xml version="1.0" encoding="UTF-8" ?> <root><tag bar="foo" foo="bar"> foo </tag></root>""" test_case.assertXmlEquivalentOutputs(data, expected) # Not the right element given wrong_element = b"""<?xml version="1.0" encoding="UTF-8" ?> <root> <notTag foo="bar" bar="foo">foo</notTag> </root>""" with self.assertRaises(test_case.failureException): test_case.assertXmlEquivalentOutputs(wrong_element, expected) # Too many tag elements data = b"""<?xml version="1.0" encoding="UTF-8" ?> <root> <tag foo="bar" bar="foo">foo</tag> <tag foo="bar" bar="foo">foo</tag> </root>""" with self.assertRaises(test_case.failureException): test_case.assertXmlEquivalentOutputs(wrong_element, expected)