def test_intset(self): writer = SetWriter(int) hset = SetHandle('myset', int) writer.append(hset, 11) writer.append(hset, 13) writer.append(hset, 17) myset = Set(hset) self.assertEqual(myset, set([11, 13, 17]))
def test_unique_indexed_set(self): writer = SetWriter(int, index_key = 'myindex', unique_index = True) hset1 = SetHandle('myset:1', int) hset2 = SetHandle('myset:2', int) for i in 1, 2, 3: writer.append(hset1, i) writer.append(hset2, i + 3) self.assertRaises(UniqueError, writer.append, hset1, 4) self.assertRaises(UniqueError, writer.append, hset2, 2) self.assertEqual(Set(hset1), set([1, 2, 3])) self.assertEqual(Set(hset2), set([4, 5, 6])) self.assertEqual(ds.hgetall('myindex'), {'1': '1', '2': '1', '3': '1', '4': '2', '5': '2', '6': '2'})
def test_indexed_set(self): writer = SetWriter(int, index_key = 'myindex') hset1 = SetHandle('myset:1', int) hset2 = SetHandle('myset:2', int) for i in 1, 2, 3: writer.append(hset1, i) for i in 2, 3, 4, 5: writer.append(hset2, i) self.assertEqual(Set(hset1), set([1, 2, 3])) self.assertEqual(Set(hset2), set([2, 3, 4, 5])) self.assertEqual(ds.smembers('myindex:1'), set(['1'])) self.assertEqual(ds.smembers('myindex:2'), set(['1', '2'])) self.assertEqual(ds.smembers('myindex:3'), set(['1', '2'])) self.assertEqual(ds.smembers('myindex:4'), set(['2'])) self.assertEqual(ds.smembers('myindex:5'), set(['2'])) self.assertEqual(ds.smembers('myindex:6'), set())