further attribute work
[PyX/mjg.git] / test / unit / test_attr.py
blob9a332e70e9e747e65e97e916955f154f847c2221
1 import unittest
3 import pyx
4 from pyx.attr import *
6 class A1(attr): pass
7 class B1(attr): pass
8 class C1(attr): pass
10 class A2(exclusiveattr): pass
11 class B2(exclusiveattr): pass
12 class C2(exclusiveattr): pass
14 class A3(sortattr): pass
15 class B3(sortattr): pass
16 class C3(attr): pass
19 class AttrTestCase(unittest.TestCase):
21 def testCheck(self):
22 checkattrs([A1(), B1(), A1()], [A1, B1])
23 try:
24 checkattrs([A1(), B1(), A1()], [A1, C1])
25 assert 0, "should have failed"
26 except TypeError:
27 pass
29 def testMerge(self):
30 a1 = A1()
31 a2 = A1()
32 b1 = B1()
33 b2 = B1()
34 c1 = C1()
35 c2 = C1()
36 assert mergeattrs([a1, b2, b1, c2, a2, c1]) == [a1, b2, b1, c2, a2, c1]
38 def testExclusive(self):
39 a1 = A2(A2)
40 a2 = A2(A2)
41 b1 = B2(B2)
42 b2 = B2(B2)
43 c1 = C2(C2)
44 c2 = C2(C2)
45 assert mergeattrs([a1, b2, b1, c2, a2, c1]) == [b1, a2, c1]
47 def testSort(self):
48 a1 = A3((B3, C3))
49 a2 = A3((B3, C3))
50 b1 = B3((C3))
51 b2 = B3((C3))
52 c1 = C3()
53 c2 = C3()
54 assert mergeattrs([a1, b2, b1, c2, a2, c1]) == [a1, a2, b2, b1, c2, c1]
57 suite = unittest.TestSuite((unittest.makeSuite(AttrTestCase, 'test'), ))
59 if __name__ == "__main__":
60 runner = unittest.TextTestRunner()
61 runner.run(suite)