From 079041fc1eb6d284382f39bd307ad8fba81b487e Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 12 May 2021 09:20:49 -0400 Subject: [PATCH] Port to Python 3. --- integration/test_web.py | 21 +++++++++++++++------ src/allmydata/util/_python3.py | 4 +--- tox.ini | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/integration/test_web.py b/integration/test_web.py index 8fac6909d..22f08da82 100644 --- a/integration/test_web.py +++ b/integration/test_web.py @@ -7,9 +7,18 @@ Most of the tests have cursory asserts and encode 'what the WebAPI did at the time of testing' -- not necessarily a cohesive idea of what the WebAPI *should* do in every situation. It's not clear the latter exists anywhere, however. + +Ported to Python 3. """ -from past.builtins import unicode +from __future__ import unicode_literals +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +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 time from urllib.parse import unquote as url_unquote, quote as url_quote @@ -66,7 +75,7 @@ def test_upload_download(alice): u"filename": u"boom", } ) - assert unicode(data, "utf-8") == FILE_CONTENTS + assert str(data, "utf-8") == FILE_CONTENTS def test_put(alice): @@ -97,7 +106,7 @@ def test_helper_status(storage_nodes): resp = requests.get(url) assert resp.status_code >= 200 and resp.status_code < 300 dom = BeautifulSoup(resp.content, "html5lib") - assert unicode(dom.h1.string) == u"Helper Status" + assert str(dom.h1.string) == u"Helper Status" def test_deep_stats(alice): @@ -202,7 +211,7 @@ def test_status(alice): ) print("Downloaded {} bytes of data".format(len(resp.content))) - assert unicode(resp.content, "ascii") == FILE_CONTENTS + assert str(resp.content, "ascii") == FILE_CONTENTS resp = requests.get( util.node_url(alice.node_dir, "status"), @@ -400,9 +409,9 @@ def test_directory_deep_check(alice): for _ in range(5): resp = requests.get(deepcheck_uri) dom = BeautifulSoup(resp.content, "html5lib") - if dom.h1 and u'Results' in unicode(dom.h1.string): + if dom.h1 and u'Results' in str(dom.h1.string): break - if dom.h2 and dom.h2.a and u"Reload" in unicode(dom.h2.a.string): + if dom.h2 and dom.h2.a and u"Reload" in str(dom.h2.a.string): dom = None time.sleep(1) assert dom is not None, "Operation never completed" diff --git a/src/allmydata/util/_python3.py b/src/allmydata/util/_python3.py index 2bde5941e..c15301c3c 100644 --- a/src/allmydata/util/_python3.py +++ b/src/allmydata/util/_python3.py @@ -17,15 +17,13 @@ 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 -# Every time a module is added here, also add it to tox.ini environment -# integrations3. Bit of duplication, but it's only a handful of files and quite -# temporary, just until we've ported them all. PORTED_INTEGRATION_TESTS = [ "integration.test_aaa_aardvark", "integration.test_servers_of_happiness", "integration.test_sftp", "integration.test_streaming_logs", "integration.test_tor", + "integration.test_web", ] diff --git a/tox.ini b/tox.ini index 04eae7833..365c5d0e9 100644 --- a/tox.ini +++ b/tox.ini @@ -102,7 +102,7 @@ setenv = COVERAGE_PROCESS_START=.coveragerc commands = # NOTE: 'run with "py.test --keep-tempdir -s -v integration/" to debug failures' - python3 -b -m pytest --timeout=1800 --coverage -v {posargs:integration/test_aaa_aardvark.py integration/test_servers_of_happiness.py integration/test_sftp.py integration/test_streaming_logs.py integration/test_tor.py} + python3 -b -m pytest --timeout=1800 --coverage -v {posargs:integration} coverage combine coverage report