File: test_writelatex.py

package info (click to toggle)
pyth 0.5.6-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 312 kB
  • sloc: python: 1,609; makefile: 7
file content (55 lines) | stat: -rw-r--r-- 1,554 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
unit tests of the latex writer
"""

import unittest
import subprocess
import tempfile
import os
import sys
import BeautifulSoup

from pyth.plugins.latex.writer import LatexWriter
from pyth.plugins.python.reader import *


class TestWriteLatex(unittest.TestCase):

    def test_basic(self):
        """
        Try to create an empty latex document
        """
        doc = PythonReader.read([])
        latex = LatexWriter.write(doc).getvalue()

    def test_paragraph(self):
        """
        Try a single paragraph document
        """
        doc = PythonReader.read(P[u"the text"])
        latex = LatexWriter.write(doc).getvalue()
        assert "the text" in latex

    def test_bold(self):
        doc = PythonReader.read([P[T(BOLD)[u"bold text"]]])
        latex = LatexWriter.write(doc).getvalue()
        assert r"\textbf{bold text}" in latex, latex

    def test_italic(self):
        doc = PythonReader.read([P[T(ITALIC)[u"italic text"]]])
        latex = LatexWriter.write(doc).getvalue()
        assert r"\emph{italic text}" in latex, latex

    def test_metadata(self):
        """
        assert that the document metadata are added into the latex file
        """
        doc = PythonReader.read([])
        doc["author"] = "The Author"
        doc["subject"] = "The Subject"
        doc["title"] = "The Title"

        latex = LatexWriter.write(doc).getvalue()
        assert "pdfauthor={The Author}" in latex, latex
        assert "pdfsubject={The Subject}" in latex, latex
        assert "pdftitle={The Title}" in latex, latex