prevent double call of _cleanup, which harms usefiles (and is a bad idea in general)
[PyX.git] / test / unit / test_parter.py
bloba7678a6d0406e07a9016451b90799d8df2fc60d9
1 import sys
2 if sys.path[0] != "../..":
3 sys.path.insert(0, "../..")
5 import unittest
7 from pyx import *
8 from pyx.graph.axis.tick import tick, rational
9 from pyx.graph.axis.parter import lin, log, preexp
12 class ParterTestCase(unittest.TestCase):
14 def PartEqual(self, part1, part2):
15 self.assertEqual(len(part1), len(part2))
16 for tick1, tick2 in zip(part1, part2):
17 self.assertEqual(tick1, tick2)
18 self.assertEqual(tick1.ticklevel, tick2.ticklevel)
19 self.assertEqual(tick1.labellevel, tick2.labellevel)
20 self.assertEqual(tick1.label, tick2.label)
22 def testLinParter(self):
23 self.PartEqual(lin(tickdists=["10"], labeldists=[]).partfunctions(0, 1, 1, 1)[0](),
24 [tick((0, 1), 0, None), tick((10, 1), 0, None)])
25 self.PartEqual(lin(tickdists=["1", "0.5"], labeldists=[]).partfunctions(0, 1, 1, 1)[0](),
26 [tick((0, 1), 0, None), tick((1, 2), 1, None), tick((1, 1), 0, None)])
27 self.PartEqual(lin(tickdists=["1", "0.5", "0.25"], labeldists=[]).partfunctions(0, 1, 1, 1)[0](),
28 [tick((0, 1), 0, None), tick((1, 4), 2, None), tick((1, 2), 1, None), tick((3, 4), 2, None), tick((1, 1), 0, None)])
29 self.PartEqual(lin(tickdists=["1", "0.5"], labeldists=[], extendtick=None).partfunctions(0, 1.5, 1, 1)[0](),
30 [tick((0, 1), 0, None), tick((1, 2), 1, None), tick((1, 1), 0, None), tick((3, 2), 1, None)])
31 self.PartEqual(lin(tickdists=["1", "0.5"], labeldists=[], extendtick=1).partfunctions(0, 1.2, 1, 1)[0](),
32 [tick((0, 1), 0, None), tick((1, 2), 1, None), tick((1, 1), 0, None), tick((3, 2), 1, None)])
33 self.PartEqual(lin(tickdists=["1", "0.5"], labeldists=[], extendtick=0).partfunctions(0, 1.2, 1, 1)[0](),
34 [tick((0, 1), 0, None), tick((1, 2), 1, None), tick((1, 1), 0, None), tick((3, 2), 1, None), tick((2, 1), 0, None)])
35 self.PartEqual(lin(labeldists=["1"], tickdists=[]).partfunctions(0, 1, 1, 1)[0](),
36 [tick((0, 1), None, 0), tick((1, 1), None, 0)])
37 self.PartEqual(lin(labeldists=["1", "0.5"], tickdists=[]).partfunctions(0, 1, 1, 1)[0](),
38 [tick((0, 1), None, 0), tick((1, 2), None, 1), tick((1, 1), None, 0)])
39 self.PartEqual(lin(labeldists=["1", "0.5", "0.25"], tickdists=[]).partfunctions(0, 1, 1, 1)[0](),
40 [tick((0, 1), None, 0), tick((1, 4), None, 2), tick((1, 2), None, 1), tick((3, 4), None, 2), tick((1, 1), None, 0)])
41 self.PartEqual(lin(labeldists=["1", "0.5"], tickdists=[], extendlabel=None).partfunctions(0, 1.5, 1, 1)[0](),
42 [tick((0, 1), None, 0), tick((1, 2), None, 1), tick((1, 1), None, 0), tick((3, 2), None, 1)])
43 self.PartEqual(lin(labeldists=["1", "0.5"], tickdists=[], extendlabel=1).partfunctions(0, 1.2, 1, 1)[0](),
44 [tick((0, 1), None, 0), tick((1, 2), None, 1), tick((1, 1), None, 0), tick((3, 2), None, 1)])
45 self.PartEqual(lin(labeldists=["1", "0.5"], tickdists=[], extendlabel=0).partfunctions(0, 1.2, 1, 1)[0](),
46 [tick((0, 1), None, 0), tick((1, 2), None, 1), tick((1, 1), None, 0), tick((3, 2), None, 1), tick((2, 1), None, 0)])
47 self.PartEqual(lin(tickdists=["1"]).partfunctions(0, 1, 1, 1)[0](),
48 [tick((0, 1), 0, 0), tick((1, 1), 0, 0)])
49 self.PartEqual(lin(tickdists=["1", "0.5"]).partfunctions(0, 1, 1, 1)[0](),
50 [tick((0, 1), 0, 0), tick((1, 2), 1, None), tick((1, 1), 0, 0)])
51 self.PartEqual(lin(tickdists=["1", "0.5", "0.25"]).partfunctions(0, 1, 1, 1)[0](),
52 [tick((0, 1), 0, 0), tick((1, 4), 2, None), tick((1, 2), 1, None), tick((3, 4), 2, None), tick((1, 1), 0, 0)])
53 self.PartEqual(lin(tickdists=["1", "0.5"], extendtick=None).partfunctions(0, 1.5, 1, 1)[0](),
54 [tick((0, 1), 0, 0), tick((1, 2), 1, None), tick((1, 1), 0, 0), tick((3, 2), 1, None)])
55 self.PartEqual(lin(tickdists=["1", "0.5"], extendtick=1).partfunctions(0, 1.2, 1, 1)[0](),
56 [tick((0, 1), 0, 0), tick((1, 2), 1, None), tick((1, 1), 0, 0), tick((3, 2), 1, None)])
57 self.PartEqual(lin(tickdists=["1", "0.5"], extendtick=0).partfunctions(0, 1.2, 1, 1)[0](),
58 [tick((0, 1), 0, 0), tick((1, 2), 1, None), tick((1, 1), 0, 0), tick((3, 2), 1, None), tick((2, 1), 0, 0)])
59 self.PartEqual(lin(labeldists=["1"]).partfunctions(0, 1, 1, 1)[0](),
60 [tick((0, 1), 0, 0), tick((1, 1), 0, 0)])
61 self.PartEqual(lin(labeldists=["1", "0.5"]).partfunctions(0, 1, 1, 1)[0](),
62 [tick((0, 1), 0, 0), tick((1, 2), None, 1), tick((1, 1), 0, 0)])
63 self.PartEqual(lin(labeldists=["1", "0.5", "0.25"]).partfunctions(0, 1, 1, 1)[0](),
64 [tick((0, 1), 0, 0), tick((1, 4), None, 2), tick((1, 2), None, 1), tick((3, 4), None, 2), tick((1, 1), 0, 0)])
65 self.PartEqual(lin(labeldists=["1", "0.5"], extendtick=None).partfunctions(0, 1.5, 1, 1)[0](),
66 [tick((0, 1), 0, 0), tick((1, 2), None, 1), tick((1, 1), 0, 0), tick((3, 2), None, 1)])
67 self.PartEqual(lin(labeldists=["1", "0.5"], extendtick=None, extendlabel=1).partfunctions(0, 1.2, 1, 1)[0](),
68 [tick((0, 1), 0, 0), tick((1, 2), None, 1), tick((1, 1), 0, 0), tick((3, 2), None, 1)])
69 self.PartEqual(lin(labeldists=["1", "0.5"], extendtick=None, extendlabel=0).partfunctions(0, 1.2, 1, 1)[0](),
70 [tick((0, 1), 0, 0), tick((1, 2), None, 1), tick((1, 1), 0, 0), tick((3, 2), None, 1), tick((2, 1), 0, 0)])
72 def testLogParter(self):
73 self.PartEqual(log(tickpreexps=[log.pre1exp], labelpreexps=[]).partfunctions(1, 10, 1, 1)[0](),
74 [tick((1, 1), 0, None), tick((10, 1), 0, None)])
75 self.PartEqual(log(tickpreexps=[log.pre1exp], labelpreexps=[]).partfunctions(1, 100, 1, 1)[0](),
76 [tick((1, 1), 0, None), tick((10, 1), 0, None), tick((100, 1), 0, None)])
77 self.PartEqual(log(tickpreexps=[preexp([rational((1, 1))], 100)], labelpreexps=[]).partfunctions(1, 100, 1, 1)[0](),
78 [tick((1, 1), 0, None), tick((100, 1), 0, None)])
79 self.PartEqual(log(tickpreexps=[log.pre1to9exp], labelpreexps=[]).partfunctions(1, 10, 1, 1)[0](),
80 [tick((1, 1), 0, None), tick((2, 1), 0, None), tick((3, 1), 0, None), tick((4, 1), 0, None), tick((5, 1), 0, None), tick((6, 1), 0, None), tick((7, 1), 0, None), tick((8, 1), 0, None), tick((9, 1), 0, None), tick((10, 1), 0, None)])
81 self.PartEqual(log(tickpreexps=[log.pre1exp, log.pre1to9exp], labelpreexps=[]).partfunctions(1, 10, 1, 1)[0](),
82 [tick((1, 1), 0, None), tick((2, 1), 1, None), tick((3, 1), 1, None), tick((4, 1), 1, None), tick((5, 1), 1, None), tick((6, 1), 1, None), tick((7, 1), 1, None), tick((8, 1), 1, None), tick((9, 1), 1, None), tick((10, 1), 0, None)])
83 self.PartEqual(log(tickpreexps=[log.pre1exp, log.pre1to9exp]).partfunctions(1, 10, 1, 1)[0](),
84 [tick((1, 1), 0, 0), tick((2, 1), 1, None), tick((3, 1), 1, None), tick((4, 1), 1, None), tick((5, 1), 1, None), tick((6, 1), 1, None), tick((7, 1), 1, None), tick((8, 1), 1, None), tick((9, 1), 1, None), tick((10, 1), 0, 0)])
87 if __name__ == "__main__":
88 unittest.main()