2 if sys
.path
[0] != "../..":
3 sys
.path
.insert(0, "../..")
5 import cStringIO
, os
, re
, unittest
7 from pyx
import dvifile
10 class DvifileTestCase(unittest
.TestCase
):
12 def dvitypetester(self
, advifile
):
13 dvitypefile
= os
.popen("dvitype %s" % advifile
)
14 dvitypelines
= dvitypefile
.readlines()
15 dvitypelineno
= dvitypelines
.index(" \n") + 1
17 pyxdvifile
= cStringIO
.StringIO()
18 df
= dvifile
.dvifile(advifile
, dvifile
.readfontmap(["psfonts.map"]),
19 debug
=1, debugfile
=pyxdvifile
)
22 pyxdvifilelines
= list(pyxdvifile
.getvalue().split("\n"))
25 while dvitypelineno
< len(dvitypelines
) and pyxdvifilelineno
< len(pyxdvifilelines
):
26 dvitypeline
= dvitypelines
[dvitypelineno
].rstrip()
27 if dvitypeline
.startswith("[") and dvitypeline
.endswith("]"):
31 pyxdvifileline
= pyxdvifilelines
[pyxdvifilelineno
].rstrip()
32 if pyxdvifileline
.startswith("[") and pyxdvifileline
.endswith("]"):
36 pyxdvifilelinere
= (pyxdvifileline
.replace("+", "\\+")
39 .replace("???", "-?\\d+") +
40 "( warning: \\|h\\|>\\d+!)?" +
42 if re
.match(pyxdvifilelinere
, dvitypeline
):
46 raise ValueError("difference:\n%s\n%s" % (dvitypeline
, pyxdvifileline
))
48 # print "\t", dvitypeline
49 # print "\t", pyxdvifileline
51 # pyxdvifilelineno += 1
53 # don't be strict about empty tailing lines
54 while dvitypelineno
< len(dvitypelines
) and not dvitypelines
[dvitypelineno
].strip():
56 while pyxdvifilelineno
< len(pyxdvifilelines
) and not pyxdvifilelines
[pyxdvifilelineno
].strip():
59 assert dvitypelineno
== len(dvitypelines
)
60 assert pyxdvifilelineno
== len(pyxdvifilelines
)
62 def testDvitypeSample2e(self
):
63 os
.system("latex sample2e.tex > /dev/null 2> /dev/null")
64 self
.dvitypetester("sample2e.dvi")
65 os
.system("rm sample2e.*")
67 def testDvitypeBigScale(self
):
68 texfile
= open("bigscale.tex", "w")
69 texfile
.write("\\nopagenumbers\n"
70 "\\font\\myfont=cmr10 at 145.678pt\\myfont\n"
72 "\\font\\myfont=cmr10 at 457.12346pt\\myfont\n"
76 os
.system("tex bigscale.tex > /dev/null 2> /dev/null")
77 self
.dvitypetester("bigscale.dvi")
78 os
.system("rm bigscale.*")
81 if __name__
== "__main__":