Package ldaptor :: Package test :: Module test_attributeset
[hide private]
[frames] | no frames]

Source Code for Module ldaptor.test.test_attributeset

  1  """ 
  2  Test cases for ldaptor.attributeset 
  3  """ 
  4   
  5  from twisted.trial import unittest 
  6  import sets 
  7  from ldaptor import attributeset 
  8   
9 -class TestComparison(unittest.TestCase):
10 - def testEquality_True_Set(self):
11 a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd']) 12 b = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd']) 13 self.assertEquals(a, b)
14
16 a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd']) 17 b = attributeset.LDAPAttributeSet('k', ['b', 'd', 'c']) 18 self.assertEquals(a, b)
19
20 - def testEquality_True_List(self):
21 a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd']) 22 b = ['b', 'c', 'd'] 23 self.assertEquals(a, b)
24
26 a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd']) 27 b = ['b', 'd', 'c'] 28 self.assertEquals(a, b)
29
30 - def testEquality_False_Value(self):
31 a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd']) 32 b = attributeset.LDAPAttributeSet('k', ['b', 'c', 'e']) 33 self.assertNotEqual(a, b)
34
35 - def testEquality_False_Key(self):
36 a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd']) 37 b = attributeset.LDAPAttributeSet('l', ['b', 'c', 'd']) 38 self.assertNotEqual(a, b)
39
40 -class TestSetOperations(unittest.TestCase):
41 - def testDifference(self):
42 a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd']) 43 b = attributeset.LDAPAttributeSet('k', ['b', 'c', 'e']) 44 self.assertEquals(a - b, sets.Set(['d']))
45
46 - def testUnion(self):
47 a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd']) 48 b = attributeset.LDAPAttributeSet('k', ['b', 'c', 'e']) 49 self.assertEquals(a | b, sets.Set(['b', 'c', 'd', 'e']))
50
51 - def testIntersection(self):
52 a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd']) 53 b = attributeset.LDAPAttributeSet('k', ['b', 'c', 'e']) 54 self.assertEquals(a & b, sets.Set(['b', 'c']))
55
56 - def testSymmetricDifference(self):
57 a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd']) 58 b = attributeset.LDAPAttributeSet('k', ['b', 'c', 'e']) 59 self.assertEquals(a ^ b, sets.Set(['d', 'e']))
60
61 - def testCopy(self):
62 class Magic: 63 pass
64 m1 = Magic() 65 a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd', m1]) 66 b = a.__copy__() 67 self.assertEquals(a, b) 68 self.assertNotIdentical(a, b) 69 70 magicFromA = [val for val in a if isinstance(val, Magic)][0] 71 magicFromB = [val for val in b if isinstance(val, Magic)][0] 72 self.assertEquals(magicFromA, magicFromB) 73 self.assertIdentical(magicFromA, magicFromB) 74 75 a.update('x') 76 self.assertEquals(a, sets.Set(['b', 'c', 'd', m1, 'x'])) 77 self.assertEquals(b, sets.Set(['b', 'c', 'd', m1]))
78
79 - def testDeepCopy(self):
80 class Magic: 81 def __eq__(self, other): 82 return isinstance(other, self.__class__)
83 def __hash__(self): 84 return 42 85 m1 = Magic() 86 a = attributeset.LDAPAttributeSet('k', ['a', m1]) 87 b = a.__deepcopy__({}) 88 self.assertEquals(a, b) 89 self.assertNotIdentical(a, b) 90 91 magicFromA = [val for val in a if isinstance(val, Magic)][0] 92 magicFromB = [val for val in b if isinstance(val, Magic)][0] 93 self.assertEquals(magicFromA, magicFromB) 94 self.assertNotIdentical(magicFromA, magicFromB) 95 96 a.update('x') 97 self.assertEquals(a, sets.Set(['a', m1, 'x'])) 98 self.assertEquals(b, sets.Set(['a', m1])) 99