All tests pass on Python 3.

This commit is contained in:
Itamar Turner-Trauring 2020-10-16 11:20:10 -04:00
parent 51d472e221
commit f7a89f76e7
2 changed files with 12 additions and 6 deletions

View File

@ -1,3 +1,4 @@
from future.utils import PY2
from past.builtins import unicode from past.builtins import unicode
import base64 import base64
@ -153,8 +154,12 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
f.close() f.close()
config = read_config(basedir, "") config = read_config(basedir, "")
self.failUnlessEqual(config.get_config("node", "nickname").decode('utf-8'), # Config returns native strings:
u"\u2621") expected_nick = u"\u2621"
if PY2:
expected_nick = expected_nick.encode("utf-8")
self.failUnlessEqual(config.get_config("node", "nickname"),
expected_nick)
def test_tahoe_cfg_hash_in_name(self): def test_tahoe_cfg_hash_in_name(self):
basedir = "test_node/test_cfg_hash_in_name" basedir = "test_node/test_cfg_hash_in_name"

View File

@ -10,7 +10,7 @@ from __future__ import division
from __future__ import print_function from __future__ import print_function
from __future__ import unicode_literals from __future__ import unicode_literals
from future.utils import PY2 from future.utils import PY2, PY3
if PY2: if PY2:
# We don't do open(), because we want files to read/write native strs when # We don't do open(), because we want files to read/write native strs when
# we do "r" or "w". # we do "r" or "w".
@ -42,11 +42,12 @@ def get_config(tahoe_cfg):
""" """
config = SafeConfigParser() config = SafeConfigParser()
with open(tahoe_cfg, "r") as f: with open(tahoe_cfg, "r") as f:
# On Python 2, where we read in bytes, skip any initial Byte Order # Skip any initial Byte Order Mark. Since this is an ordinary file, we
# Mark. Since this is an ordinary file, we don't need to handle # don't need to handle incomplete reads, and can assume seekability.
# incomplete reads, and can assume seekability.
if PY2 and f.read(3) != b'\xEF\xBB\xBF': if PY2 and f.read(3) != b'\xEF\xBB\xBF':
f.seek(0) f.seek(0)
if PY3 and f.read(1) != u"\uFEFF":
f.seek(0)
config.readfp(f) config.readfp(f)
return config return config