Skip to content

Update tests for Python 3 #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test-run
Submodule test-run updated 72 files
+14 −0 .coveragerc
+2 −0 .flake8
+70 −0 .github/workflows/test.yml
+1 −0 .gitignore
+6 −0 .gitmodules
+32 −0 .luacheckrc
+19 −0 .tarantoolctl
+33 −0 Makefile
+114 −47 README.md
+82 −36 dispatcher.py
+0 −2 lib/Makefile
+26 −4 lib/__init__.py
+20 −14 lib/admin_connection.py
+127 −18 lib/app_server.py
+15 −18 lib/box_connection.py
+1 −0 lib/checks
+95 −46 lib/colorer.py
+7 −7 lib/connpool.py
+3 −0 lib/error.py
+26 −8 lib/inspector.py
+1 −0 lib/luatest
+133 −0 lib/luatest_server.py
+201 −62 lib/options.py
+121 −55 lib/preprocessor.py
+38 −22 lib/pytap13.py
+182 −0 lib/sampler.py
+62 −2 lib/server.py
+25 −10 lib/server_mixins.py
+0 −7 lib/singleton.py
+1 −1 lib/tarantool-python
+13 −10 lib/tarantool_connection.py
+480 −171 lib/tarantool_server.py
+88 −49 lib/test.py
+102 −21 lib/test_suite.py
+25 −10 lib/unittest_server.py
+230 −20 lib/utils.py
+80 −24 lib/worker.py
+0 −0 lib/yapps/__init__.py
+0 −442 lib/yapps/runtime.py
+222 −31 listeners.py
+0 −224 pretest_clean.lua
+3 −0 requirements-test.txt
+2 −5 requirements.txt
+119 −30 test-run.py
+19 −0 test/instances/default.lua
+44 −0 test/luatest_helpers.lua
+141 −0 test/luatest_helpers/server.lua
+19 −0 test/test-app/cfg.test.lua
+5 −0 test/test-app/suite.ini
+35 −0 test/test-luatest/smoke_check_test.lua
+3 −0 test/test-luatest/suite.ini
+1 −0 test/test-run.py
+12 −0 test/test-tarantool/box.lua
+592 −0 test/test-tarantool/call.result
+214 −0 test/test-tarantool/call.test.py
+15 −0 test/test-tarantool/engine.cfg
+7 −0 test/test-tarantool/iproto.result
+55 −0 test/test-tarantool/iproto.test.py
+21 −0 test/test-tarantool/replica.lua
+50 −0 test/test-tarantool/set_language.result
+18 −0 test/test-tarantool/set_language.test.sql
+35 −0 test/test-tarantool/setopt_delimeter.result
+22 −0 test/test-tarantool/setopt_delimeter.test.lua
+6 −0 test/test-tarantool/suite.ini
+43 −0 test/test-tarantool/worker_hang_when_gc_triggered_inside_colorer.result
+21 −0 test/test-tarantool/worker_hang_when_gc_triggered_inside_colorer.test.lua
+5 −0 test/test-unit/broken_unicode.result
+15 −0 test/test-unit/broken_unicode.test
+4 −0 test/test-unit/suite.ini
+ test/unittest/00000000000000000003.snap
+32 −0 test/unittest/test_lib_utils.py
+159 −17 test_run.lua
10 changes: 6 additions & 4 deletions test/binary/binary-boundary.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions test/binary/binary-expire.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion test/binary/binary-gh-73.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions test/binary/binary-toobig.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions test/binary/binary.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion test/capable/capable-binary.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
5 changes: 4 additions & 1 deletion test/capable/capable-text.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
48 changes: 48 additions & 0 deletions test/internal/compat.py
Original file line number Diff line number Diff line change
@@ -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 <bytes>.
"""
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 <str>.
"""
if type(s) != str:
raise ValueError('Internal error: expected {}, got {}: {}'.format(
str(str), str(type(s)), repr(s)))

def bytes_to_str(b):
""" Convert <bytes> to <str>.

No-op on Python 2.
"""
assert_bytes(b)
if PY2:
return b
return b.decode('utf-8')

def str_to_bytes(s):
""" Convert <str> to <bytes>.

No-op on Python 2.
"""
assert_str(s)
if PY2:
return s
return s.encode('utf-8')
32 changes: 20 additions & 12 deletions test/internal/memcached_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 = []

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions test/sasl/binary-sasl.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
Loading