From 7f4a99306bd08d0459e00fcf2169e0ac3b744199 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 6 Apr 2021 10:04:18 -0400 Subject: [PATCH 1/9] No need to port to Python 3. --- src/allmydata/test/_win_subprocess.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/allmydata/test/_win_subprocess.py b/src/allmydata/test/_win_subprocess.py index fe6960c73..2c2cb60b4 100644 --- a/src/allmydata/test/_win_subprocess.py +++ b/src/allmydata/test/_win_subprocess.py @@ -1,3 +1,13 @@ +""" +This module is only necessary on Python 2. Once Python 2 code is dropped, it +can be deleted. +""" + +from future.utils import PY3 +if PY3: + raise RuntimeError("Just use subprocess.Popen") + + # -*- coding: utf-8 -*- ## Copyright (C) 2021 Valentin Lab From abe3fbc2e52dda4b6dfa31a298602195a09a2d64 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 6 Apr 2021 10:22:30 -0400 Subject: [PATCH 2/9] Empty file. --- src/allmydata/test/status.py | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/allmydata/test/status.py diff --git a/src/allmydata/test/status.py b/src/allmydata/test/status.py deleted file mode 100644 index 8b1378917..000000000 --- a/src/allmydata/test/status.py +++ /dev/null @@ -1 +0,0 @@ - From ae7680759dbff6a86b25c76a22e5e7fd3658caea Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 6 Apr 2021 10:22:47 -0400 Subject: [PATCH 3/9] Another checker script. --- {src/allmydata/test => misc/checkers}/check_grid.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {src/allmydata/test => misc/checkers}/check_grid.py (100%) diff --git a/src/allmydata/test/check_grid.py b/misc/checkers/check_grid.py similarity index 100% rename from src/allmydata/test/check_grid.py rename to misc/checkers/check_grid.py From 044c79c4db9c5b5885cdb675fb39c76aa4bfd650 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 6 Apr 2021 10:29:29 -0400 Subject: [PATCH 4/9] Port to Python 3. --- src/allmydata/test/eliotutil.py | 9 +++++++++ src/allmydata/util/_python3.py | 1 + 2 files changed, 10 insertions(+) diff --git a/src/allmydata/test/eliotutil.py b/src/allmydata/test/eliotutil.py index 63c24f08a..c2359f132 100644 --- a/src/allmydata/test/eliotutil.py +++ b/src/allmydata/test/eliotutil.py @@ -1,12 +1,21 @@ """ Tools aimed at the interaction between tests and Eliot. + +Ported to Python 3. """ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals # Python 2 compatibility # Can't use `builtins.str` because it's not JSON encodable: # `exceptions.TypeError: is not JSON-encodeable` from past.builtins import unicode as str from future.utils import PY2 +if PY2: + from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, max, min # noqa: F401 + from six import ensure_text __all__ = [ diff --git a/src/allmydata/util/_python3.py b/src/allmydata/util/_python3.py index 03eafdea5..d17cbe6d8 100644 --- a/src/allmydata/util/_python3.py +++ b/src/allmydata/util/_python3.py @@ -101,6 +101,7 @@ PORTED_MODULES = [ "allmydata.test.cli_node_api", "allmydata.test.common", "allmydata.test.common_web", + "allmydata.test.eliotutil", "allmydata.test.no_network", "allmydata.test.matchers", "allmydata.test.mutable", From bb84442f4e939189cab1ea7142f5f3fa223f99ba Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 6 Apr 2021 10:29:46 -0400 Subject: [PATCH 5/9] News file. --- newsfragments/3671.minor | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 newsfragments/3671.minor diff --git a/newsfragments/3671.minor b/newsfragments/3671.minor new file mode 100644 index 000000000..e69de29bb From 2257f89d39aa9eeff0bbbfdaebad7d31c7bedfe6 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 6 Apr 2021 10:45:44 -0400 Subject: [PATCH 6/9] More semantically robust test. --- src/allmydata/test/web/test_web.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/allmydata/test/web/test_web.py b/src/allmydata/test/web/test_web.py index 6b25305c6..e73cc12f8 100644 --- a/src/allmydata/test/web/test_web.py +++ b/src/allmydata/test/web/test_web.py @@ -1394,8 +1394,8 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi def _got(res_and_status_and_headers): (res, status, headers) = res_and_status_and_headers self.failUnlessReallyEqual(res, "") - self.failUnlessReallyEqual(headers.getRawHeaders("content-length")[0], - str(len(self.BAR_CONTENTS))) + self.failUnlessReallyEqual(int(headers.getRawHeaders("content-length")[0]), + len(self.BAR_CONTENTS)) self.failUnlessReallyEqual(headers.getRawHeaders("content-type"), ["text/plain"]) d.addCallback(_got) @@ -3015,8 +3015,8 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi def _got_headers(res_and_status_and_headers): (res, status, headers) = res_and_status_and_headers self.failUnlessReallyEqual(res, "") - self.failUnlessReallyEqual(headers.getRawHeaders("content-length")[0], - str(len(NEW2_CONTENTS))) + self.failUnlessReallyEqual(int(headers.getRawHeaders("content-length")[0]), + len(NEW2_CONTENTS)) self.failUnlessReallyEqual(headers.getRawHeaders("content-type"), ["text/plain"]) d.addCallback(_got_headers) From 3429f8bf030b8f2713fcabb13cf49fed8e079279 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 6 Apr 2021 10:45:58 -0400 Subject: [PATCH 7/9] Port to Python 3. --- src/allmydata/test/common_util.py | 21 ++++++++++++++------- src/allmydata/util/_python3.py | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/allmydata/test/common_util.py b/src/allmydata/test/common_util.py index 91f0b0f78..f4cc4a074 100644 --- a/src/allmydata/test/common_util.py +++ b/src/allmydata/test/common_util.py @@ -1,8 +1,15 @@ +""" +Ported to Python 3. +""" from __future__ import print_function +from __future__ import absolute_import +from __future__ import division +from __future__ import unicode_literals from future.utils import PY2, bchr, binary_type from future.builtins import str as future_str -from past.builtins import unicode +if PY2: + from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, dict, list, object, range, str, max, min # noqa: F401 import os import time @@ -24,7 +31,7 @@ from allmydata.util.encodingutil import unicode_platform, get_filesystem_encodin def skip_if_cannot_represent_filename(u): - precondition(isinstance(u, unicode)) + precondition(isinstance(u, str)) enc = get_filesystem_encoding() if not unicode_platform(): @@ -44,7 +51,7 @@ def _getvalue(io): def maybe_unicode_to_argv(o): """Convert object to argv form if necessary.""" - if isinstance(o, unicode): + if isinstance(o, str): return unicode_to_argv(o) return o @@ -181,7 +188,7 @@ class DevNullDictionary(dict): return def insecurerandstr(n): - return b''.join(map(bchr, map(randrange, [0]*n, [256]*n))) + return b''.join(map(bchr, list(map(randrange, [0]*n, [256]*n)))) def flip_bit(good, which): """Flip the low-order bit of good[which].""" @@ -211,9 +218,9 @@ class ReallyEqualMixin(object): # type. They're equal, and _logically_ the same type, but have # different types in practice. if a.__class__ == future_str: - a = unicode(a) + a = str(a) if b.__class__ == future_str: - b = unicode(b) + b = str(b) self.assertEqual(type(a), type(b), "a :: %r (%s), b :: %r (%s), %r" % (a, type(a), b, type(b), msg)) @@ -297,7 +304,7 @@ class ShouldFailMixin(object): of the message wrapped by this Failure, or the test will fail. """ - assert substring is None or isinstance(substring, (bytes, unicode)) + assert substring is None or isinstance(substring, (bytes, str)) d = defer.maybeDeferred(callable, *args, **kwargs) def done(res): if isinstance(res, failure.Failure): diff --git a/src/allmydata/util/_python3.py b/src/allmydata/util/_python3.py index d17cbe6d8..4676f6955 100644 --- a/src/allmydata/util/_python3.py +++ b/src/allmydata/util/_python3.py @@ -100,6 +100,7 @@ PORTED_MODULES = [ "allmydata.test.cli", "allmydata.test.cli_node_api", "allmydata.test.common", + "allmydata.test.common_util", "allmydata.test.common_web", "allmydata.test.eliotutil", "allmydata.test.no_network", From 315bb672d11ca77de93edef9b07d82c4a6bc8405 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 6 Apr 2021 10:49:00 -0400 Subject: [PATCH 8/9] Port to Python 3. --- src/allmydata/test/web/common.py | 11 +++++++++++ src/allmydata/util/_python3.py | 1 + 2 files changed, 12 insertions(+) diff --git a/src/allmydata/test/web/common.py b/src/allmydata/test/web/common.py index 00a40e3c5..43a13a902 100644 --- a/src/allmydata/test/web/common.py +++ b/src/allmydata/test/web/common.py @@ -1,3 +1,14 @@ +""" +Ported to Python 3. +""" +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + +from future.utils import PY2 +if PY2: + from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401 import re diff --git a/src/allmydata/util/_python3.py b/src/allmydata/util/_python3.py index 4676f6955..5d70d1e73 100644 --- a/src/allmydata/util/_python3.py +++ b/src/allmydata/util/_python3.py @@ -110,6 +110,7 @@ PORTED_MODULES = [ "allmydata.test.python3_tests", "allmydata.test.storage_plugin", "allmydata.test.web", + "allmydata.test.web.common", "allmydata.test.web.matchers", "allmydata.testing", "allmydata.testing.web", From ddcca38f3148abb020e0f4d8139dac9bc3e9e966 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 6 Apr 2021 10:51:14 -0400 Subject: [PATCH 9/9] Port to Python 3. --- src/allmydata/test/strategies.py | 10 ++++++++++ src/allmydata/util/_python3.py | 1 + 2 files changed, 11 insertions(+) diff --git a/src/allmydata/test/strategies.py b/src/allmydata/test/strategies.py index 553b2c226..c0f558ef6 100644 --- a/src/allmydata/test/strategies.py +++ b/src/allmydata/test/strategies.py @@ -1,6 +1,16 @@ """ Hypothesis strategies use for testing Tahoe-LAFS. + +Ported to Python 3. """ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + +from future.utils import PY2 +if PY2: + from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401 from hypothesis.strategies import ( one_of, diff --git a/src/allmydata/util/_python3.py b/src/allmydata/util/_python3.py index 5d70d1e73..3f705fe09 100644 --- a/src/allmydata/util/_python3.py +++ b/src/allmydata/util/_python3.py @@ -109,6 +109,7 @@ PORTED_MODULES = [ "allmydata.test.mutable.util", "allmydata.test.python3_tests", "allmydata.test.storage_plugin", + "allmydata.test.strategies", "allmydata.test.web", "allmydata.test.web.common", "allmydata.test.web.matchers",