mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-20 05:28:04 +00:00
Merge pull request #1037 from tahoe-lafs/3671.more-test-utilities-python-3
Port even more test utilities to Python 3 Fixes ticket:3671
This commit is contained in:
commit
8b4e92e1d7
0
newsfragments/3671.minor
Normal file
0
newsfragments/3671.minor
Normal file
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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: <class 'future.types.newstr.newstr'> 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__ = [
|
||||
|
@ -1 +0,0 @@
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -100,14 +100,18 @@ 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",
|
||||
"allmydata.test.matchers",
|
||||
"allmydata.test.mutable",
|
||||
"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",
|
||||
"allmydata.testing",
|
||||
"allmydata.testing.web",
|
||||
|
Loading…
Reference in New Issue
Block a user