File: test_setmulti.py

package info (click to toggle)
python-memcache 1.57-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 360 kB
  • ctags: 313
  • sloc: python: 1,204; makefile: 43; sh: 19
file content (72 lines) | stat: -rw-r--r-- 1,860 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
#
#  Tests for set_multi.
#
# ==============
#  This is based on a skeleton test file, more information at:
#
#     https://github.com/linsomniac/python-unittest-skeleton

from __future__ import print_function

import socket
import sys
import unittest

sys.path.append('..')
import memcache

DEBUG = False


class test_Memcached_Set_Multi(unittest.TestCase):
    def setUp(self):
        RECV_CHUNKS = [b'chunk1']

        class FakeSocket(object):
            def __init__(self, *args):
                if DEBUG:
                    print('FakeSocket{0!r}'.format(args))
                self._recv_chunks = list(RECV_CHUNKS)

            def connect(self, *args):
                if DEBUG:
                    print('FakeSocket.connect{0!r}'.format(args))

            def sendall(self, *args):
                if DEBUG:
                    print('FakeSocket.sendall{0!r}'.format(args))

            def recv(self, *args):
                if self._recv_chunks:
                    data = self._recv_chunks.pop(0)
                else:
                    data = ''
                if DEBUG:
                    print('FakeSocket.recv{0!r} -> {1!r}'.format(args, data))
                return data

            def close(self):
                if DEBUG:
                    print('FakeSocket.close()')

        self.old_socket = socket.socket
        socket.socket = FakeSocket

        self.mc = memcache.Client(['memcached'], debug=True)

    def tearDown(self):
        socket.socket = self.old_socket

    def test_Socket_Disconnect(self):
        mapping = {'foo': 'FOO', 'bar': 'BAR'}
        bad_keys = self.mc.set_multi(mapping)

        self.assertEqual(sorted(bad_keys), ['bar', 'foo'])

        if DEBUG:
            print('set_multi({0!r}) -> {1!r}'.format(mapping, bad_keys))


if __name__ == '__main__':
    unittest.main()