add UnicodeEngine (MultiEngineText and axis texters returning MultiEngineText), texte...
[PyX.git] / test / unit / test_texmessageparser.py
blob02da2c6178e90732798dfd4f4c3fda41eb9956fd
1 import sys
2 if sys.path[0] != "../..":
3 sys.path.insert(0, "../..")
5 import unittest, warnings, os, logging
7 from testfixtures import log_capture
9 from pyx import text, unit
11 # text.set(texdebug="bla.tex", usefiles=["bla.log"])
13 class MessageParserTestCase(unittest.TestCase):
15 @log_capture(level=logging.WARNING)
16 def testBadTeX(self, l):
17 text.text(0, 0, r"\some \badly \broken \TeX", texmessages=[text.texmessage.warn])
18 l.check(("pyx", "WARNING", r"""ignoring TeX warnings:
20 *! Undefined control sequence.
21 <argument> \some
22 \badly \broken \TeX
23 <*> }{1}
25 ! Undefined control sequence.
26 <argument> \some \badly
27 \broken \TeX
28 <*> }{1}
30 ! Undefined control sequence.
31 <argument> \some \badly \broken
32 \TeX
33 <*> }{1}
37 *"""))
39 @log_capture(level=logging.WARNING)
40 def testFontWarning(self, l):
41 text.text(0, 0, r"\fontseries{invalid}\selectfont{}hello, world", texmessages=[text.texmessage.font_warning])
42 text.default_runner.instance.do_finish()
43 l.check(("pyx", "WARNING", r"""ignoring font substitutions of NFSS:
44 LaTeX Font Warning: Font shape `OT1/cmr/invalid/n' undefined
45 (Font) using `OT1/cmr/m/n' instead on input line 0."""),
46 ("pyx", "WARNING", r"""ignoring font substitutions of NFSS:
47 LaTeX Font Warning: Some font shapes were not available, defaults substituted."""))
49 @log_capture(level=logging.WARNING)
50 def testOverfullHboxWarning(self, l):
51 text.text(0, 0, r"hello, world", textattrs=[text.parbox(30*unit.u_pt)])
52 l.check(("pyx", "WARNING", r"""ignoring overfull/underfull box:
53 Overfull \hbox (8.22089pt too wide) detected at line 0
54 []\OT1/cmr/m/n/10 hello,"""))
56 @log_capture(level=logging.WARNING)
57 def testUnderfullHboxWarning(self, l):
58 text.text(0, 0, r"\hbadness=0hello, world, hello", textattrs=[text.parbox(2.5)])
59 l.check(("pyx", "WARNING", r"""ignoring overfull/underfull box:
60 Underfull \hbox (badness 171) detected at line 0
61 []\OT1/cmr/m/n/10 hello, world,"""))
63 @log_capture(level=logging.WARNING)
64 def testOverfullVboxWarning(self, l):
65 text.text(0, 0, r"\parindent=0pt\vbox to 1cm {hello, world, hello, world, hello, world}", textattrs=[text.parbox(1.9)])
66 l.check(("pyx", "WARNING", r"""ignoring overfull/underfull box:
67 Overfull \vbox (2.4917pt too high) detected at line 0"""))
69 @log_capture(level=logging.WARNING)
70 def testUnderfullVboxWarning(self, l):
71 text.text(0, 0, r"\parindent=0pt\vbox to 1cm {hello, world, hello, world}", textattrs=[text.parbox(1.9)])
72 l.check(("pyx", "WARNING", r"""ignoring overfull/underfull box:
73 Underfull \vbox (badness 10000) detected at line 0"""))
75 def testLoadLongFileNames(self):
76 testfilename = "x"*100
77 with open(testfilename + ".tex", "w") as f:
78 f.write("\message{ignore this}")
79 text.text(0, 0, "\\input %s\n" % testfilename, texmessages=[text.texmessage.load])
80 os.remove(testfilename + ".tex")
81 with open(testfilename + ".eps", "w") as f:
82 f.write("%%BoundingBox: 0 0 10 10")
83 text.text(0, 0, r"\includegraphics{%s}" % testfilename)
84 os.remove(testfilename + ".eps")
86 def setUp(self):
87 text.set(engine=text.LatexEngine)
88 text.preamble(r"\usepackage{graphicx}")
90 if __name__ == "__main__":
91 unittest.main()