mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-26 06:37:20 +02:00
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:
parent
27b8cabac1
commit
808524507e
2 changed files with 14 additions and 3 deletions
|
@ -5,6 +5,7 @@ How to Build Taskwarrior
|
||||||
will be utilizing C++11.
|
will be utilizing C++11.
|
||||||
- libuuid
|
- libuuid
|
||||||
- gnutls (optional)
|
- gnutls (optional)
|
||||||
|
- python 2.7 or 3 (optional, for running the test suite)
|
||||||
|
|
||||||
Obtain and build code:
|
Obtain and build code:
|
||||||
$ git clone https://git.tasktools.org/scm/tm/task.git task.git
|
$ git clone https://git.tasktools.org/scm/tm/task.git task.git
|
||||||
|
|
16
test/run_all
16
test/run_all
|
@ -9,10 +9,16 @@ import argparse
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
from multiprocessing import cpu_count
|
from multiprocessing import cpu_count
|
||||||
from Queue import Queue, Empty
|
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from subprocess import call, Popen, PIPE
|
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/
|
# Look for taskd in $PATH instead of task/src/
|
||||||
os.environ["TASKD_USE_PATH"] = "1"
|
os.environ["TASKD_USE_PATH"] = "1"
|
||||||
|
|
||||||
|
@ -38,6 +44,9 @@ def run_test(testqueue, outqueue, threadname):
|
||||||
# Premature end
|
# Premature end
|
||||||
break
|
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)
|
output = ("# {0}\n".format(os.path.basename(test)), out, err)
|
||||||
log.debug("Collected output %s", output)
|
log.debug("Collected output %s", output)
|
||||||
outqueue.put(output)
|
outqueue.put(output)
|
||||||
|
@ -62,8 +71,8 @@ class TestRunner(object):
|
||||||
if os.access(test, os.X_OK):
|
if os.access(test, os.X_OK):
|
||||||
# Executables only
|
# Executables only
|
||||||
if not cmd_args.serial:
|
if not cmd_args.serial:
|
||||||
with open(test) as fh:
|
with open(test, 'rb') as fh:
|
||||||
if "/usr/bin/env python" in fh.readline():
|
if b"/usr/bin/env python" in fh.read(50):
|
||||||
log.debug("Treating as parallel: %s", test)
|
log.debug("Treating as parallel: %s", test)
|
||||||
self._parallelq.put(test)
|
self._parallelq.put(test)
|
||||||
else:
|
else:
|
||||||
|
@ -166,6 +175,7 @@ def parse_args():
|
||||||
parser.add_argument('--verbose', '-v', action="store_true",
|
parser.add_argument('--verbose', '-v', action="store_true",
|
||||||
help="Also send TAP output to stdout")
|
help="Also send TAP output to stdout")
|
||||||
parser.add_argument('--logging', '-l', action="count",
|
parser.add_argument('--logging', '-l', action="count",
|
||||||
|
default=0,
|
||||||
help="Logging level. -lll is the highest level")
|
help="Logging level. -lll is the highest level")
|
||||||
parser.add_argument('--serial', action="store_true",
|
parser.add_argument('--serial', action="store_true",
|
||||||
help="Do not run tests in parallel")
|
help="Do not run tests in parallel")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue