File: test_cmemcached.py

package info (click to toggle)
pylibmc 1.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 300 kB
  • sloc: ansic: 1,859; python: 529; makefile: 91
file content (56 lines) | stat: -rw-r--r-- 1,776 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Ported cmemcached tests"""

import pylibmc
from nose.tools import eq_
from tests import PylibmcTestCase

class TestCmemcached(PylibmcTestCase):
    def testSetAndGet(self):
        self.mc.set("num12345", 12345)
        eq_(self.mc.get("num12345"), 12345)
        self.mc.set("str12345", "12345")
        eq_(self.mc.get("str12345"), "12345")

    def testDelete(self):
        self.mc.set("str12345", "12345")
        #delete return True on success, otherwise False
        assert self.mc.delete("str12345")
        assert self.mc.get("str12345") is None

        # This test only works with old memcacheds. This has become a "client
        # error" in memcached.
        try:
            assert not self.mc.delete("hello world")
        except pylibmc.ClientError:
            pass

    def testGetMulti(self):
        self.mc.set("a", "valueA")
        self.mc.set("b", "valueB")
        self.mc.set("c", "valueC")
        result = self.mc.get_multi(["a", "b", "c", "", "hello world"])
        eq_(result, {'a':'valueA', 'b':'valueB', 'c':'valueC'})

    def testBigGetMulti(self):
        count = 10 ** 4
        keys = ['key%d' % i for i in xrange(count)]
        pairs = zip(keys, ['value%d' % i for i in xrange(count)])
        for key, value in pairs:
            self.mc.set(key, value)
        result = self.mc.get_multi(keys)
        eq_(result, dict(pairs))

    def testFunnyDelete(self):
        assert not self.mc.delete("")

    def testAppend(self):
        self.mc.delete("a")
        self.mc.set("a", "I ")
        assert self.mc.append("a", "Do")
        eq_(self.mc.get("a"), "I Do")

    def testPrepend(self):
        self.mc.delete("a")
        self.mc.set("a", "Do")
        assert self.mc.prepend("a", "I ")
        eq_(self.mc.get("a"), "I Do")