Tests: Python 3 compatibility

The tests use '#!/usr/bin/env python' which may be Python 3.  Adjust the
tests to work under either Python 2 or Python 3.

This introduces a use of b"" string literals, which are supported by
Python 2.7 and Python 3, but not by Python 2.6.

Also, document the required minimum Python version.
This commit is contained in:
Daniel Shahaf 2015-07-07 14:40:30 +00:00 committed by Renato Alves
parent 27b8cabac1
commit 808524507e
2 changed files with 14 additions and 3 deletions

View file

@ -5,6 +5,7 @@ How to Build Taskwarrior
will be utilizing C++11.
- libuuid
- gnutls (optional)
- python 2.7 or 3 (optional, for running the test suite)
Obtain and build code:
$ git clone https://git.tasktools.org/scm/tm/task.git task.git

View file

@ -9,10 +9,16 @@ import argparse
import logging
import time
from multiprocessing import cpu_count
from Queue import Queue, Empty
from threading import Thread
from subprocess import call, Popen, PIPE
try:
# python 2
from Queue import Queue, Empty
except ImportError:
# python 3
from queue import Queue, Empty
# Look for taskd in $PATH instead of task/src/
os.environ["TASKD_USE_PATH"] = "1"
@ -38,6 +44,9 @@ def run_test(testqueue, outqueue, threadname):
# Premature end
break
if sys.version_info > (3,):
out, err = out.decode('utf-8'), err.decode('utf-8')
output = ("# {0}\n".format(os.path.basename(test)), out, err)
log.debug("Collected output %s", output)
outqueue.put(output)
@ -62,8 +71,8 @@ class TestRunner(object):
if os.access(test, os.X_OK):
# Executables only
if not cmd_args.serial:
with open(test) as fh:
if "/usr/bin/env python" in fh.readline():
with open(test, 'rb') as fh:
if b"/usr/bin/env python" in fh.read(50):
log.debug("Treating as parallel: %s", test)
self._parallelq.put(test)
else:
@ -166,6 +175,7 @@ def parse_args():
parser.add_argument('--verbose', '-v', action="store_true",
help="Also send TAP output to stdout")
parser.add_argument('--logging', '-l', action="count",
default=0,
help="Logging level. -lll is the highest level")
parser.add_argument('--serial', action="store_true",
help="Do not run tests in parallel")