generate PDF, as well
[PyX/mjg.git] / test / unit / test_texmessageparser.py
blob4f4ff16a1ff27916cebe4089cc356ecf189cb010
1 import sys
2 if sys.path[0] != "../..":
3 sys.path.insert(0, "../..")
5 import unittest, warnings, os
7 from pyx import text, unit
9 # text.set(texdebug="bla.tex", usefiles=["bla.log"])
11 class MessageParserTestCase(unittest.TestCase):
13 def failUnlessRaisesUserWarning(self, texexpression, warningmessage, textattrs=[], texmessages=[]):
14 try:
15 warnings.resetwarnings()
16 warnings.filterwarnings(action="error")
17 text.text(0, 0, texexpression, textattrs=textattrs, texmessages=texmessages)
18 except UserWarning, w:
19 if str(w) != warningmessage:
20 if 0: # turn on for debugging differences
21 print len(str(w)), len(warningmessage)
22 for i, (c1, c2) in enumerate(zip(str(w), warningmessage)):
23 print c1,
24 if c1 != c2:
25 print "difference at position %d" % i
26 print ord(c1), ord(c2)
27 break
28 raise
30 def testWarnings(self):
31 self.failUnlessRaisesUserWarning(r"\some \badly \broken \TeX", r"""ignoring all warnings:
33 *! Undefined control sequence.
34 <argument> \some
35 \badly \broken \TeX
36 <*> }{1}
38 ! Undefined control sequence.
39 <argument> \some \badly
40 \broken \TeX
41 <*> }{1}
43 ! Undefined control sequence.
44 <argument> \some \badly \broken
45 \TeX
46 <*> }{1}
52 """, texmessages=[text.texmessage.allwarning])
53 self.failUnlessRaisesUserWarning(r"\fontseries{invalid}\selectfont{}hello, world", r"""ignoring font warning:
54 LaTeX Font Warning: Font shape `OT1/cmr/invalid/n' undefined
55 (Font) using `OT1/cmr/m/n' instead on input line 0.""", texmessages=[text.texmessage.fontwarning])
56 self.failUnlessRaisesUserWarning(r"hello, world", r"""ignoring overfull/underfull box warning:
57 Overfull \hbox (8.22089pt too wide) detected at line 0
58 []\OT1/cmr/m/n/10 hello,""", textattrs=[text.parbox(30*unit.u_pt)])
59 self.failUnlessRaisesUserWarning(r"\hbadness=0hello, world, hello", r"""ignoring overfull/underfull box warning:
60 Underfull \hbox (badness 171) detected at line 0
61 []\OT1/cmr/m/n/10 hello, world,""", textattrs=[text.parbox(2.5)])
62 self.failUnlessRaisesUserWarning(r"\parindent=0pt\vbox to 1cm {hello, world, hello, world, hello, world}", r"""ignoring overfull/underfull box warning:
63 Overfull \vbox (2.4917pt too high) detected at line 0""", textattrs=[text.parbox(1.9)])
64 self.failUnlessRaisesUserWarning(r"\parindent=0pt\vbox to 1cm {hello, world, hello, world}", r"""ignoring overfull/underfull box warning:
65 Underfull \vbox (badness 10000) detected at line 0""", textattrs=[text.parbox(1.9)])
67 def testLoadLongFileNames(self):
68 testfilename = "x"*100
69 f = open(testfilename + ".tex", "w")
70 f.write("\message{ignore this}")
71 f.close()
72 text.text(0, 0, "\\input %s\n" % testfilename, texmessages=[text.texmessage.load])
73 os.remove(testfilename + ".tex")
74 f = open(testfilename + ".eps", "w")
75 f.write("%%BoundingBox: 0 0 10 10")
76 f.close()
77 text.text(0, 0, r"\includegraphics{%s}" % testfilename)
78 os.remove(testfilename + ".eps")
80 def setUp(self):
81 text.set(mode="latex")
82 text.reset()
83 text.preamble(r"\usepackage{graphicx}")
85 def tearDown(self):
86 try:
87 warnings.resetwarnings()
88 warnings.filterwarnings(action="error")
89 text.defaulttexrunner.finishdvi()
90 except UserWarning, w:
91 if str(w) != """ignoring font warning:
92 LaTeX Font Warning: Some font shapes were not available, defaults substituted.""":
93 raise
96 if __name__ == "__main__":
97 unittest.main()