Exemple #1
0
 def test_indexedSpan(self):
     """
     Test processing of a span tag with an index class results in a latex
     \\index directive the correct value.
     """
     doc = dom.parseString('<span class="index" value="name" />').documentElement
     out = StringIO()
     spitter = LatexSpitter(out.write)
     spitter.visitNode(doc)
     self.assertEqual(out.getvalue(), u'\\index{name}\n')
Exemple #2
0
 def test_indexedSpan(self):
     """
     Test processing of a span tag with an index class results in a latex
     \\index directive the correct value.
     """
     doc = dom.parseString('<span class="index" value="name" />').documentElement
     out = StringIO()
     spitter = LatexSpitter(out.write)
     spitter.visitNode(doc)
     self.assertEqual(out.getvalue(), u'\\index{name}\n')
Exemple #3
0
 def setUp(self):
     self.filename = self.mktemp()
     self.output = []
     self.spitter = LatexSpitter(self.output.append, filename=self.filename)
Exemple #4
0
class LatexSpitterTests(TestCase):
    """
    Tests for L{LatexSpitter}.
    """
    def setUp(self):
        self.filename = self.mktemp()
        self.output = []
        self.spitter = LatexSpitter(self.output.append, filename=self.filename)

    def test_head(self):
        """
        L{LatexSpitter.visitNode} writes out author information for each
        I{link} element with a I{rel} attribute set to I{author}.
        """
        head = Element('head')
        first = Element('link')
        first.setAttribute('rel', 'author')
        first.setAttribute('title', 'alice')
        second = Element('link')
        second.setAttribute('rel', 'author')
        second.setAttribute('href', 'http://example.com/bob')
        third = Element('link')
        third.setAttribute('rel', 'author')
        third.setAttribute('href', 'mailto:[email protected]')
        head.appendChild(first)
        head.appendChild(second)
        head.appendChild(third)

        self.spitter.visitNode(head)

        self.assertEqual(
            ''.join(self.output),
            '\\author{alice \\and $<$http://example.com/bob$>$ \\and $<[email protected]$>$}'
        )

    def test_skipComments(self):
        """
        L{LatexSpitter.visitNode} writes nothing to its output stream for
        comments.
        """
        self.spitter.visitNode(Comment('foo'))
        self.assertNotIn('foo', ''.join(self.output))

    def test_anchorListing(self):
        """
        L{LatexSpitter.visitNode} emits a verbatim block when it encounters a
        code listing (represented by an I{a} element with a I{listing} class).
        """
        path = FilePath(self.mktemp())
        path.setContent('foo\nbar\n')
        listing = Element('a')
        listing.setAttribute('class', 'listing')
        listing.setAttribute('href', path.path)
        self.spitter.visitNode(listing)
        self.assertEqual(
            ''.join(self.output), "\\begin{verbatim}\n"
            "foo\n"
            "bar\n"
            "\\end{verbatim}\\parbox[b]{\\linewidth}{\\begin{center} --- "
            "\\begin{em}temp\\end{em}\\end{center}}")

    def test_anchorListingSkipLines(self):
        """
        When passed an I{a} element with a I{listing} class and an I{skipLines}
        attribute, L{LatexSpitter.visitNode} emits a verbatim block which skips
        the indicated number of lines from the beginning of the source listing.
        """
        path = FilePath(self.mktemp())
        path.setContent('foo\nbar\n')
        listing = Element('a')
        listing.setAttribute('class', 'listing')
        listing.setAttribute('skipLines', '1')
        listing.setAttribute('href', path.path)
        self.spitter.visitNode(listing)
        self.assertEqual(
            ''.join(self.output), "\\begin{verbatim}\n"
            "bar\n"
            "\\end{verbatim}\\parbox[b]{\\linewidth}{\\begin{center} --- "
            "\\begin{em}temp\\end{em}\\end{center}}")

    def test_anchorRef(self):
        """
        L{LatexSpitter.visitNode} emits a footnote when it encounters an I{a}
        element with an I{href} attribute with a network scheme.
        """
        listing = Element('a')
        listing.setAttribute('href', 'http://example.com/foo')
        self.spitter.visitNode(listing)
        self.assertEqual(''.join(self.output),
                         "\\footnote{http://example.com/foo}")

    def test_anchorName(self):
        """
        When passed an I{a} element with a I{name} attribute,
        L{LatexSpitter.visitNode} emits a label.
        """
        listing = Element('a')
        listing.setAttribute('name', 'foo')
        self.spitter.visitNode(listing)
        self.assertEqual(
            ''.join(self.output), "\\label{%sHASHfoo}" %
            (os.path.abspath(self.filename).replace('\\', '/'), ))
Exemple #5
0
 def setUp(self):
     self.filename = self.mktemp()
     self.output = []
     self.spitter = LatexSpitter(self.output.append, filename=self.filename)
Exemple #6
0
class LatexSpitterTests(TestCase):
    """
    Tests for L{LatexSpitter}.
    """
    def setUp(self):
        self.filename = self.mktemp()
        self.output = []
        self.spitter = LatexSpitter(self.output.append, filename=self.filename)


    def test_head(self):
        """
        L{LatexSpitter.visitNode} writes out author information for each
        I{link} element with a I{rel} attribute set to I{author}.
        """
        head = Element('head')
        first = Element('link')
        first.setAttribute('rel', 'author')
        first.setAttribute('title', 'alice')
        second = Element('link')
        second.setAttribute('rel', 'author')
        second.setAttribute('href', 'http://example.com/bob')
        third = Element('link')
        third.setAttribute('rel', 'author')
        third.setAttribute('href', 'mailto:[email protected]')
        head.appendChild(first)
        head.appendChild(second)
        head.appendChild(third)

        self.spitter.visitNode(head)

        self.assertEqual(
            ''.join(self.output),
            '\\author{alice \\and $<$http://example.com/bob$>$ \\and $<[email protected]$>$}')


    def test_skipComments(self):
        """
        L{LatexSpitter.visitNode} writes nothing to its output stream for
        comments.
        """
        self.spitter.visitNode(Comment('foo'))
        self.assertNotIn('foo', ''.join(self.output))


    def test_anchorListing(self):
        """
        L{LatexSpitter.visitNode} emits a verbatim block when it encounters a
        code listing (represented by an I{a} element with a I{listing} class).
        """
        path = FilePath(self.mktemp())
        path.setContent('foo\nbar\n')
        listing = Element('a')
        listing.setAttribute('class', 'listing')
        listing.setAttribute('href', path.path)
        self.spitter.visitNode(listing)
        self.assertEqual(
            ''.join(self.output),
            "\\begin{verbatim}\n"
            "foo\n"
            "bar\n"
            "\\end{verbatim}\\parbox[b]{\\linewidth}{\\begin{center} --- "
            "\\begin{em}temp\\end{em}\\end{center}}")


    def test_anchorListingSkipLines(self):
        """
        When passed an I{a} element with a I{listing} class and an I{skipLines}
        attribute, L{LatexSpitter.visitNode} emits a verbatim block which skips
        the indicated number of lines from the beginning of the source listing.
        """
        path = FilePath(self.mktemp())
        path.setContent('foo\nbar\n')
        listing = Element('a')
        listing.setAttribute('class', 'listing')
        listing.setAttribute('skipLines', '1')
        listing.setAttribute('href', path.path)
        self.spitter.visitNode(listing)
        self.assertEqual(
            ''.join(self.output),
            "\\begin{verbatim}\n"
            "bar\n"
            "\\end{verbatim}\\parbox[b]{\\linewidth}{\\begin{center} --- "
            "\\begin{em}temp\\end{em}\\end{center}}")


    def test_anchorRef(self):
        """
        L{LatexSpitter.visitNode} emits a footnote when it encounters an I{a}
        element with an I{href} attribute with a network scheme.
        """
        listing = Element('a')
        listing.setAttribute('href', 'http://example.com/foo')
        self.spitter.visitNode(listing)
        self.assertEqual(
            ''.join(self.output),
            "\\footnote{http://example.com/foo}")


    def test_anchorName(self):
        """
        When passed an I{a} element with a I{name} attribute,
        L{LatexSpitter.visitNode} emits a label.
        """
        listing = Element('a')
        listing.setAttribute('name', 'foo')
        self.spitter.visitNode(listing)
        self.assertEqual(
            ''.join(self.output),
            "\\label{%sHASHfoo}" % (
                os.path.abspath(self.filename).replace('\\', '/'),))