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
=[]):
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
)):
25 print "difference at position %d" % i
26 print ord(c1
), ord(c2
)
30 def testWarnings(self
):
31 self
.failUnlessRaisesUserWarning(r
"\some \badly \broken \TeX", r
"""ignoring all warnings:
33 *! Undefined control sequence.
38 ! Undefined control sequence.
39 <argument> \some \badly
43 ! Undefined control sequence.
44 <argument> \some \badly \broken
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}")
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")
77 text
.text(0, 0, r
"\includegraphics{%s}" % testfilename
)
78 os
.remove(testfilename
+ ".eps")
81 text
.set(mode
="latex")
83 text
.preamble(r
"\usepackage{graphicx}")
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.""":
96 if __name__
== "__main__":