Skip to content

xmltester

Class to test xml snippets.

XMLTester

Bases: unittest.TestCase

Test xml equality.

Source code in /home/anders/projects/CorpusTools/corpustools/test/xmltester.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class XMLTester(unittest.TestCase):
    """Test xml equality."""

    @staticmethod
    def assertXmlEqual(got, want):
        """Check if two stringified xml snippets are equal.

        Args:
            got (etree.Element): the xml part given by the tester
            want (etree.Element): the wanted xml

        Raises:
            AssertionError: If they are not equal
        """
        got = etree.tostring(got, encoding="unicode")
        want = etree.tostring(want, encoding="unicode")

        checker = doctestcompare.LXMLOutputChecker()
        if not checker.check_output(want, got, 0):
            message = checker.output_difference(doctest.Example("", want), got, 0)
            raise AssertionError(message)

assertXmlEqual(got, want) staticmethod

Check if two stringified xml snippets are equal.

Parameters:

Name Type Description Default
got etree.Element

the xml part given by the tester

required
want etree.Element

the wanted xml

required

Raises:

Type Description
AssertionError

If they are not equal

Source code in /home/anders/projects/CorpusTools/corpustools/test/xmltester.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
@staticmethod
def assertXmlEqual(got, want):
    """Check if two stringified xml snippets are equal.

    Args:
        got (etree.Element): the xml part given by the tester
        want (etree.Element): the wanted xml

    Raises:
        AssertionError: If they are not equal
    """
    got = etree.tostring(got, encoding="unicode")
    want = etree.tostring(want, encoding="unicode")

    checker = doctestcompare.LXMLOutputChecker()
    if not checker.check_output(want, got, 0):
        message = checker.output_difference(doctest.Example("", want), got, 0)
        raise AssertionError(message)