1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
|
From: Gordon Ball <gordon@chronitis.net>
Date: Thu, 14 May 2020 10:17:07 +0000
Subject: Port testsuite to python3
---
src/libshared/test/json_test.t | 6 +--
test/basetest/CMakeLists.txt | 1 -
test/basetest/compat.py | 7 ----
test/basetest/hooks.py | 7 +---
test/basetest/meta.py | 3 --
test/basetest/task.py | 4 +-
test/basetest/utils.py | 87 +++---------------------------------------
test/encoding.test.py | 2 +-
test/export.test.py | 2 +-
9 files changed, 12 insertions(+), 107 deletions(-)
delete mode 100644 test/basetest/compat.py
diff --git a/src/libshared/test/json_test.t b/src/libshared/test/json_test.t
index bcfb5b8..2563534 100755
--- a/src/libshared/test/json_test.t
+++ b/src/libshared/test/json_test.t
@@ -64,15 +64,13 @@ class MetaTestJson(MetaTest):
return test
-class TestJsonParsing(TestCase):
- __metaclass__ = MetaTestJson
-
+class TestJsonParsing(TestCase, metaclass=MetaTestJson):
EXTRA = {}
EXTRA["TEST_DIR"] = os.path.abspath(os.path.join(CURRENT_DIR, ".."))
EXTRA["TEST_BIN"] = os.path.join(EXTRA["TEST_DIR"], "json_test")
TESTS = (
- zip(glob(os.path.join(EXTRA["TEST_DIR"], "json/*.json")))
+ list(zip(glob(os.path.join(EXTRA["TEST_DIR"], "json/*.json"))))
)
diff --git a/test/basetest/CMakeLists.txt b/test/basetest/CMakeLists.txt
index 67daf11..5fd0a49 100644
--- a/test/basetest/CMakeLists.txt
+++ b/test/basetest/CMakeLists.txt
@@ -1,5 +1,4 @@
configure_file(__init__.py __init__.py COPYONLY)
-configure_file(compat.py compat.py COPYONLY)
configure_file(exceptions.py exceptions.py COPYONLY)
configure_file(hooks.py hooks.py COPYONLY)
configure_file(meta.py meta.py COPYONLY)
diff --git a/test/basetest/compat.py b/test/basetest/compat.py
deleted file mode 100644
index 33696e8..0000000
--- a/test/basetest/compat.py
+++ /dev/null
@@ -1,7 +0,0 @@
-try:
- STRING_TYPE = basestring
-except NameError:
- # Python 3
- STRING_TYPE = str
-
-# vim: ai sts=4 et sw=4
diff --git a/test/basetest/hooks.py b/test/basetest/hooks.py
index 9332dc7..79bc7c5 100644
--- a/test/basetest/hooks.py
+++ b/test/basetest/hooks.py
@@ -1,14 +1,9 @@
-from __future__ import division
import errno
import os
from sys import stderr
import shutil
import stat
-
-try:
- import simplejson as json
-except ImportError:
- import json
+import json
from datetime import datetime
from .utils import DEFAULT_HOOK_PATH
diff --git a/test/basetest/meta.py b/test/basetest/meta.py
index f5b30a5..6127179 100644
--- a/test/basetest/meta.py
+++ b/test/basetest/meta.py
@@ -1,6 +1,3 @@
-from __future__ import print_function, division
-
-
class MetaTest(type):
"""Helper metaclass to simplify dynamic test creation
diff --git a/test/basetest/task.py b/test/basetest/task.py
index 6e51b71..860b15f 100644
--- a/test/basetest/task.py
+++ b/test/basetest/task.py
@@ -15,8 +15,6 @@ from .utils import (
task_binary_location,
CMAKE_BINARY_DIR,
)
-from .compat import STRING_TYPE
-
class Task(object):
"""Manage a task warrior instance
@@ -147,7 +145,7 @@ class Task(object):
argument. The string is literally the same as if written in the shell.
"""
# Enable nicer-looking calls by allowing plain strings
- if isinstance(args, STRING_TYPE):
+ if isinstance(args, str):
args = shlex.split(args)
return args
diff --git a/test/basetest/utils.py b/test/basetest/utils.py
index d2ba9aa..3a83bd1 100644
--- a/test/basetest/utils.py
+++ b/test/basetest/utils.py
@@ -1,4 +1,3 @@
-from __future__ import division
import errno
import os
import sys
@@ -10,16 +9,9 @@ import tempfile
from subprocess import Popen, PIPE, STDOUT
from threading import Thread
-try:
- from Queue import Queue, Empty
-except ImportError:
- from queue import Queue, Empty
+from queue import Queue, Empty
from time import sleep
-
-try:
- import simplejson as json
-except ImportError:
- import json
+import json
from .exceptions import CommandError, TimeoutWaitingFor
USED_PORTS = set()
@@ -76,7 +68,7 @@ def wait_condition(cond, timeout=10, sleeptime=0.01):
timeout = 10
if timeout < sleeptime:
- print("Warning, timeout cannot be smaller than", sleeptime)
+ print(("Warning, timeout cannot be smaller than", sleeptime))
timeout = sleeptime
# Max number of attempts until giving up
@@ -143,8 +135,7 @@ def _queue_output(arguments, pidq, outputq):
# Send input and wait for finish
out, err = proc.communicate(input_data)
- 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')
# Give the output back to the caller
outputq.put((out, err, proc.returncode))
@@ -290,74 +281,8 @@ def memoize(obj):
return memoizer
-try:
- from shutil import which
-
- which = memoize(which)
-except ImportError:
- # NOTE: This is shutil.which backported from python-3.3.3
- @memoize
- def which(cmd, mode=os.F_OK | os.X_OK, path=None):
- """Given a command, mode, and a PATH string, return the path which
- conforms to the given mode on the PATH, or None if there is no such
- file.
-
- `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
- of os.environ.get("PATH"), or can be overridden with a custom search
- path.
-
- """
-
- # Check that a given file can be accessed with the correct mode.
- # Additionally check that `file` is not a directory, as on Windows
- # directories pass the os.access check.
- def _access_check(fn, mode):
- return os.path.exists(fn) and os.access(fn, mode) and not os.path.isdir(fn)
-
- # If we're given a path with a directory part, look it up directly
- # rather than referring to PATH directories. This includes checking
- # relative to the current directory, e.g. ./script
- if os.path.dirname(cmd):
- if _access_check(cmd, mode):
- return cmd
- return None
-
- if path is None:
- path = os.environ.get("PATH", os.defpath)
- if not path:
- return None
- path = path.split(os.pathsep)
-
- if sys.platform == "win32":
- # The current directory takes precedence on Windows.
- if os.curdir not in path:
- path.insert(0, os.curdir)
-
- # PATHEXT is necessary to check on Windows.
- pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
- # See if the given file matches any of the expected path
- # extensions. This will allow us to short circuit when given
- # "python.exe". If it does match, only test that one, otherwise we
- # have to try others.
- if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
- files = [cmd]
- else:
- files = [cmd + ext for ext in pathext]
- else:
- # On other platforms you don't have things like PATHEXT to tell you
- # what file suffixes are executable, so just pass on cmd as-is.
- files = [cmd]
-
- seen = set()
- for dir in path:
- normdir = os.path.normcase(dir)
- if normdir not in seen:
- seen.add(normdir)
- for thefile in files:
- name = os.path.join(dir, thefile)
- if _access_check(name, mode):
- return name
- return None
+from shutil import which
+which = memoize(which)
def parse_datafile(file):
diff --git a/test/encoding.test.py b/test/encoding.test.py
index 13b4973..d47c0d5 100755
--- a/test/encoding.test.py
+++ b/test/encoding.test.py
@@ -65,7 +65,7 @@ class TestUtf8(TestCase):
# contains wide utf8 characters
self.t.config("print.empty.columns", "0")
- self.t(("add", "abc", "pro:Bar\u263a"))
+ self.t(("add", "abc", "pro:Bar\\u263a"))
self.t("add def pro:Foo")
code, out, err = self.t("ls")
diff --git a/test/export.test.py b/test/export.test.py
index 777bcf2..3206a59 100755
--- a/test/export.test.py
+++ b/test/export.test.py
@@ -37,7 +37,7 @@ sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from basetest import Task, TestCase
from basetest.utils import UUID_REGEXP
-from basetest.compat import STRING_TYPE
+STRING_TYPE = str
DATETIME_FORMAT = "%Y%m%dT%H%M%SZ"
|