Skip to content

Commit

Permalink
test: support both Python 2 & 3 in the test runner
Browse files Browse the repository at this point in the history
Python 2 going to its real EOL and it is often easier to get Python 3 on
a certain system rather than Python 2.

The test runner layer, which is written in Python is quite thin, so it
worth re-write it to support both Python 2 and Python 3.
  • Loading branch information
Totktonada committed Mar 28, 2020
1 parent 54c7da5 commit 9bc7fa5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/tarantool_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ def execute_no_reconnect(self, command):
if not command:
return
cmd = command.replace('\n', ' ') + '\n'
self.socket.sendall(cmd)
self.socket.sendall(cmd.encode())

bufsiz = 4096
res = ""
res = b""

while True:
buf = self.socket.recv(bufsiz)
if not buf:
break
res = res + buf
if (res.rfind("\n...\n") >= 0 or res.rfind("\r\n...\r\n") >= 0):
if (res.rfind(b"\n...\n") >= 0 or res.rfind(b"\r\n...\r\n") >= 0):
break

return yaml.safe_load(res)
Expand Down Expand Up @@ -245,7 +245,7 @@ def start(self):
self.generate_configuration()
if self.script:
shutil.copy(self.script, self.script_dst)
os.chmod(self.script_dst, 0777)
os.chmod(self.script_dst, 0o777)
args = self.prepare_args()
self.process = subprocess.Popen(args,
cwd = self.vardir,
Expand Down
8 changes: 4 additions & 4 deletions test-run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python

import os
import sys
Expand All @@ -15,7 +15,7 @@
def read_popen(cmd):
path = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
path.wait()
return path.stdout.read()
return path.stdout.read().decode()

def read_popen_config(cmd):
cmd = os.environ.get('PHP_CONFIG', 'php-config') + ' ' + cmd
Expand Down Expand Up @@ -111,9 +111,9 @@ def main():
cmd = cmd + 'sudo dtruss ' + find_php_bin()
cmd = cmd + ' -c tarantool.ini {0}'.format(test_lib_path)
else:
print find_php_bin()
print(find_php_bin())
cmd = '{0} -c tarantool.ini {1}'.format(find_php_bin(), test_lib_path)
print cmd
print(cmd)

print('Running "%s" with "%s"' % (cmd, php_ini))
proc = subprocess.Popen(cmd, shell=True, cwd=test_cwd)
Expand Down

0 comments on commit 9bc7fa5

Please sign in to comment.