def test_update(self): s = rom.Set(connection=self.conn, key="s") s.add("one") s.update(["one", "two"]) self.assertEqual(set(["one", "two"]), s.value) s.update(["two", "three"]) self.assertEqual(set(["one", "two", "three"]), s.value)
def test_len(self): s = rom.Set(connection=self.conn, key="s") self.assertEqual(0, len(s)) s.value = ["a", "b", "c"] self.assertEqual(3, len(s)) s.remove("b") self.assertEqual(2, len(s))
def test_cachable(self): s = rom.Set(connection=self.conn, key="s", cacheable=True) s.value = set(['a', 'b', 'c']) value = s.value self.conn.sadd(s.key, 'd') self.assertEqual(set(['d']).union(value), self.conn.smembers(s.key)) self.assertEqual(value, s.value)
def test_remove(self): s = rom.Set(connection=self.conn, key="s") s.value = ["one", "two"] self.assertEqual((True, 1), s.remove("two")) self.assertRaises(KeyError, s.remove, "two") self.assertEqual(set(["one"]), s.value) self.assertEqual((True, 0), s.remove("one")) self.assertEqual(set(), s.value)
def test_discard(self): s = rom.Set(connection=self.conn, key="s") s.value = ["one", "two"] self.assertEqual((True, 1), s.discard("two")) self.assertEqual((False, 1), s.discard("two")) self.assertEqual(set(["one"]), s.value) self.assertEqual((True, 0), s.discard("one")) self.assertEqual(set(), s.value)
def test_add(self): s = rom.Set(connection=self.conn, key="s") s.add("one") self.assertEqual(set(["one"]), s.value) s.add("one") self.assertEqual(set(["one"]), s.value) s.add("two") self.assertEqual(set(["one", "two"]), s.value)
def test_value(self): s = rom.Set(connection=self.conn, key="s") self.assertEqual(set(), s.value) native_set = set(["one", "two", "three"]) s.value = native_set self.assertEqual(native_set, s.value) native_set = set(["four"]) s.value = native_set self.assertEqual(native_set, s.value) self.assertEqual(str(native_set), str(s))
def test_add_return_size(self): s = rom.Set(connection=self.conn, key="s") rv, size = s.add_return_size("one") self.assertEqual(1, rv) self.assertEqual(1, size) self.assertItemsEqual(["one"], s.value) rv, size = s.add_return_size("one") self.assertEqual(0, rv) self.assertEqual(1, size) self.assertItemsEqual(["one"], s.value) rv, size = s.add_return_size("two") self.assertEqual(1, rv) self.assertEqual(2, size) self.assertItemsEqual(["one", "two"], s.value)
def test_iterator(self): s = rom.Set(connection=self.conn, key="s") s.value = ["a", "b", "c"] self.assertEqual(["a", "b", "c"], sorted([x for x in s]))