add UnicodeEngine (MultiEngineText and axis texters returning MultiEngineText), texte...
[PyX.git] / test / unit / test_dvifile.py
blob833b1c9ccb110baf0a5ec4d2e62a2e8b829168dd
1 import sys
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)
19 while df.readpage():
20 pass
21 pyxdvifilelines = list(pyxdvifile.getvalue().split("\n"))
22 pyxdvifilelineno = 0
24 while dvitypelineno < len(dvitypelines) and pyxdvifilelineno < len(pyxdvifilelines):
25 dvitypeline = dvitypelines[dvitypelineno].rstrip()
26 if dvitypeline.startswith("[") and dvitypeline.endswith("]"):
27 dvitypelineno += 1
28 continue
30 pyxdvifileline = pyxdvifilelines[pyxdvifilelineno].rstrip()
31 if pyxdvifileline.startswith("[") and pyxdvifileline.endswith("]"):
32 pyxdvifilelineno += 1
33 continue
35 pyxdvifilelinere = (pyxdvifileline.replace("+", "\\+")
36 .replace("(", "\\(")
37 .replace(")", "\\)")
38 .replace("???", "-?\\d+") +
39 "( warning: \\|h\\|>\\d+!)?" +
40 "$")
41 if re.match(pyxdvifilelinere, dvitypeline):
42 dvitypelineno += 1
43 pyxdvifilelineno += 1
44 else:
45 raise ValueError("difference:\n%s\n%s" % (dvitypeline, pyxdvifileline))
46 # print "difference:"
47 # print "\t", dvitypeline
48 # print "\t", pyxdvifileline
49 # dvitypelineno += 1
50 # pyxdvifilelineno += 1
52 # don't be strict about empty tailing lines
53 while dvitypelineno < len(dvitypelines) and not dvitypelines[dvitypelineno].strip():
54 dvitypelineno += 1
55 while pyxdvifilelineno < len(pyxdvifilelines) and not pyxdvifilelines[pyxdvifilelineno].strip():
56 pyxdvifilelineno += 1
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"
70 "i\\par\n"
71 "\\font\\myfont=cmr10 at 457.12346pt\\myfont\n"
72 "m\\par\n"
73 "\\bye\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__":
80 unittest.main()