mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Switch to python 3
- #259 Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
This commit is contained in:
parent
f7a3e26d8e
commit
ddf713a722
1 changed files with 26 additions and 36 deletions
62
test/run_all
62
test/run_all
|
@ -1,26 +1,18 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
from __future__ import print_function
|
import argparse
|
||||||
|
import codecs
|
||||||
|
import glob
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import glob
|
|
||||||
import argparse
|
|
||||||
import logging
|
|
||||||
import time
|
import time
|
||||||
|
from builtins import object
|
||||||
|
from builtins import range
|
||||||
from multiprocessing import cpu_count
|
from multiprocessing import cpu_count
|
||||||
from threading import Thread
|
from queue import Queue, Empty
|
||||||
from subprocess import call, Popen, PIPE
|
from subprocess import call, Popen, PIPE
|
||||||
|
from threading import Thread
|
||||||
if sys.version_info > (3,):
|
|
||||||
import codecs
|
|
||||||
|
|
||||||
try:
|
|
||||||
# python 2
|
|
||||||
from Queue import Queue, Empty
|
|
||||||
except ImportError:
|
|
||||||
# python 3
|
|
||||||
from queue import Queue, Empty
|
|
||||||
|
|
||||||
TIMEOUT = .2
|
TIMEOUT = .2
|
||||||
|
|
||||||
|
@ -36,16 +28,14 @@ def run_test(testqueue, outqueue, threadname):
|
||||||
log.info("Running test %s", test)
|
log.info("Running test %s", test)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
p = Popen(os.path.abspath(test), stdout=PIPE, stderr=PIPE,
|
p = Popen(os.path.abspath(test), stdout=PIPE, stderr=PIPE, env=os.environ)
|
||||||
env=os.environ)
|
|
||||||
out, err = p.communicate()
|
out, err = p.communicate()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
# Premature end
|
# Premature end
|
||||||
break
|
break
|
||||||
|
|
||||||
if sys.version_info > (3,):
|
out, err = out.decode('utf-8'), err.decode('utf-8')
|
||||||
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)
|
||||||
|
@ -60,10 +50,7 @@ def run_test(testqueue, outqueue, threadname):
|
||||||
class TestRunner(object):
|
class TestRunner(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.threads = []
|
self.threads = []
|
||||||
if sys.version_info > (3,):
|
self.tap = open(cmd_args.tapfile, 'w', errors='ignore')
|
||||||
self.tap = open(cmd_args.tapfile, 'w', errors='ignore')
|
|
||||||
else:
|
|
||||||
self.tap = open(cmd_args.tapfile, 'w')
|
|
||||||
|
|
||||||
self._parallelq = Queue()
|
self._parallelq = Queue()
|
||||||
self._serialq = Queue()
|
self._serialq = Queue()
|
||||||
|
@ -118,13 +105,13 @@ class TestRunner(object):
|
||||||
if cmd_args.serial:
|
if cmd_args.serial:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# This is a pretty weird way to do it, and not realiable.
|
# This is a pretty weird way to do it, and not reliable.
|
||||||
# We are dealing with some binary tests though.
|
# We are dealing with some binary tests though.
|
||||||
with open(test, 'rb') as fh:
|
with open(test, 'rb') as fh:
|
||||||
header = fh.read(100).split(b"\n")
|
header = fh.read(100).split(b"\n")
|
||||||
if len(header) >= 2 and \
|
if len(header) >= 2 and \
|
||||||
((b"/usr/bin/env python" in header[0]) or \
|
((b"/usr/bin/env python" in header[0]) or
|
||||||
(header[1][-14:] == b"bash_tap_tw.sh")):
|
(header[1][-14:] == b"bash_tap_tw.sh")):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
@ -187,21 +174,26 @@ class TestRunner(object):
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(description="Run Taskwarrior tests")
|
parser = argparse.ArgumentParser(description="Run Taskwarrior tests")
|
||||||
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,
|
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")
|
||||||
parser.add_argument('--tapfile', default="all.log",
|
parser.add_argument('--tapfile',
|
||||||
|
default="all.log",
|
||||||
help="File to use for TAP output")
|
help="File to use for TAP output")
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if sys.version_info > (3,):
|
sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
|
||||||
sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
|
|
||||||
|
|
||||||
runner = TestRunner()
|
runner = TestRunner()
|
||||||
runner.start()
|
runner.start()
|
||||||
|
@ -235,5 +227,3 @@ if __name__ == "__main__":
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# vim: ai sts=4 et sw=4
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue