Try to fix some failing unit tests in ASCII locale.

This commit is contained in:
Itamar Turner-Trauring 2020-10-27 08:54:28 -04:00
parent dce8d3598a
commit c76afc9ece
3 changed files with 13 additions and 16 deletions

View File

@ -10,17 +10,12 @@ import os.path
import re import re
import types import types
import errno import errno
from io import StringIO
import tempfile import tempfile
from base64 import b32decode, b32encode from base64 import b32decode, b32encode
# On Python 2 this will be the backported package. # On Python 2 this will be the backported package.
import configparser import configparser
from future.utils import PY2
if PY2:
from io import BytesIO as StringIO # noqa: F811
from twisted.python import log as twlog from twisted.python import log as twlog
from twisted.application import service from twisted.application import service
from twisted.python.failure import Failure from twisted.python.failure import Failure
@ -213,7 +208,9 @@ def config_from_string(basedir, portnumfile, config_str, _valid_config=None):
# load configuration from in-memory string # load configuration from in-memory string
parser = configparser.SafeConfigParser() parser = configparser.SafeConfigParser()
parser.readfp(StringIO(config_str)) if isinstance(config_str, bytes):
config_str = config_str.decode("utf-8")
parser.read_string(config_str)
fname = "<in-memory>" fname = "<in-memory>"
configutil.validate_config(fname, parser, _valid_config) configutil.validate_config(fname, parser, _valid_config)

View File

@ -168,7 +168,11 @@ class Tor(unittest.TestCase):
tor_provider = create_tor_provider(reactor, config) tor_provider = create_tor_provider(reactor, config)
tor_provider.get_tor_handler() tor_provider.get_tor_handler()
self.assertIn( self.assertIn(
"invalid literal for int() with base 10: 'kumquat'", "invalid literal for int()",
str(ctx.exception)
)
self.assertIn(
"kumquat",
str(ctx.exception) str(ctx.exception)
) )

View File

@ -35,15 +35,11 @@ def get_config(tahoe_cfg):
Configuration is returned as native strings. Configuration is returned as native strings.
""" """
config = SafeConfigParser(strict=False) config = SafeConfigParser(strict=False)
with open(tahoe_cfg, "r") as f: # Byte Order Mark is an optional garbage byte you sometimes get at the
# Who put the BOM in the BOM SHOO BOP SHOO BOP. # start of UTF-8 encoded files. Especially on Windows. Skip it by using
# # utf-8-sig. https://en.wikipedia.org/wiki/Byte_order_mark
# Byte Order Mark is an optional garbage byte you sometimes get at the with open(tahoe_cfg, "r", encoding="utf-8-sig") as f:
# start of UTF-8 encoded files. Especially on Windows. Skip it. config.read_file(f)
# https://en.wikipedia.org/wiki/Byte_order_mark
if f.read(1) != u'\uFEFF':
f.seek(0)
config.readfp(f)
return config return config
def set_config(config, section, option, value): def set_config(config, section, option, value):