rename texmessage.loadfd to texmessage.loaddef and allow for .def and .fd files
[PyX/mjg.git] / test / unit / test_dvifile.py
blob28acbb33f6ae2f332eefe412916c908bb5816d33
1 import sys
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)
20 while df.readpage():
21 pass
22 pyxdvifilelines = list(pyxdvifile.getvalue().split("\n"))
23 pyxdvifilelineno = 0
25 while dvitypelineno < len(dvitypelines) and pyxdvifilelineno < len(pyxdvifilelines):
26 dvitypeline = dvitypelines[dvitypelineno].rstrip()
27 if dvitypeline.startswith("[") and dvitypeline.endswith("]"):
28 dvitypelineno += 1
29 continue
31 pyxdvifileline = pyxdvifilelines[pyxdvifilelineno].rstrip()
32 if pyxdvifileline.startswith("[") and pyxdvifileline.endswith("]"):
33 pyxdvifilelineno += 1
34 continue
36 pyxdvifilelinere = (pyxdvifileline.replace("+", "\\+")
37 .replace("(", "\\(")
38 .replace(")", "\\)")
39 .replace("???", "-?\\d+") +
40 "( warning: \\|h\\|>\\d+!)?" +
41 "$")
42 if re.match(pyxdvifilelinere, dvitypeline):
43 dvitypelineno += 1
44 pyxdvifilelineno += 1
45 else:
46 raise ValueError("difference:\n%s\n%s" % (dvitypeline, pyxdvifileline))
47 # print "difference:"
48 # print "\t", dvitypeline
49 # print "\t", pyxdvifileline
50 # dvitypelineno += 1
51 # pyxdvifilelineno += 1
53 # don't be strict about empty tailing lines
54 while dvitypelineno < len(dvitypelines) and not dvitypelines[dvitypelineno].strip():
55 dvitypelineno += 1
56 while pyxdvifilelineno < len(pyxdvifilelines) and not pyxdvifilelines[pyxdvifilelineno].strip():
57 pyxdvifilelineno += 1
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"
71 "i\\par\n"
72 "\\font\\myfont=cmr10 at 457.12346pt\\myfont\n"
73 "m\\par\n"
74 "\\bye\n")
75 texfile.close()
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__":
82 unittest.main()