diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml index f77b034..4c2f5ef 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -33,10 +33,10 @@ jobs: - run: cmake . - - name: Setup Python 2 for tests + - name: Setup Python 3 for tests uses: actions/setup-python@v2 with: - python-version: 2.7 + python-version: 3.7 - name: Install test requirements run: pip install -r test-run/requirements.txt diff --git a/README.md b/README.md index 943d177..b59ed45 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,9 @@ Memcached protocol 'wrapper' for Tarantool. * Tarantol 1.6.8+ with header files (tarantool && tarantool-dev packages). * Cyrus SASL library (with header files) - * Python >= 2.7, <3 with next packages (for testing only): - - PyYAML - - msgpack-python - - six==1.9.0 + * Python >= 3.7 with next packages (for testing only): + - PyYAML 5+ + - gevent 21+ ### Installation @@ -150,7 +149,7 @@ Usual rules for memcached are applicable for this plugin: import bmemcached client = bmemcached.Client(('127.0.0.1:11211', ), 'testuser', 'testpasswd') client.set('key', 'value') - print client.get('key') + print(client.get('key')) ``` For custom configuration file path, please, use `SASL_CONF_PATH` environment variable. diff --git a/test-run b/test-run index 38400e9..d16cbdc 160000 --- a/test-run +++ b/test-run @@ -1 +1 @@ -Subproject commit 38400e91c600677fb661154d00459d660fa9880d +Subproject commit d16cbdc2702e7d939d5d34e41730fd83d2c65879 diff --git a/test/binary/binary-boundary.test.py b/test/binary/binary-boundary.test.py index ebd310a..fea631b 100644 --- a/test/binary/binary-boundary.test.py +++ b/test/binary/binary-boundary.test.py @@ -10,14 +10,16 @@ from internal.memcached_connection import MemcachedBinaryConnection from internal.memcached_connection import STATUS, COMMANDS +from internal.compat import string_types + mc = MemcachedBinaryConnection("127.0.0.1", iproto.py_con.port) def iequal(left, right, level = 1): if (left != right): tb = traceback.extract_stack()[-(level + 1)] - print "Error on line %s:%d: %s not equal %s" % (tb[0], tb[1], - repr(left), repr(right)) - if (isinstance(left, basestring)): + print("Error on line %s:%d: %s not equal %s" % (tb[0], tb[1], + repr(left), repr(right))) + if (isinstance(left, string_types)): if (len(left) != len(right)): print("length is different") return False @@ -39,7 +41,7 @@ def check(key, flags, val, level = 0): val = "x" * i mc.setq(key, val, flags=82, nosend=True) mc.setq("alt_%s" % key, "blah", flags=82, nosend=True) - data = "".join(mc.commands) + data = b"".join(mc.commands) mc.commands = [] if (len(data) > 2024): diff --git a/test/binary/binary-expire.test.py b/test/binary/binary-expire.test.py index 3b09fb7..50c2698 100644 --- a/test/binary/binary-expire.test.py +++ b/test/binary/binary-expire.test.py @@ -15,15 +15,15 @@ def iequal(left, right, level = 1): if (left != right): tb = traceback.extract_stack()[-(level + 1)] - print "Error on line %s:%d: %s not equal %s" % (tb[0], tb[1], - repr(left), repr(right)) + print("Error on line %s:%d: %s not equal %s" % (tb[0], tb[1], + repr(left), repr(right))) return False return True def issert(stmt, level = 1): if not bool(stmt): tb = traceback.extract_stack()[-(level + 1)] - print "Error on line %s:%d: result is False" % (tb[0], tb[1]) + print("Error on line %s:%d: result is False" % (tb[0], tb[1])) return False return True @@ -41,7 +41,7 @@ def check(key, flags, val, level = 0): stat = mc.stat("reset") -for i in xrange(10000): +for i in range(10000): mc.set('key-%d' % i, 'value-%d' % i, expire=1) stat = mc.stat() diff --git a/test/binary/binary-gh-73.test.py b/test/binary/binary-gh-73.test.py index 948aa8d..80515de 100644 --- a/test/binary/binary-gh-73.test.py +++ b/test/binary/binary-gh-73.test.py @@ -18,7 +18,7 @@ key = "test_key_%d" % i mc.setq(key, val, flags = 82, nosend=True) -data = "".join(mc.commands) +data = b"".join(mc.commands) mc.socket.sendall(data) # Get any key right after setting. diff --git a/test/binary/binary-toobig.test.py b/test/binary/binary-toobig.test.py index ce2a2c1..d1c693d 100644 --- a/test/binary/binary-toobig.test.py +++ b/test/binary/binary-toobig.test.py @@ -14,24 +14,24 @@ def iequal(left, right, level = 1): if (left != right): tb = traceback.extract_stack()[-(level + 1)] - print "Error on line %s:%d: %s not equal %s" % (tb[0], tb[1], - repr(left), repr(right)) + print("Error on line %s:%d: %s not equal %s" % (tb[0], tb[1], + repr(left), repr(right))) return False return True def inequal(left, right, level = 0): if (left == right): tb = traceback.extract_stack()[-(level + 1)] - print "Error on line %s:%d: %s equal %s" % (tb[0], tb[1], - repr(left), repr(right)) + print("Error on line %s:%d: %s equal %s" % (tb[0], tb[1], + repr(left), repr(right))) return False return True def issert(stmt, level = 0): if bool(stmt): tb = traceback.extract_stack()[-(level + 1)] - print "Error on line %s:%d: is False" % (tb[0], tb[1], - repr(left), repr(right)) + print("Error on line %s:%d: is False" % (tb[0], tb[1], + repr(left), repr(right))) return False return True diff --git a/test/binary/binary.test.py b/test/binary/binary.test.py index 06300f1..51a77fc 100644 --- a/test/binary/binary.test.py +++ b/test/binary/binary.test.py @@ -14,24 +14,24 @@ def iequal(left, right, level = 1): if (left != right): tb = traceback.extract_stack()[-(level + 1)] - print "Error on line %s:%d: %s not equal %s" % (tb[0], tb[1], - repr(left), repr(right)) + print("Error on line %s:%d: %s not equal %s" % (tb[0], tb[1], + repr(left), repr(right))) return False return True def inequal(left, right, level = 0): if (left == right): tb = traceback.extract_stack()[-(level + 1)] - print "Error on line %s:%d: %s equal %s" % (tb[0], tb[1], - repr(left), repr(right)) + print("Error on line %s:%d: %s equal %s" % (tb[0], tb[1], + repr(left), repr(right))) return False return True def issert(stmt, level = 0): if bool(stmt): tb = traceback.extract_stack()[-(level + 1)] - print "Error on line %s:%d: is False" % (tb[0], tb[1], - repr(left), repr(right)) + print("Error on line %s:%d: is False" % (tb[0], tb[1], + repr(left), repr(right))) return False return True diff --git a/test/capable/capable-binary.test.py b/test/capable/capable-binary.test.py index 6f6913d..25e2c76 100644 --- a/test/capable/capable-binary.test.py +++ b/test/capable/capable-binary.test.py @@ -12,6 +12,8 @@ from internal.memcached_connection import MemcachedBinaryConnection from internal.memcached_connection import STATUS, COMMANDS +from internal.compat import bytes_to_str + mc = MemcachedBinaryConnection("127.0.0.1", iproto.py_con.port) mc.flush() @@ -20,6 +22,7 @@ task = Popen(cmd, stdout=PIPE, stderr=STDOUT) -print task.communicate()[0] +testcase = task.communicate()[0] +print(bytes_to_str(testcase)) sys.path = saved_path diff --git a/test/capable/capable-text.test.py b/test/capable/capable-text.test.py index e904610..fa36d9d 100644 --- a/test/capable/capable-text.test.py +++ b/test/capable/capable-text.test.py @@ -12,6 +12,8 @@ from internal.memcached_connection import MemcachedBinaryConnection from internal.memcached_connection import STATUS, COMMANDS +from internal.compat import bytes_to_str + mc = MemcachedBinaryConnection("127.0.0.1", iproto.py_con.port) mc.flush() @@ -20,6 +22,7 @@ task = Popen(cmd, stdout=PIPE, stderr=STDOUT) -print task.communicate()[0] +testcase = task.communicate()[0] +print(bytes_to_str(testcase)) sys.path = saved_path diff --git a/test/internal/compat.py b/test/internal/compat.py new file mode 100644 index 0000000..09bea74 --- /dev/null +++ b/test/internal/compat.py @@ -0,0 +1,48 @@ +import sys + +# Added for compatibility with Python 3. + +# Useful for very coarse version differentiation. +PY3 = sys.version_info[0] == 3 +PY2 = sys.version_info[0] == 2 + +if PY3: + string_types = str, + integer_types = int, +else: + string_types = basestring, # noqa: F821 + integer_types = (int, long) # noqa: F821 + +def assert_bytes(b): + """ Ensure given value is . + """ + if type(b) != bytes: + raise ValueError('Internal error: expected {}, got {}: {}'.format( + str(bytes), str(type(b)), repr(b))) + +def assert_str(s): + """ Ensure given value is . + """ + if type(s) != str: + raise ValueError('Internal error: expected {}, got {}: {}'.format( + str(str), str(type(s)), repr(s))) + +def bytes_to_str(b): + """ Convert to . + + No-op on Python 2. + """ + assert_bytes(b) + if PY2: + return b + return b.decode('utf-8') + +def str_to_bytes(s): + """ Convert to . + + No-op on Python 2. + """ + assert_str(s) + if PY2: + return s + return s.encode('utf-8') diff --git a/test/internal/memcached_connection.py b/test/internal/memcached_connection.py index aa8a57a..a707f1b 100644 --- a/test/internal/memcached_connection.py +++ b/test/internal/memcached_connection.py @@ -4,6 +4,7 @@ from struct import Struct from lib.tarantool_connection import TarantoolConnection +from internal.compat import bytes_to_str, str_to_bytes HEADER = '!BBHBBHLLQ' HEADER_STRUCT = Struct(HEADER) @@ -165,7 +166,7 @@ def __init__(self, host, port): self.connect() def send(self): - commands = ''.join(self.commands) + commands = b''.join(self.commands) self.socket.sendall(commands) self.commands = [] @@ -202,8 +203,8 @@ def _read_and_parse_response(self): assert(magic == MAGIC['response']) if status == STATUS['OK']: assert(ext_len == ext_lenv) - assert(((key_lenv > 0 or key_lenv is None) and key_len > 0) or key_len == 0) - assert(((val_lenv > 0 or val_lenv is None) and val_len > 0) or val_len == 0) + assert(((key_lenv is None or key_lenv > 0) and key_len > 0) or key_len == 0) + assert(((val_lenv is None or val_lenv > 0) and val_len > 0) or val_len == 0) else: assert(val_len > 0) @@ -237,7 +238,14 @@ def _read_and_parse_response(self): # decode result of (incr/decr)(q) if is_indecrq(op): val = INDECR_STRUCT.unpack_from(val)[0] - if val is not None: + else: + # Ideally we should lean on 4th bit in flags to + # decide whether to interpret this value as binary + # or as text. + # + # Unconditional interpreting it as a text is + # enough for testing purposes, though. + val = bytes_to_str(val) retval['val'] = val return retval @@ -268,9 +276,9 @@ def append_query(self, cmd, args): retval = [ struct.pack(MAGIC['request'], op, key_len, ext_len, dtype, 0, tot_len, opaque, cas, *extra), - key, val + str_to_bytes(key), str_to_bytes(val) ] - cmd = ''.join(retval) + cmd = b''.join(retval) self.commands.append(cmd) @binary_decorator @@ -477,7 +485,7 @@ def stat(self, key=''): if 'key' in rv and not rv['key'] and \ 'val' in rv and not rv['val']: return ans - ans[rv['key']] = rv['val'] + ans[bytes_to_str(rv['key'])] = rv['val'] return ans @binary_decorator @@ -559,9 +567,9 @@ def execute_no_reconnect(self, commands, silent = False): def send(self, commands, silent = False): self.commands = commands - self.socket.sendall(commands) + self.socket.sendall(str_to_bytes(commands)) if not silent: - print "<<" + '-' * 50 + print("<<" + '-' * 50) sys.stdout.write(self.commands.strip() + '\n') #sys.stdout.write(self.commands) @@ -595,7 +603,7 @@ def recv(self, silent = False): self.reply_unknown(cmd) if not silent: - print ">>" + '-'*50 + print(">>" + '-'*50) sys.stdout.write(self.reply.strip() + '\n') #sys.stdout.write(self.reply) @@ -643,7 +651,7 @@ def reply_retrieval(self, cmd): break else: # unknown - print "error: unknown line: '%s'" % key + print("error: unknown line: '%s'" % key) self.reply += "error: unknown line: '%s'" % key break @@ -699,7 +707,7 @@ def read_line(self): index = buf.find(MEMCACHED_SEPARATOR) if index > 0: break - data = self.socket.recv(1048576) + data = bytes_to_str(self.socket.recv(1048576)) if not data: return None buf += data diff --git a/test/sasl/binary-sasl.test.py b/test/sasl/binary-sasl.test.py index c16d983..8d8b06c 100644 --- a/test/sasl/binary-sasl.test.py +++ b/test/sasl/binary-sasl.test.py @@ -15,24 +15,24 @@ def iequal(left, right, level = 1): if (left != right): tb = traceback.extract_stack()[-(level + 1)] - print "Error on line %s:%d: %s not equal %s" % (tb[0], tb[1], - repr(left), repr(right)) + print("Error on line %s:%d: %s not equal %s" % (tb[0], tb[1], + repr(left), repr(right))) return False return True def inequal(left, right, level = 0): if (left == right): tb = traceback.extract_stack()[-(level + 1)] - print "Error on line %s:%d: %s equal %s" % (tb[0], tb[1], - repr(left), repr(right)) + print("Error on line %s:%d: %s equal %s" % (tb[0], tb[1], + repr(left), repr(right))) return False return True def issert(stmt, level = 0): if bool(stmt): tb = traceback.extract_stack()[-(level + 1)] - print "Error on line %s:%d: is False" % (tb[0], tb[1], - repr(left), repr(right)) + print("Error on line %s:%d: is False" % (tb[0], tb[1], + repr(left), repr(right))) return False return True @@ -80,7 +80,7 @@ def delete(key, when): res = mc.sasl_list() if res[0]['val'].find('PLAIN') == -1: - print "Error" + print("Error") secret = '%c%s%c%s' % (0, 'testuser', 0, 'testpass') res = mc.sasl_start("X" * 40, secret) diff --git a/test/text/cas.test.py b/test/text/cas.test.py index a2be81e..f221f1d 100644 --- a/test/text/cas.test.py +++ b/test/text/cas.test.py @@ -17,111 +17,111 @@ mc_client("cas bad 0 0 blah 0\r\n") mc_client("cas bad 0 0 0 blah\r\n") -print """# gets foo (should not exist) """ +print("""# gets foo (should not exist) """) mc_client("gets foo\r\n") -print """# set foo """ +print("""# set foo """) mc_client("set foo 0 0 6\r\nbarval\r\n") -print """# gets foo and verify identifier exists """ +print("""# gets foo and verify identifier exists """) mc_client("gets foo\r\n") -print """# cas fail """ +print("""# cas fail """) mc_client("cas foo 0 0 6 123\r\nbarva2\r\n") -print """# gets foo and verify identifier exists """ +print("""# gets foo and verify identifier exists """) sys.stdout.write("gets foo\r\n") result = mc_client("gets foo\r\n", silent = True) unique_id = int(result.split()[4]) -print """# cas success """ +print("""# cas success """) sys.stdout.write("cas foo 0 0 6 \r\nbarva2\r\n") result = mc_client("cas foo 0 0 6 %d\r\nbarva2\r\n" % unique_id, silent = True) sys.stdout.write(result) -print """# cas failure (reusing the same key) """ +print("""# cas failure (reusing the same key) """) sys.stdout.write("cas foo 0 0 6 \r\nbarva2\r\n") result = mc_client("cas foo 0 0 6 %d\r\nbarva2\r\n" % unique_id, silent = True) sys.stdout.write(result) -print """# delete foo """ +print("""# delete foo """) mc_client("delete foo\r\n") -print """# cas missing """ +print("""# cas missing """) sys.stdout.write("cas foo 0 0 6 \r\nbarva2\r\n") result = mc_client("cas foo 0 0 6 %d\r\nbarva2\r\n" % unique_id, silent = True) sys.stdout.write(result) -print """# set foo1 """ +print("""# set foo1 """) mc_client("set foo1 0 0 1\r\n1\r\n") -print """# set foo2 """ +print("""# set foo2 """) mc_client("set foo2 0 0 1\r\n2\r\n") -print """# gets foo1 check """ +print("""# gets foo1 check """) result = mc_client("gets foo1\r\n") foo1_cas = int(result.split()[4]) -print """# gets foo2 check """ +print("""# gets foo2 check """) result = mc_client("gets foo2\r\n") foo2_cas = int(result.split()[4]) -print """# validate foo1 != foo2 """ +print("""# validate foo1 != foo2 """) if foo1_cas != foo2_cas: - print "pass: foo1_cas != foo2_cas" + print("pass: foo1_cas != foo2_cas") else: - print "fail: foo1_cas == foo2_cas" + print("fail: foo1_cas == foo2_cas") memcached1 = mc_client memcached2 = MemcachedTextConnection('localhost', port) -print """# gets foo from memcached1 - should success """ +print("""# gets foo from memcached1 - should success """) result = memcached1("gets foo1\r\n", silent = True) mem1_cas = int(result.split()[4]) -print """# gets foo from memcached2 - should success """ +print("""# gets foo from memcached2 - should success """) result = memcached2("gets foo1\r\n", silent = True) mem2_cas = int(result.split()[4]) -print """# send 'cas foo1' from memcached1 """ +print("""# send 'cas foo1' from memcached1 """) memcached1.send("cas foo1 0 0 6 %d\r\nbarva2\r\n" % mem1_cas, silent = True) -print """# send 'cas foo1' from memcached2 """ +print("""# send 'cas foo1' from memcached2 """) memcached2.send("cas foo1 0 0 4 %d\r\npear\r\n" % mem2_cas, silent = True) -print """# recv reply 'cas foo1' from memcached1 """ +print("""# recv reply 'cas foo1' from memcached1 """) result = memcached1.recv(silent = True) mem1_cas_result = result.split()[0] -print """# recv reply 'cas foo1' from memcached2 """ +print("""# recv reply 'cas foo1' from memcached2 """) result = memcached2.recv(silent = True) mem2_cas_result = result.split()[0] if mem1_cas_result == "STORED" and mem2_cas_result == "EXISTS": - print "race cas: pass" + print("race cas: pass") elif mem1_cas_result == "EXISTS" and mem2_cas_result == "STORED": - print "race cas: pass" + print("race cas: pass") else: - print "race cas: fail" - print "cas 1 = %s" % mem1_cas_result - print "cas 2 = %s" % mem2_cas_result + print("race cas: fail") + print("cas 1 = %s" % mem1_cas_result) + print("cas 2 = %s" % mem2_cas_result) -print """# set bug15 """ +print("""# set bug15 """) mc_client("set bug15 0 0 1\r\n0\r\n") -print """# Check out the first gets. """ +print("""# Check out the first gets. """) result = mc_client("gets bug15\r\n", silent = True) bug15_cas = int(result.split()[4]) -print """# Increment. """ +print("""# Increment. """) mc_client("incr bug15 1\r\n") -print """# Validate a changed CAS. """ +print("""# Validate a changed CAS. """) result = mc_client("gets bug15\r\n", silent = True) next_bug15_cas = int(result.split()[4]) -print """# validate bug15_cas != next_bug15_cas """ +print("""# validate bug15_cas != next_bug15_cas """) if bug15_cas != next_bug15_cas: - print "pass: bug15_cas != next_bug15_cas" + print("pass: bug15_cas != next_bug15_cas") else: - print "fail: bug15_cas == next_bug15_cas" + print("fail: bug15_cas == next_bug15_cas") mc_client("flush_all\r\n") diff --git a/test/text/expirations.test.py b/test/text/expirations.test.py index f2eccd7..ce5073d 100644 --- a/test/text/expirations.test.py +++ b/test/text/expirations.test.py @@ -14,35 +14,35 @@ master_id = server.get_param('server')['id'] -print """# expire: after 1 second""" +print("""# expire: after 1 second""") server.admin("box.space.__mc_memcached:truncate()", silent=True) lsn = server.get_lsn(master_id) while True: - print """# set foo""" + print("""# set foo""") mc_client("set foo 0 1 6\r\nfooval\r\n") - print """# foo shoud exists""" + print("""# foo shoud exists""") mc_client("get foo\r\n") break server.wait_lsn(master_id, lsn + 2) -print """# foo shoud expired""" +print("""# foo shoud expired""") mc_client("get foo\r\n") lsn = server.get_lsn(master_id) while True: - print """# expire: time - 1 second""" + print("""# expire: time - 1 second""") expire = time.time() - 1 - print """# set foo""" + print("""# set foo""") mc_client("set foo 0 %d 6\r\nfooval\r\n" % expire, silent = True) - print """# foo shoud be expired""" + print("""# foo shoud be expired""") mc_client("get foo\r\n") break @@ -51,51 +51,51 @@ lsn = server.get_lsn(master_id) while True: - print """# expire: time + 1 second""" + print("""# expire: time + 1 second""") expire = time.time() + 1 - print """# set foo""" + print("""# set foo""") mc_client("set foo 0 %d 6\r\nfooval\r\n" % expire, silent = True) - print """# foo shoud exists""" + print("""# foo shoud exists""") mc_client("get foo\r\n") break server.wait_lsn(master_id, lsn + 2) -print """# foo shoud be expired""" +print("""# foo shoud be expired""") mc_client("get foo\r\n") lsn = server.get_lsn(master_id) while True: - print """# expire: time - 20 second""" + print("""# expire: time - 20 second""") expire = time.time() - 20 - print """# set boo""" + print("""# set boo""") mc_client("set boo 0 %d 6\r\nbooval\r\n" % expire, silent = True) - print """# foo shoud expired""" + print("""# foo shoud expired""") mc_client("get boo\r\n") break server.wait_lsn(master_id, lsn + 2) -print """# expire: after 2 second""" +print("""# expire: after 2 second""") lsn = server.get_lsn(master_id) while True: - print """# add add""" + print("""# add add""") mc_client("add add 0 1 6\r\naddval\r\n") - print """# readd add - shoud be fail""" + print("""# readd add - shoud be fail""") mc_client("add add 0 1 7\r\naddval1\r\n") break server.wait_lsn(master_id, lsn + 2) -print """# readd add - shoud be success""" +print("""# readd add - shoud be success""") mc_client("add add 0 1 7\r\naddval2\r\n") mc_client("flush_all\r\n") diff --git a/test/text/flags.test.py b/test/text/flags.test.py index 6af713d..0c44f8d 100644 --- a/test/text/flags.test.py +++ b/test/text/flags.test.py @@ -19,9 +19,9 @@ result = mc_client("gets foo\r\n") ret_flags = int(result.split()[2]) if flags == ret_flags: - print "success: flags (0x%x) == ret_flags (0x%x)" % (flags, ret_flags) + print("success: flags (0x%x) == ret_flags (0x%x)" % (flags, ret_flags)) else: - print "fail: flags (0x%x) != ret_flags (0x%x)" % (flags, ret_flags) + print("fail: flags (0x%x) != ret_flags (0x%x)" % (flags, ret_flags)) mc_client("flush_all\r\n") diff --git a/test/text/flush-all.test.py b/test/text/flush-all.test.py index 7cb5fc7..74752f2 100644 --- a/test/text/flush-all.test.py +++ b/test/text/flush-all.test.py @@ -16,7 +16,7 @@ ################################### def get_memcached_len(serv): resp = server.admin("box.space.__mc_memcached:len()", silent=True) - return yaml.load(resp)[0] + return yaml.safe_load(resp)[0] def wait_for_empty_space(serv = server): serv_admin = serv.admin @@ -26,20 +26,20 @@ def wait_for_empty_space(serv = server): time.sleep(0.01) ################################### -print """# Test flush_all with zero delay. """ +print("""# Test flush_all with zero delay. """) mc_client("set foo 0 0 6\r\nfooval\r\n") mc_client("get foo\r\n") mc_client("flush_all\r\n") mc_client("get foo\r\n") -print """# check that flush_all doesn't blow away items that immediately get set """ +print("""# check that flush_all doesn't blow away items that immediately get set """) mc_client("set foo 0 0 3\r\nnew\r\n") mc_client("get foo\r\n") -print """# and the other form, specifying a flush_all time... """ +print("""# and the other form, specifying a flush_all time... """) expire = time.time() + 1 -print "flush_all time + 1" -print mc_client("flush_all %d\r\n" % expire, silent=True) +print("flush_all time + 1") +print(mc_client("flush_all %d\r\n" % expire, silent=True)) mc_client("get foo\r\n") mc_client("set foo 0 0 3\r\n123\r\n") diff --git a/test/text/getset.test.py b/test/text/getset.test.py index 480ca23..9196e66 100644 --- a/test/text/getset.test.py +++ b/test/text/getset.test.py @@ -14,46 +14,46 @@ mc_client("flush_all\r\n", silent = True) -print """# set foo (and should get it) """ +print("""# set foo (and should get it) """) mc_client("set foo 0 0 6\r\nfooval\r\n") mc_client("get foo\r\n") -print """# add bar (and should get it)""" +print("""# add bar (and should get it)""") mc_client("set bar 0 0 6\r\nbarval\r\n") mc_client("get bar\r\n") -print """# add foo (but shouldn't get new value)""" +print("""# add foo (but shouldn't get new value)""") mc_client("add foo 0 0 5\r\nfoov2\r\n") mc_client("get foo\r\n") -print """# replace bar (should work)""" +print("""# replace bar (should work)""") mc_client("replace bar 0 0 6\r\nbarva2\r\n") mc_client("get bar\r\n") -print """# replace notexist (shouldn't work)""" +print("""# replace notexist (shouldn't work)""") mc_client("replace notexist 0 0 6\r\nbarva2\r\n") mc_client("get notexist\r\n") -print """# delete foo""" +print("""# delete foo""") mc_client("delete foo\r\n") mc_client("get foo\r\n") -print """# delete foo again. not found this time.""" +print("""# delete foo again. not found this time.""") mc_client("delete foo\r\n") mc_client("get foo\r\n") -print """# add moo""" +print("""# add moo""") mc_client("add moo 0 0 6\r\nmooval\r\n") mc_client("get moo\r\n") -print """# check-and-set (cas) failure case, try to set value with incorrect cas unique val""" +print("""# check-and-set (cas) failure case, try to set value with incorrect cas unique val""") mc_client("cas moo 0 0 6 0\r\nMOOVAL\r\n") mc_client("get moo\r\n") result = mc_client("gets moo\r\n", silent = True) unique_id = int(result.split()[4]) -print """# now test that we can store moo with the correct unique id""" +print("""# now test that we can store moo with the correct unique id""") mc_client("cas moo 0 0 6 %d\r\nMOOVAL\r\n" % unique_id, silent = True) mc_client("get moo\r\n") @@ -63,22 +63,22 @@ while len < (1024 * 1028): val = 'B' * len if len > (1024 * 1024): - print """# Ensure causing a memory overflow doesn't leave stale data.""" - print "# set small data: - should pass" + print("""# Ensure causing a memory overflow doesn't leave stale data.""") + print("# set small data: - should pass") mc_client("set foo_%d 0 0 3\r\nMOO\r\n" % (len)) mc_client("get foo_%d\r\n" % (len)) - print "# set big data: - should fail" - print "set foo_%d 0 0 %d\r\n\r\n" % (len, len) - print mc_client("set foo_%d 0 0 %d\r\n%s\r\n" % (len, len, val), silent = True) + print("# set big data: - should fail") + print("set foo_%d 0 0 %d\r\n\r\n" % (len, len)) + print(mc_client("set foo_%d 0 0 %d\r\n%s\r\n" % (len, len, val), silent = True)) else: - print "# set big data: - should pass" - print "set foo_%d 0 0 %d\r\n\r\n" % (len, len) - print mc_client("set foo_%d 0 0 %d\r\n%s\r\n" % (len, len, val), silent = True) + print("# set big data: - should pass") + print("set foo_%d 0 0 %d\r\n\r\n" % (len, len)) + print(mc_client("set foo_%d 0 0 %d\r\n%s\r\n" % (len, len, val), silent = True)) len += 1024 * 512 -print """# +print("""# # A test for Bug#898198 memcached protocol isn't case-insensitive" -#""" +#""") mc_client("SET foo 0 0 6\r\nfooval\r\n") mc_client("GET foo\r\n") diff --git a/test/text/incrdecr.test.py b/test/text/incrdecr.test.py index 6fa958e..0f31933 100644 --- a/test/text/incrdecr.test.py +++ b/test/text/incrdecr.test.py @@ -12,13 +12,13 @@ port = int(iproto.uri.split(':')[1]) mc_client = MemcachedTextConnection('localhost', port) -print """# incr/decr big value """ +print("""# incr/decr big value """) mc_client("set bug21 0 0 19\r\n9223372036854775807\r\n") mc_client("incr bug21 1\r\n") mc_client("incr bug21 1\r\n") mc_client("decr bug21 1\r\n") -print """# underflow protection """ +print("""# underflow protection """) mc_client("set num 0 0 1\r\n1\r\n") mc_client("incr num 1\r\n") mc_client("incr num 8\r\n") @@ -26,23 +26,23 @@ mc_client("decr num 9\r\n") mc_client("decr num 5\r\n") -print """# 32-bit value """ +print("""# 32-bit value """) mc_client("set num 0 0 10\r\n4294967296\r\n") mc_client("incr num 1\r\n") -print """# overflow value """ +print("""# overflow value """) mc_client("set num 0 0 20\r\n18446744073709551615\r\n") mc_client("incr num 1\r\n") -print """# bogus """ +print("""# bogus """) mc_client("decr bogus 1\r\n") mc_client("decr incr 1\r\n") -print """# bit increment """ +print("""# bit increment """) mc_client("set bigincr 0 0 1\r\n0\r\n") mc_client("incr bigincr 18446744073709551610\r\n") -print """# incr text value error """ +print("""# incr text value error """) mc_client("set text 0 0 2\r\nhi\r\n") mc_client("incr text 1\r\n") diff --git a/test/text/multiversioning.test.py b/test/text/multiversioning.test.py index fcf48bc..13360bb 100644 --- a/test/text/multiversioning.test.py +++ b/test/text/multiversioning.test.py @@ -13,35 +13,35 @@ mc_client = MemcachedTextConnection('localhost', port) buf_size = 256 * 1024 -buf = "0123456789abcdef" * (buf_size / 16) +buf = "0123456789abcdef" * int(buf_size / 16) buf_upper = buf.upper() memcached1 = mc_client memcached2 = MemcachedTextConnection('localhost', port) -print """# Store big in lower case via first memcached client """ -print "set big 0 0 %d\r\n" % buf_size -print memcached1("set big 0 0 %d\r\n%s\r\n" % (buf_size, buf), silent = True) +print("""# Store big in lower case via first memcached client """) +print("set big 0 0 %d\r\n" % buf_size) +print(memcached1("set big 0 0 %d\r\n%s\r\n" % (buf_size, buf), silent = True)) -print """# send command 'get big' to first memcached client """ +print("""# send command 'get big' to first memcached client """) memcached1.send("get big\r\n") time.sleep(0.01) -print """# send command 'delete big' to second client """ +print("""# send command 'delete big' to second client """) memcached2("delete big\r\n") -print """# Store big in upper case via second memcached client """ -print "set big 0 0 %d\r\n" % buf_size -print memcached2("set big 0 0 %d\r\n%s\r\n" % (buf_size, buf_upper), silent = True) +print("""# Store big in upper case via second memcached client """) +print("set big 0 0 %d\r\n" % buf_size) +print(memcached2("set big 0 0 %d\r\n%s\r\n" % (buf_size, buf_upper), silent = True)) -print """# recv reply 'get big' from the first memcached client """ +print("""# recv reply 'get big' from the first memcached client """) reply = memcached1.recv(silent = True) reply_buf = reply.split('\r\n')[1] if buf == reply_buf: - print "success: buf == reply" + print("success: buf == reply") else: - print "fail: buf != reply" - print len(buf), len(reply_buf) + print("fail: buf != reply") + print(len(buf), len(reply_buf)) server.stop() server.cleanup() diff --git a/test/text/noreply.test.py b/test/text/noreply.test.py index 342702a..940f6fe 100644 --- a/test/text/noreply.test.py +++ b/test/text/noreply.test.py @@ -12,7 +12,7 @@ port = int(iproto.uri.split(':')[1]) mc_client = MemcachedTextConnection('localhost', port) -print """# Test that commands can take 'noreply' parameter. """ +print("""# Test that commands can take 'noreply' parameter. """) mc_client("flush_all noreply\r\n") mc_client("flush_all 0 noreply\r\n") diff --git a/test/var/memcached b/test/var/memcached deleted file mode 120000 index 5f92de7..0000000 --- a/test/var/memcached +++ /dev/null @@ -1 +0,0 @@ -../../memcached/ \ No newline at end of file