Skip to content

test_xslmaker

Test the XslMaker class.

TestXslMaker

Bases: XMLTester

Test the Xslmaker class.

Source code in /home/anders/projects/CorpusTools/corpustools/test/test_xslmaker.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class TestXslMaker(XMLTester):
    """Test the Xslmaker class."""

    def test_get_xsl(self):
        """Test the functionality of the XslMaker class."""
        xsl_maker = xslmaker.XslMaker(
            etree.parse(
                os.path.join(HERE, "converter_data/samediggi-article-48.html.xsl")
            )
        )
        got = xsl_maker.xsl

        # The import href is different for each user testing, so just
        # check that it looks OK:
        import_elt = got.find(
            "/xsl:import", namespaces={"xsl": "http://www.w3.org/1999/XSL/Transform"}
        )
        self.assertTrue(import_elt.attrib["href"].startswith("file:///"))
        self.assertTrue(import_elt.attrib["href"].endswith("common.xsl"))
        with open(import_elt.attrib["href"][7:].replace("%20", " ")) as xsl:
            self.assertGreater(len(xsl.read()), 0)
        # ... and set it to the hardcoded path in test.xsl:
        import_elt.attrib["href"] = (
            "file:///home/boerre/langtech/trunk/tools/CorpusTools/"
            "corpustools/xslt/common.xsl"
        )

        want = etree.parse(os.path.join(HERE, "converter_data/test.xsl"))
        self.assertXmlEqual(got, want)

test_get_xsl()

Test the functionality of the XslMaker class.

Source code in /home/anders/projects/CorpusTools/corpustools/test/test_xslmaker.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def test_get_xsl(self):
    """Test the functionality of the XslMaker class."""
    xsl_maker = xslmaker.XslMaker(
        etree.parse(
            os.path.join(HERE, "converter_data/samediggi-article-48.html.xsl")
        )
    )
    got = xsl_maker.xsl

    # The import href is different for each user testing, so just
    # check that it looks OK:
    import_elt = got.find(
        "/xsl:import", namespaces={"xsl": "http://www.w3.org/1999/XSL/Transform"}
    )
    self.assertTrue(import_elt.attrib["href"].startswith("file:///"))
    self.assertTrue(import_elt.attrib["href"].endswith("common.xsl"))
    with open(import_elt.attrib["href"][7:].replace("%20", " ")) as xsl:
        self.assertGreater(len(xsl.read()), 0)
    # ... and set it to the hardcoded path in test.xsl:
    import_elt.attrib["href"] = (
        "file:///home/boerre/langtech/trunk/tools/CorpusTools/"
        "corpustools/xslt/common.xsl"
    )

    want = etree.parse(os.path.join(HERE, "converter_data/test.xsl"))
    self.assertXmlEqual(got, want)