File: test_texmessageparser.py

package info (click to toggle)
pyx3 0.17-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,328 kB
  • sloc: python: 27,656; makefile: 225; ansic: 130; sh: 17
file content (91 lines) | stat: -rw-r--r-- 3,483 bytes parent folder | download
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import sys
if sys.path[0] != "../..":
    sys.path.insert(0, "../..")

import unittest, warnings, os, logging

from testfixtures import log_capture

from pyx import text, unit

# text.set(texdebug="bla.tex", usefiles=["bla.log"])

class MessageParserTestCase(unittest.TestCase):

    @log_capture(level=logging.WARNING)
    def testBadTeX(self, l):
        text.text(0, 0, r"\some \badly \broken \TeX", texmessages=[text.texmessage.warn])
        l.check(("pyx", "WARNING", r"""ignoring TeX warnings:
  *
  *! Undefined control sequence.
  <argument> \some 
                   \badly \broken \TeX 
  <*> }{1}
          %
  ! Undefined control sequence.
  <argument> \some \badly 
                          \broken \TeX 
  <*> }{1}
          %
  ! Undefined control sequence.
  <argument> \some \badly \broken 
                                  \TeX 
  <*> }{1}
          %
  
  
  *"""))

    @log_capture(level=logging.WARNING)
    def testFontWarning(self, l):
        text.text(0, 0, r"\fontseries{invalid}\selectfont{}hello, world", texmessages=[text.texmessage.font_warning])
        text.defaulttextengine.instance.do_finish()
        l.check(("pyx", "WARNING", r"""ignoring font substitutions of NFSS:
LaTeX Font Warning: Font shape `OT1/cmr/invalid/n' undefined
(Font)              using `OT1/cmr/m/n' instead on input line 0."""),
                ("pyx", "WARNING", r"""ignoring font substitutions of NFSS:
LaTeX Font Warning: Some font shapes were not available, defaults substituted."""))

    @log_capture(level=logging.WARNING)
    def testOverfullHboxWarning(self, l):
        text.text(0, 0, r"hello, world", textattrs=[text.parbox(30*unit.u_pt)])
        l.check(("pyx", "WARNING", r"""ignoring overfull/underfull box:
Overfull \hbox (8.22089pt too wide) detected at line 0
[]\OT1/cmr/m/n/10 hello,"""))

    @log_capture(level=logging.WARNING)
    def testUnderfullHboxWarning(self, l):
        text.text(0, 0, r"\hbadness=0hello, world, hello", textattrs=[text.parbox(2.5)])
        l.check(("pyx", "WARNING", r"""ignoring overfull/underfull box:
Underfull \hbox (badness 171) detected at line 0
[]\OT1/cmr/m/n/10 hello, world,"""))

    @log_capture(level=logging.WARNING)
    def testOverfullVboxWarning(self, l):
        text.text(0, 0, r"\parindent=0pt\vbox to 1cm {hello, world, hello, world, hello, world}", textattrs=[text.parbox(1.9)])
        l.check(("pyx", "WARNING", r"""ignoring overfull/underfull box:
Overfull \vbox (2.4917pt too high) detected at line 0"""))

    @log_capture(level=logging.WARNING)
    def testUnderfullVboxWarning(self, l):
        text.text(0, 0, r"\parindent=0pt\vbox to 1cm {hello, world, hello, world}", textattrs=[text.parbox(1.9)])
        l.check(("pyx", "WARNING", r"""ignoring overfull/underfull box:
Underfull \vbox (badness 10000) detected at line 0"""))

    def testLoadLongFileNames(self):
        testfilename = "x"*100
        with open(testfilename + ".tex", "w") as f:
            f.write(r"\message{ignore this}")
        text.text(0, 0, "\\input %s\n" % testfilename, texmessages=[text.texmessage.load])
        os.remove(testfilename + ".tex")
        with open(testfilename + ".eps", "w") as f:
            f.write("%%BoundingBox: 0 0 10 10")
        text.text(0, 0, r"\includegraphics{%s}" % testfilename)
        os.remove(testfilename + ".eps")

    def setUp(self):
        text.set(engine=text.LatexEngine)
        text.preamble(r"\usepackage{graphicx}")

if __name__ == "__main__":
    unittest.main()