2 if sys
.path
[0] != "../..":
3 sys
.path
.insert(0, "../..")
5 import io
, os
, re
, unittest
7 from pyx
.dvi
import dvifile
10 class DvifileTestCase(unittest
.TestCase
):
12 def dvitypetester(self
, advifile
):
13 with os
.popen("dvitype %s" % advifile
) as dvitypefile
:
14 dvitypelines
= dvitypefile
.readlines()
15 dvitypelineno
= dvitypelines
.index(" \n") + 1
17 pyxdvifile
= io
.StringIO()
18 df
= dvifile
.DVIfile(advifile
, debug
=1, debugfile
=pyxdvifile
)
21 pyxdvifilelines
= list(pyxdvifile
.getvalue().split("\n"))
24 while dvitypelineno
< len(dvitypelines
) and pyxdvifilelineno
< len(pyxdvifilelines
):
25 dvitypeline
= dvitypelines
[dvitypelineno
].rstrip()
26 if dvitypeline
.startswith("[") and dvitypeline
.endswith("]"):
30 pyxdvifileline
= pyxdvifilelines
[pyxdvifilelineno
].rstrip()
31 if pyxdvifileline
.startswith("[") and pyxdvifileline
.endswith("]"):
35 pyxdvifilelinere
= (pyxdvifileline
.replace("+", "\\+")
38 .replace("???", "-?\\d+") +
39 "( warning: \\|h\\|>\\d+!)?" +
41 if re
.match(pyxdvifilelinere
, dvitypeline
):
45 raise ValueError("difference:\n%s\n%s" % (dvitypeline
, pyxdvifileline
))
47 # print "\t", dvitypeline
48 # print "\t", pyxdvifileline
50 # pyxdvifilelineno += 1
52 # don't be strict about empty tailing lines
53 while dvitypelineno
< len(dvitypelines
) and not dvitypelines
[dvitypelineno
].strip():
55 while pyxdvifilelineno
< len(pyxdvifilelines
) and not pyxdvifilelines
[pyxdvifilelineno
].strip():
58 assert dvitypelineno
== len(dvitypelines
)
59 assert pyxdvifilelineno
== len(pyxdvifilelines
)
61 def testDvitypeSample2e(self
):
62 os
.system("latex sample2e.tex > /dev/null 2> /dev/null")
63 self
.dvitypetester("sample2e.dvi")
64 os
.system("rm sample2e.*")
66 def testDvitypeBigScale(self
):
67 with
open("bigscale.tex", "w") as texfile
:
68 texfile
.write("\\nopagenumbers\n"
69 "\\font\\myfont=cmr10 at 145.678pt\\myfont\n"
71 "\\font\\myfont=cmr10 at 457.12346pt\\myfont\n"
74 os
.system("tex bigscale.tex > /dev/null 2> /dev/null")
75 self
.dvitypetester("bigscale.dvi")
76 os
.system("rm bigscale.*")
79 if __name__
== "__main__":