create py3k branch
[PyX.git] / test / unit / test_attr.py
bloba6417f72e983fd0e805540850d51dacf431efe75
1 import sys
2 if sys.path[0] != "../..":
3 sys.path.insert(0, "../..")
5 import unittest
7 import pyx
8 from pyx.attr import *
10 class A1(attr): pass
11 class B1(attr): pass
12 class C1(attr): pass
14 class A2(exclusiveattr): pass
15 class B2(exclusiveattr): pass
16 class C2(exclusiveattr): pass
18 class A3(sortbeforeattr): pass
19 class B3(sortbeforeattr): pass
20 class C3(attr): pass
22 class A4(sortbeforeexclusiveattr): pass
23 class B4(sortbeforeexclusiveattr): pass
24 class C4(attr): pass
27 class AttrTestCase(unittest.TestCase):
29 def testCheck(self):
30 checkattrs([A1(), B1(), A1()], [A1, B1])
31 self.failUnlessRaises(TypeError, checkattrs, [A1(), B1(), A1()], [A1, C1])
33 def testMerge(self):
34 a1 = A1()
35 a2 = A1()
36 b1 = B1()
37 b2 = B1()
38 c1 = C1()
39 c2 = C1()
40 self.failUnlessEqual(mergeattrs([a1, b2, b1, c2, a2, c1]), [a1, b2, b1, c2, a2, c1])
42 def testExclusive(self):
43 a1 = A2(A2)
44 a2 = A2(A2)
45 b1 = B2(B2)
46 b2 = B2(B2)
47 c1 = C2(C2)
48 c2 = C2(C2)
49 self.failUnlessEqual(mergeattrs([a1, b2, b1, c2, a2, c1]), [b1, a2, c1])
51 def testSort(self):
52 a1 = A3((B3, C3))
53 a2 = A3((B3, C3))
54 b1 = B3((C3,))
55 b2 = B3((C3,))
56 c1 = C3()
57 c2 = C3()
58 self.failUnlessEqual(mergeattrs([a1, b2, b1, c2, a2, c1]), [a1, a2, b2, b1, c2, c1])
60 def testExclusiveSort(self):
61 a1 = A4(A4, (B4, C4))
62 a2 = A4(A4, (B4, C4))
63 b1 = B4(B4, (C4,))
64 b2 = B4(B4, (C4,))
65 c1 = C4()
66 c2 = C4()
67 self.failUnlessEqual(mergeattrs([b2, a1, b1, c2, a2, c1]), [a2, b1, c2, c1])
70 if __name__ == "__main__":
71 unittest.main()