Bug 1471666 [wpt PR 11692] - Support python 3 in wptserve.config.Config., a=testonly

Automatic update from web-platform-testsSupport python 3 in wptserve.config.Config. (#11692)

--

wpt-commits: 97043862742e95f9ef12f15a0abc93d4bcc369b0
wpt-pr: 11692
This commit is contained in:
Ms2ger 2018-07-06 23:24:22 +00:00 коммит произвёл James Graham
Родитель 00b9e6b5f8
Коммит 2229f3871f
3 изменённых файлов: 25 добавлений и 69 удалений

Просмотреть файл

@ -57,13 +57,11 @@ def test_make_hosts_file_windows():
assert lines[-1] == ""
@pytest.mark.xfail(sys.version_info >= (3,), reason="serve only works on Py2")
def test_ws_doc_root_default():
c = Config()
assert c.ws_doc_root == os.path.join(localpaths.repo_root, "websockets", "handlers")
@pytest.mark.xfail(sys.version_info >= (3,), reason="serve only works on Py2")
def test_init_ws_doc_root():
c = Config(ws_doc_root="/")
assert c.doc_root == localpaths.repo_root # check this hasn't changed
@ -71,7 +69,6 @@ def test_init_ws_doc_root():
assert c.ws_doc_root == "/"
@pytest.mark.xfail(sys.version_info >= (3,), reason="serve only works on Py2")
def test_set_ws_doc_root():
c = Config()
c.ws_doc_root = "/"
@ -80,7 +77,6 @@ def test_set_ws_doc_root():
assert c.ws_doc_root == "/"
@pytest.mark.xfail(sys.version_info >= (3,), reason="serve only works on Py2")
def test_pickle():
# Ensure that the config object can be pickled
pickle.dumps(Config())

Просмотреть файл

@ -1,6 +1,5 @@
import logging
import pickle
import sys
from logging import handlers
import pytest
@ -8,14 +7,12 @@ import pytest
config = pytest.importorskip("wptserve.config")
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_renamed_are_renamed():
assert len(set(config._renamed_props.viewkeys()) & set(config.Config._default.viewkeys())) == 0
assert len(set(config._renamed_props.keys()) & set(config.Config._default.keys())) == 0
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_renamed_exist():
assert set(config._renamed_props.viewvalues()).issubset(set(config.Config._default.viewkeys()))
assert set(config._renamed_props.values()).issubset(set(config.Config._default.keys()))
@pytest.mark.parametrize("base, override, expected", [
@ -27,18 +24,15 @@ def test_renamed_exist():
pytest.param({"a": {"b": 1}}, {"a": 2}, {"a": 1}, marks=pytest.mark.xfail),
pytest.param({"a": 1}, {"a": {"b": 2}}, {"a": 1}, marks=pytest.mark.xfail),
])
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_merge_dict(base, override, expected):
assert expected == config._merge_dict(base, override)
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_logger_created():
c = config.Config()
assert c.logger is not None
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_logger_preserved():
logger = logging.getLogger("test_logger_preserved")
logger.setLevel(logging.DEBUG)
@ -47,19 +41,16 @@ def test_logger_preserved():
assert c.logger is logger
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_init_basic_prop():
c = config.Config(browser_host="foo.bar")
assert c.browser_host == "foo.bar"
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_init_prefixed_prop():
c = config.Config(doc_root="/")
assert c._doc_root == "/"
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_init_renamed_host():
logger = logging.getLogger("test_init_renamed_host")
logger.setLevel(logging.DEBUG)
@ -74,28 +65,25 @@ def test_init_renamed_host():
assert c.browser_host == "foo.bar"
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_init_bogus():
with pytest.raises(TypeError) as e:
config.Config(foo=1, bar=2)
assert "foo" in e.value.message
assert "bar" in e.value.message
message = e.value.args[0]
assert "foo" in message
assert "bar" in message
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_getitem():
c = config.Config(browser_host="foo.bar")
assert c["browser_host"] == "foo.bar"
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_no_setitem():
c = config.Config()
with pytest.raises(TypeError):
c["browser_host"] = "foo.bar"
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_iter():
c = config.Config()
s = set(iter(c))
@ -105,28 +93,24 @@ def test_iter():
assert "_browser_host" not in s
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_assignment():
c = config.Config()
c.browser_host = "foo.bar"
assert c.browser_host == "foo.bar"
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_update_basic():
c = config.Config()
c.update({"browser_host": "foo.bar"})
assert c.browser_host == "foo.bar"
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_update_prefixed():
c = config.Config()
c.update({"doc_root": "/"})
assert c._doc_root == "/"
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_update_renamed_host():
logger = logging.getLogger("test_update_renamed_host")
logger.setLevel(logging.DEBUG)
@ -145,14 +129,12 @@ def test_update_renamed_host():
assert c.browser_host == "foo.bar"
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_update_bogus():
c = config.Config()
with pytest.raises(KeyError):
c.update({"foobar": 1})
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_ports_auto():
c = config.Config(ports={"http": ["auto"]},
ssl={"type": "none"})
@ -162,7 +144,6 @@ def test_ports_auto():
assert isinstance(ports["http"][0], int)
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_ports_auto_mutate():
c = config.Config(ports={"http": [1001]},
ssl={"type": "none"})
@ -177,7 +158,6 @@ def test_ports_auto_mutate():
assert isinstance(new_ports["http"][0], int)
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_ports_auto_roundtrip():
c = config.Config(ports={"http": ["auto"]},
ssl={"type": "none"})
@ -187,7 +167,6 @@ def test_ports_auto_roundtrip():
assert old_ports == new_ports
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_ports_idempotent():
c = config.Config(ports={"http": ["auto"]},
ssl={"type": "none"})
@ -196,7 +175,6 @@ def test_ports_idempotent():
assert ports_a == ports_b
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_ports_explicit():
c = config.Config(ports={"http": [1001]},
ssl={"type": "none"})
@ -205,7 +183,6 @@ def test_ports_explicit():
assert ports["http"] == [1001]
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_ports_no_ssl():
c = config.Config(ports={"http": [1001], "https": [1002], "ws": [1003], "wss": [1004]},
ssl={"type": "none"})
@ -217,7 +194,6 @@ def test_ports_no_ssl():
assert ports["wss"] == [None]
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_ports_openssl():
c = config.Config(ports={"http": [1001], "https": [1002], "ws": [1003], "wss": [1004]},
ssl={"type": "openssl"})
@ -229,14 +205,12 @@ def test_ports_openssl():
assert ports["wss"] == [1004]
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_init_doc_root():
c = config.Config(doc_root="/")
assert c._doc_root == "/"
assert c.doc_root == "/"
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_set_doc_root():
c = config.Config()
c.doc_root = "/"
@ -244,13 +218,11 @@ def test_set_doc_root():
assert c.doc_root == "/"
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_server_host_from_browser_host():
c = config.Config(browser_host="foo.bar")
assert c.server_host == "foo.bar"
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_init_server_host():
c = config.Config(server_host="foo.bar")
assert c.browser_host == "localhost" # check this hasn't changed
@ -258,7 +230,6 @@ def test_init_server_host():
assert c.server_host == "foo.bar"
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_set_server_host():
c = config.Config()
c.server_host = "/"
@ -267,7 +238,6 @@ def test_set_server_host():
assert c.server_host == "/"
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_domains():
c = config.Config(browser_host="foo.bar",
alternate_hosts={"alt": "foo2.bar"},
@ -288,7 +258,6 @@ def test_domains():
}
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_not_domains():
c = config.Config(browser_host="foo.bar",
alternate_hosts={"alt": "foo2.bar"},
@ -307,7 +276,6 @@ def test_not_domains():
}
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_domains_not_domains_intersection():
c = config.Config(browser_host="foo.bar",
alternate_hosts={"alt": "foo2.bar"},
@ -315,15 +283,14 @@ def test_domains_not_domains_intersection():
not_subdomains={"x", "y"})
domains = c.domains
not_domains = c.not_domains
assert len(set(domains.iterkeys()) ^ set(not_domains.iterkeys())) == 0
for host in domains.iterkeys():
assert len(set(domains.keys()) ^ set(not_domains.keys())) == 0
for host in domains.keys():
host_domains = domains[host]
host_not_domains = not_domains[host]
assert len(set(host_domains.iterkeys()) & set(host_not_domains.iterkeys())) == 0
assert len(set(host_domains.itervalues()) & set(host_not_domains.itervalues())) == 0
assert len(set(host_domains.keys()) & set(host_not_domains.keys())) == 0
assert len(set(host_domains.values()) & set(host_not_domains.values())) == 0
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_all_domains():
c = config.Config(browser_host="foo.bar",
alternate_hosts={"alt": "foo2.bar"},
@ -348,7 +315,6 @@ def test_all_domains():
}
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_domains_set():
c = config.Config(browser_host="foo.bar",
alternate_hosts={"alt": "foo2.bar"},
@ -365,7 +331,6 @@ def test_domains_set():
}
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_not_domains_set():
c = config.Config(browser_host="foo.bar",
alternate_hosts={"alt": "foo2.bar"},
@ -380,7 +345,6 @@ def test_not_domains_set():
}
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_all_domains_set():
c = config.Config(browser_host="foo.bar",
alternate_hosts={"alt": "foo2.bar"},
@ -401,20 +365,17 @@ def test_all_domains_set():
}
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_ssl_env_override():
c = config.Config(override_ssl_env="foobar")
assert c.ssl_env == "foobar"
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_ssl_env_none():
c = config.Config(ssl={"type": "none"})
assert c.ssl_env is not None
assert c.ssl_env.ssl_enabled is False
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_ssl_env_openssl():
c = config.Config(ssl={"type": "openssl", "openssl": {"openssl_binary": "foobar"}})
assert c.ssl_env is not None
@ -422,14 +383,12 @@ def test_ssl_env_openssl():
assert c.ssl_env.binary == "foobar"
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_ssl_env_bogus():
c = config.Config(ssl={"type": "foobar"})
with pytest.raises(ValueError):
c.ssl_env
@pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
def test_pickle():
# Ensure that the config object can be pickled
pickle.dumps(config.Config())

Просмотреть файл

@ -2,8 +2,9 @@ import logging
import os
from collections import defaultdict, Mapping
from six import iteritems, itervalues
from . import sslutils
from .sslutils import environments
from .utils import get_port
@ -17,7 +18,7 @@ _renamed_props = {
def _merge_dict(base_dict, override_dict):
rv = base_dict.copy()
for key, value in base_dict.iteritems():
for key, value in iteritems(base_dict):
if key in override_dict:
if isinstance(value, dict):
rv[key] = _merge_dict(value, override_dict[key])
@ -73,13 +74,13 @@ class Config(Mapping):
self.log_level = level_name
self._logger_name = logger.name
for k, v in self._default.iteritems():
for k, v in iteritems(self._default):
setattr(self, k, kwargs.pop(k, v))
self.subdomains = subdomains
self.not_subdomains = not_subdomains
for k, new_k in _renamed_props.iteritems():
for k, new_k in iteritems(_renamed_props):
if k in kwargs:
self.logger.warning(
"%s in config is deprecated; use %s instead" % (
@ -114,7 +115,7 @@ class Config(Mapping):
if k in override:
self._set_override(k, override.pop(k))
for k, new_k in _renamed_props.iteritems():
for k, new_k in iteritems(_renamed_props):
if k in override:
self.logger.warning(
"%s in config is deprecated; use %s instead" % (
@ -146,7 +147,7 @@ class Config(Mapping):
except AttributeError:
old_ports = {}
for scheme, ports in self._ports.iteritems():
for scheme, ports in iteritems(self._ports):
for i, port in enumerate(ports):
if scheme in ["wss", "https"] and not self.ssl_env.ssl_enabled:
port = None
@ -189,8 +190,8 @@ class Config(Mapping):
hosts[""] = self.browser_host
rv = {}
for name, host in hosts.iteritems():
rv[name] = {subdomain: (subdomain.encode("idna") + u"." + host)
for name, host in iteritems(hosts):
rv[name] = {subdomain: (subdomain.encode("idna").decode("ascii") + u"." + host)
for subdomain in self.subdomains}
rv[name][""] = host
return rv
@ -202,8 +203,8 @@ class Config(Mapping):
hosts[""] = self.browser_host
rv = {}
for name, host in hosts.iteritems():
rv[name] = {subdomain: (subdomain.encode("idna") + u"." + host)
for name, host in iteritems(hosts):
rv[name] = {subdomain: (subdomain.encode("idna").decode("ascii") + u"." + host)
for subdomain in self.not_subdomains}
return rv
@ -218,14 +219,14 @@ class Config(Mapping):
@property
def domains_set(self):
return {domain
for per_host_domains in self.domains.itervalues()
for domain in per_host_domains.itervalues()}
for per_host_domains in itervalues(self.domains)
for domain in itervalues(per_host_domains)}
@property
def not_domains_set(self):
return {domain
for per_host_domains in self.not_domains.itervalues()
for domain in per_host_domains.itervalues()}
for per_host_domains in itervalues(self.not_domains)
for domain in itervalues(per_host_domains)}
@property
def all_domains_set(self):
@ -246,7 +247,7 @@ class Config(Mapping):
implementation_type = self.ssl["type"]
try:
cls = sslutils.environments[implementation_type]
cls = environments[implementation_type]
except KeyError:
raise ValueError("%s is not a vaid ssl type." % implementation_type)
kwargs = self.ssl.get(implementation_type, {}).copy()