当前位置: 首页>>代码示例>>Python>>正文


Python test.make_test_client函数代码示例

本文整理汇总了Python中pylibmc.test.make_test_client函数的典型用法代码示例。如果您正苦于以下问题:Python make_test_client函数的具体用法?Python make_test_client怎么用?Python make_test_client使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了make_test_client函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_zerokey

 def test_zerokey(self):
     bc = make_test_client(binary=True)
     k = "\x00\x01"
     test_str = "test"
     ok_(bc.set(k, test_str))
     rk = next(iter(bc.get_multi([k])))
     eq_(k, rk)
开发者ID:7ujian,项目名称:pylibmc,代码行数:7,代码来源:test_client.py

示例2: test_get_with_default

 def test_get_with_default(self):
     mc = make_test_client(binary=True)
     key = 'get-api-test'
     mc.delete(key)
     eq_(mc.get(key), None)
     default = object()
     assert mc.get(key, default) is default
开发者ID:lericson,项目名称:pylibmc,代码行数:7,代码来源:test_client.py

示例3: setUp

 def setUp(self):
     self.mc = make_test_client(
         cls=self.memcached_client,
         server_type=self.memcached_server_type,
         host=self.memcached_host,
         port=self.memcached_port,
     )
开发者ID:ketralnis,项目名称:pylibmc,代码行数:7,代码来源:__init__.py

示例4: _test_get

 def _test_get(self, key, val):
     bc = make_test_client(binary=True)
     refcountables = [key, val]
     initial_refcounts = get_refcounts(refcountables)
     bc.set(key, val)
     eq_(get_refcounts(refcountables), initial_refcounts)
     eq_(bc.get(key), val)
     eq_(get_refcounts(refcountables), initial_refcounts)
开发者ID:CoolCloud,项目名称:pylibmc,代码行数:8,代码来源:test_refcounts.py

示例5: test_none_values

 def test_none_values(self):
     mc = make_test_client(binary=True)
     mc.set('none-test', None)
     self.assertEqual(mc.get('none-test'), None)
     self.assertEqual(mc.get('none-test', 'default'), None)
     # formerly, this would raise a KeyError, which was incorrect
     self.assertEqual(mc['none-test'], None)
     assert 'none-test' in mc
开发者ID:lericson,项目名称:pylibmc,代码行数:8,代码来源:test_client.py

示例6: test_cas

 def test_cas(self):
     k = "testkey"
     mc = make_test_client(binary=False, behaviors={"cas": True})
     ok_(mc.set(k, 0))
     while True:
         rv, cas = mc.gets(k)
         ok_(mc.cas(k, rv + 1, cas))
         if rv == 10:
             break
开发者ID:JonathanMatthey,项目名称:top10trackslastfm,代码行数:9,代码来源:test_client.py

示例7: test_get_multi

 def test_get_multi(self):
     bc = make_test_client(binary=True)
     keys = ["first", "second"]
     value = "first_value"
     refcountables = keys + [value]
     initial_refcounts = get_refcounts(refcountables)
     bc.set(keys[0], value)
     eq_(get_refcounts(refcountables), initial_refcounts)
     eq_(bc.get_multi(keys), {keys[0]: value})
     eq_(get_refcounts(refcountables), initial_refcounts)
开发者ID:CoolCloud,项目名称:pylibmc,代码行数:10,代码来源:test_refcounts.py

示例8: test_override_deserialize

    def test_override_deserialize(self):
        class MyClient(pylibmc.Client):
            ignored = []

            def deserialize(self, bytes_, flags):
                try:
                    return super(MyClient, self).deserialize(bytes_, flags)
                except Exception as error:
                    self.ignored.append(error)
                    raise pylibmc.CacheMiss

        global MyObject  # Needed by the pickling system.

        class MyObject(object):
            def __getstate__(self):
                return dict(a=1)

            def __eq__(self, other):
                return type(other) is type(self)

            def __setstate__(self, d):
                assert d["a"] == 1

        c = make_test_client(MyClient, behaviors={"cas": True})
        eq_(c.get("notathing"), None)

        refcountables = ["foo", "myobj", "noneobj", "myobj2", "cachemiss"]
        initial_refcounts = get_refcounts(refcountables)

        c["foo"] = "foo"
        c["myobj"] = MyObject()
        c["noneobj"] = None
        c["myobj2"] = MyObject()

        # Show that everything is initially regular.
        eq_(c.get("myobj"), MyObject())
        eq_(get_refcounts(refcountables), initial_refcounts)
        eq_(c.get_multi(["foo", "myobj", "noneobj", "cachemiss"]), dict(foo="foo", myobj=MyObject(), noneobj=None))
        eq_(get_refcounts(refcountables), initial_refcounts)
        eq_(c.gets("myobj2")[0], MyObject())
        eq_(get_refcounts(refcountables), initial_refcounts)

        # Show that the subclass can transform unpickling issues into a cache miss.
        del MyObject  # Break unpickling

        eq_(c.get("myobj"), None)
        eq_(get_refcounts(refcountables), initial_refcounts)
        eq_(c.get_multi(["foo", "myobj", "noneobj", "cachemiss"]), dict(foo="foo", noneobj=None))
        eq_(get_refcounts(refcountables), initial_refcounts)
        eq_(c.gets("myobj2"), (None, None))
        eq_(get_refcounts(refcountables), initial_refcounts)

        # The ignored errors are "AttributeError: test.test_client has no MyObject"
        eq_(len(MyClient.ignored), 3)
        assert all(isinstance(error, AttributeError) for error in MyClient.ignored)
开发者ID:cwaeland,项目名称:pylibmc,代码行数:55,代码来源:test_serialization.py

示例9: test_get_multi_bytes_and_unicode

 def test_get_multi_bytes_and_unicode(self):
     bc = make_test_client(binary=True)
     keys = ["third", b"fourth"]
     value = "another_value"
     kv = dict((k, value) for k in keys)
     refcountables = [keys] + [value]
     initial_refcounts = get_refcounts(refcountables)
     bc.set_multi(kv)
     eq_(get_refcounts(refcountables), initial_refcounts)
     eq_(bc.get_multi(keys)[keys[0]], value)
     eq_(get_refcounts(refcountables), initial_refcounts)
开发者ID:CoolCloud,项目名称:pylibmc,代码行数:11,代码来源:test_refcounts.py

示例10: test_get_invalid_key

 def test_get_invalid_key(self):
     bc = make_test_client(binary=True)
     key = object()
     initial_refcount = sys.getrefcount(key)
     raised = False
     try:
         bc.get(key)
     except TypeError:
         raised = True
     assert raised
     eq_(sys.getrefcount(key), initial_refcount)
开发者ID:CoolCloud,项目名称:pylibmc,代码行数:11,代码来源:test_refcounts.py

示例11: test_incr

    def test_incr(self):
        bc = make_test_client(binary=True)
        keys = [b"increment_key", "increment_key_again"]
        refcountables = keys
        initial_refcounts = get_refcounts(refcountables)

        bc.set(keys[0], 1)
        eq_(get_refcounts(refcountables), initial_refcounts)
        bc.incr(keys[0])
        eq_(get_refcounts(refcountables), initial_refcounts)
        bc.set(keys[1], 5)
        eq_(get_refcounts(refcountables), initial_refcounts)
        bc.incr(keys[1])
        eq_(get_refcounts(refcountables), initial_refcounts)
开发者ID:CoolCloud,项目名称:pylibmc,代码行数:14,代码来源:test_refcounts.py

示例12: test_zerokey

 def test_zerokey(self):
     bc = make_test_client(binary=True)
     k = "\x00\x01"
     test_str = "test"
     ok_(bc.set(k, test_str))
     if PY3:
         rk = list(bc.get_multi([k]).keys())[0]
         # Keys are converted to UTF-8 strings before being
         # used, so the key that we get back will be a byte
         # string. Encode the test key to match this.
         k = k.encode('utf-8')
     else:
         rk = bc.get_multi([k]).keys()[0]
     eq_(k, rk)
开发者ID:Wikia,项目名称:pylibmc,代码行数:14,代码来源:test_client.py

示例13: test_cas

    def test_cas(self):
        k = "testkey"
        val = 1138478589238
        mc = make_test_client(binary=False, behaviors={'cas': True})
        refcountables = [k, val]
        initial_refcounts = get_refcounts(refcountables)

        ok_(mc.set(k, 0))
        eq_(get_refcounts(refcountables), initial_refcounts)
        while True:
            rv, cas = mc.gets(k)
            eq_(get_refcounts(refcountables), initial_refcounts)
            ok_(mc.cas(k, rv + 1, cas))
            eq_(get_refcounts(refcountables), initial_refcounts)
            if rv == 10:
                break
开发者ID:CoolCloud,项目名称:pylibmc,代码行数:16,代码来源:test_refcounts.py

示例14: test_nonintegers

    def test_nonintegers(self):
        # tuples (python_value, (expected_bytestring, expected_flags))
        SERIALIZATION_TEST_VALUES = [
            # booleans
            (True, (b"1", 16)),
            (False, (b"0", 16)),
            # bytestrings
            (b"asdf", (b"asdf", 0)),
            (b"\xb5\xb1\xbf\xed\xa9\xc2{8", (b"\xb5\xb1\xbf\xed\xa9\xc2{8", 0)),
            # objects
            (datetime.date(2015, 12, 28), (pickle.dumps(datetime.date(2015, 12, 28)), 1)),
        ]

        c = make_test_client(binary=True)
        for value, serialized_value in SERIALIZATION_TEST_VALUES:
            eq_(c.serialize(value), serialized_value)
            eq_(c.deserialize(*serialized_value), value)
开发者ID:cwaeland,项目名称:pylibmc,代码行数:17,代码来源:test_serialization.py

示例15: test_get_with_default

 def test_get_with_default(self):
     bc = make_test_client(binary=True)
     key = b'refcountest4'
     val = 'some_value'
     default = object()
     refcountables = [key, val, default]
     initial_refcounts = get_refcounts(refcountables)
     bc.set(key, val)
     eq_(get_refcounts(refcountables), initial_refcounts)
     assert bc.get(key) == val
     eq_(get_refcounts(refcountables), initial_refcounts)
     assert bc.get(key, default) == val
     eq_(get_refcounts(refcountables), initial_refcounts)
     bc.delete(key)
     assert bc.get(key) is None
     eq_(get_refcounts(refcountables), initial_refcounts)
     assert bc.get(key, default) is default
     eq_(get_refcounts(refcountables), initial_refcounts)
开发者ID:lericson,项目名称:pylibmc,代码行数:18,代码来源:test_refcounts.py


注:本文中的pylibmc.test.make_test_client函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。