def test_intersection_update(self): self.myset = TwoWaySyncSet([self.a1, self.b1]) self.otherset = TwoWaySyncSet([self.b1, self.c3]) self.myset.__iand__(self.otherset) self.assertIsInstance(self.myset, TwoWaySyncSet) self.assertIn(self.b1, self.myset) self.assertNotIn(self.a1, self.myset) self.assertNotIn(self.c3, self.myset) self.myset = TwoWaySyncSet([self.a1, self.b1]) self.otherset = TwoWaySyncSet([self.b1, self.c3]) self.myset &= self.otherset self.assertIsInstance(self.myset, TwoWaySyncSet) self.assertIn(self.b1, self.myset) self.assertNotIn(self.a1, self.myset) self.assertNotIn(self.c3, self.myset) self.myset = TwoWaySyncSet([self.a1, self.b1]) self.otherset = TwoWaySyncSet([self.b1, self.c3]) self.myset.intersection_update(self.otherset) self.assertIsInstance(self.myset, TwoWaySyncSet) self.assertIn(self.b1, self.myset) self.assertNotIn(self.a1, self.myset) self.assertNotIn(self.c3, self.myset) self.myset = TwoWaySyncSet([self.a1, self.b1]) set1 = TwoWaySyncSet([self.a1, self.b2]) set2 = TwoWaySyncSet([self.a1, self.c1]) self.myset.intersection_update(set1, set2) self.assertIsInstance(self.myset, TwoWaySyncSet) self.assertIn(self.a1, self.myset) self.assertNotIn(self.b1, self.myset) self.assertNotIn(self.c1, self.myset)
def test_difference_update(self): self.myset = TwoWaySyncSet([self.a1, self.b1]) self.otherset = TwoWaySyncSet([self.b1, self.c3]) self.myset.__isub__(self.otherset) self.assertIsInstance(self.myset, TwoWaySyncSet) self.assertIn(self.a1, self.myset) self.assertNotIn(self.b1, self.myset) self.myset = TwoWaySyncSet([self.a1, self.b1]) self.otherset = TwoWaySyncSet([self.b1, self.c3]) self.myset -= self.otherset self.assertIsInstance(self.myset, TwoWaySyncSet) self.assertIn(self.a1, self.myset) self.assertNotIn(self.b1, self.myset) self.myset = TwoWaySyncSet([self.a1, self.b1]) self.otherset = TwoWaySyncSet([self.b1, self.c3]) self.myset.difference_update(self.otherset) self.assertIsInstance(self.myset, TwoWaySyncSet) self.assertIn(self.a1, self.myset) self.assertNotIn(self.b1, self.myset) self.myset = TwoWaySyncSet([self.a1, self.b1, self.c1]) set1 = TwoWaySyncSet([self.b1]) set2 = TwoWaySyncSet([self.c1]) self.myset.difference_update(set1, set2) self.assertIsInstance(self.myset, TwoWaySyncSet) self.assertIn(self.a1, self.myset) self.assertNotIn(self.b1, self.myset) self.assertNotIn(self.c1, self.myset)
def test_union(self): self.myset = TwoWaySyncSet([self.a1, self.b1]) self.otherset = TwoWaySyncSet([self.b1, self.c1]) data = self.myset.__or__(self.otherset) self.assertIsInstance(data, TwoWaySyncSet) self.assertIn(self.a1, data) self.assertIn(self.b1, data) self.assertIn(self.c1, data) self.myset = TwoWaySyncSet([self.a1, self.b1]) self.otherset = TwoWaySyncSet([self.b1, self.c1]) data = self.myset | self.otherset self.assertIsInstance(data, TwoWaySyncSet) self.assertIn(self.a1, data) self.assertIn(self.b1, data) self.assertIn(self.c1, data) self.myset = TwoWaySyncSet([self.a1, self.b1]) self.otherset = TwoWaySyncSet([self.b1, self.c1]) data = self.myset.union(self.otherset) self.assertIsInstance(data, TwoWaySyncSet) self.assertIn(self.a1, data) self.assertIn(self.b1, data) self.assertIn(self.c1, data) self.myset = TwoWaySyncSet([self.a1, self.b2]) set1 = TwoWaySyncSet([self.b1, self.c2]) set2 = TwoWaySyncSet([self.c1]) data = self.myset.union(set1, set2) self.assertIsInstance(data, TwoWaySyncSet) self.assertIn(self.a1, data) self.assertIn(self.b2, data) self.assertIn(self.c2, data)
def test_update(self): self.myset = TwoWaySyncSet([self.a1]) self.otherset = TwoWaySyncSet([self.b1]) self.myset.__ior__(self.otherset) self.assertIsInstance(self.myset, TwoWaySyncSet) self.assertIn(self.a1, self.myset) self.assertIn(self.b1, self.myset) self.myset = TwoWaySyncSet([self.a1]) self.otherset = TwoWaySyncSet([self.b1]) self.myset |= self.otherset self.assertIsInstance(self.myset, TwoWaySyncSet) self.assertIn(self.a1, self.myset) self.assertIn(self.b1, self.myset) self.myset = TwoWaySyncSet([self.a1]) self.otherset = TwoWaySyncSet([self.b1]) self.myset.update(self.otherset) self.assertIsInstance(self.myset, TwoWaySyncSet) self.assertIn(self.a1, self.myset) self.assertIn(self.b1, self.myset) self.myset = TwoWaySyncSet([self.a1]) set1 = TwoWaySyncSet([self.b1]) set2 = TwoWaySyncSet([self.c1]) self.myset.update(set1, set2) self.assertIsInstance(self.myset, TwoWaySyncSet) self.assertIn(self.a1, self.myset) self.assertIn(self.b1, self.myset) self.assertIn(self.c1, self.myset)
def test_difference(self): self.myset = TwoWaySyncSet([self.a1, self.b1]) set1 = TwoWaySyncSet([self.b1]) data = self.myset.__sub__(set1) self.assertIsInstance(data, TwoWaySyncSet) self.assertIn(self.a1, data) self.assertNotIn(self.b1, data) self.myset = TwoWaySyncSet([self.a1, self.b1]) set1 = TwoWaySyncSet([self.b1]) data = self.myset - set1 self.assertIsInstance(data, TwoWaySyncSet) self.assertIn(self.a1, data) self.assertNotIn(self.b1, data) self.myset = TwoWaySyncSet([self.a1, self.b1]) set1 = TwoWaySyncSet([self.b1]) data = self.myset.difference(set1) self.assertIsInstance(data, TwoWaySyncSet) self.assertIn(self.a1, data) self.assertNotIn(self.b1, data) self.myset = TwoWaySyncSet([self.a1, self.b1]) set1 = TwoWaySyncSet([self.b1]) set2 = TwoWaySyncSet([self.c1]) data = self.myset.difference(set1, set2) self.assertIsInstance(data, TwoWaySyncSet) self.assertIn(self.a1, data) self.assertNotIn(self.b1, data) self.assertNotIn(self.c1, data)
def test_twoway_diff(self): for m in (self.a2, self.b2, self.c2): self.myset.add(m) for m in (self.a1, self.b2, self.c3): self.otherset.add(m) only_in_self, only_in_other, newer_in_self, newer_in_other = self.myset.diff(self.otherset) for coll in (only_in_self, only_in_other, newer_in_self, newer_in_other): self.assertIsInstance(coll, TwoWaySyncSet) self.assertEqual(only_in_self, TwoWaySyncSet()) self.assertEqual(only_in_other, TwoWaySyncSet()) self.assertEqual(newer_in_self, TwoWaySyncSet([self.a2])) self.assertEqual(newer_in_other, TwoWaySyncSet([self.c3]))
def setUp(self): self.myset = TwoWaySyncSet() self.otherset = TwoWaySyncSet() self.a1 = TestMember('a', 1) self.a2 = TestMember('a', 2) self.a3 = TestMember('a', 3) self.b1 = TestMember('b', 1) self.b2 = TestMember('b', 2) self.b3 = TestMember('b', 3) self.c1 = TestMember('c', 1) self.c2 = TestMember('c', 2) self.c3 = TestMember('c', 3)
def test_twoway_diff_2(self): m0 = TestMember(0, 1) m10 = TestMember(4, 1) for m in (self.a2, self.b1, m0): self.myset.add(m) for m in (self.a1, self.b2, m10): self.otherset.add(m) only_in_self, only_in_other, newer_in_self, newer_in_other = self.myset.diff(self.otherset) for coll in (only_in_self, only_in_other, newer_in_self, newer_in_other): self.assertIsInstance(coll, TwoWaySyncSet) self.assertEqual(only_in_self, TwoWaySyncSet([m0])) self.assertEqual(only_in_other, TwoWaySyncSet([m10])) self.assertEqual(newer_in_self, TwoWaySyncSet([self.a2])) self.assertEqual(newer_in_other, TwoWaySyncSet([self.b2]))
def test_equal(self): self.assertEqual( TwoWaySyncSet([self.a1, self.b1])[self.a1.get_id()], TwoWaySyncSet([self.a1, self.b1])[self.a1.get_id()] ) self.assertEqual( TwoWaySyncSet([self.a1, self.b1])[self.a1.get_id()], TwoWaySyncSet([self.b1, self.a1])[self.a1.get_id()] ) self.assertEqual(TwoWaySyncSet([self.b1, self.a1]), TwoWaySyncSet([self.a1, self.b1])) self.assertNotEqual(OneWaySyncSet([self.a1]), OneWaySyncSet([self.a1, self.b1])) self.assertNotEqual(OneWaySyncSet([self.a1, self.b1]), OneWaySyncSet([self.a1, self.c1]))
def test_symmetric_difference_update(self): self.myset = TwoWaySyncSet([self.a1, self.b1]) self.otherset = TwoWaySyncSet([self.b1, self.c3]) self.myset.__ixor__(self.otherset) self.assertIsInstance(self.myset, TwoWaySyncSet) self.assertIn(self.a1, self.myset) self.assertIn(self.c3, self.myset) self.assertNotIn(self.b1, self.myset) self.myset = TwoWaySyncSet([self.a1, self.b1]) self.otherset = TwoWaySyncSet([self.b1, self.c3]) self.myset ^= self.otherset self.assertIsInstance(self.myset, TwoWaySyncSet) self.assertIn(self.a1, self.myset) self.assertIn(self.c3, self.myset) self.assertNotIn(self.b1, self.myset) self.myset = TwoWaySyncSet([self.a1, self.b1]) self.otherset = TwoWaySyncSet([self.b1, self.c3]) self.myset.symmetric_difference_update(self.otherset) self.assertIsInstance(self.myset, TwoWaySyncSet) self.assertIn(self.a1, self.myset) self.assertIn(self.c3, self.myset) self.assertNotIn(self.b1, self.myset)
def test_symmetric_difference(self): self.myset = TwoWaySyncSet([self.a1, self.b1]) self.otherset = TwoWaySyncSet([self.b1, self.c1]) data = self.myset.__xor__(self.otherset) self.assertIsInstance(data, TwoWaySyncSet) self.assertIn(self.a1, data) self.assertIn(self.c1, data) self.assertNotIn(self.b1, data) self.myset = TwoWaySyncSet([self.a1, self.b1]) self.otherset = TwoWaySyncSet([self.b1, self.c1]) data = self.myset ^ self.otherset self.assertIsInstance(data, TwoWaySyncSet) self.assertIn(self.a1, data) self.assertIn(self.c1, data) self.assertNotIn(self.b1, data) self.myset = TwoWaySyncSet([self.a1, self.b1]) self.otherset = TwoWaySyncSet([self.b1, self.c1]) data = self.myset.symmetric_difference(self.otherset) self.assertIsInstance(data, TwoWaySyncSet) self.assertIn(self.a1, data) self.assertIn(self.c1, data) self.assertNotIn(self.b1, data)
def test_get(self): self.assertEqual(TwoWaySyncSet([self.a1, self.b1]).get(self.a1.get_id()), self.a1)
def test_copy(self): self.myset = TwoWaySyncSet([self.a1]) set_copy = self.myset.copy() self.assertIsInstance(set_copy, TwoWaySyncSet)
def test_constructor(self): self.assertEqual(self.myset, self.otherset) self.assertEqual(self.myset.item_dict, self.otherset.item_dict) self.myset = TwoWaySyncSet([self.a1, self.b1, self.c1]) self.otherset = TwoWaySyncSet([self.a1, self.b1, self.c1]) self.assertEqual(self.myset, self.otherset) self.assertEqual(self.myset.item_dict, self.otherset.item_dict) self.otherset = TwoWaySyncSet([self.c1, self.a1, self.b1]) self.assertEqual(self.myset, self.otherset) self.assertEqual(self.myset.item_dict, self.otherset.item_dict) self.assertEqual(TwoWaySyncSet([self.a2, self.a1]), TwoWaySyncSet([self.a1, self.a2])) self.assertTrue(TwoWaySyncSet([self.a2, self.a1]) == TwoWaySyncSet([self.a1, self.a2])) self.assertNotEqual(TwoWaySyncSet([self.a2, self.a1]), TwoWaySyncSet([self.a3, self.a1])) self.assertNotEqual(TwoWaySyncSet([self.a1, self.b1]), TwoWaySyncSet([self.a1, self.b2]))