diff --git a/tools/serve/serve.py b/tools/serve/serve.py index c4afc691d34d70..d920b841138172 100644 --- a/tools/serve/serve.py +++ b/tools/serve/serve.py @@ -16,6 +16,7 @@ from six.moves import urllib import uuid from collections import defaultdict, OrderedDict +from itertools import chain, product from multiprocessing import Process, Event from localpaths import repo_root @@ -720,6 +721,9 @@ def build_config(override_path=None, **kwargs): return rv +def _make_subdomains_product(s, depth=2): + return set(u".".join(x) for x in chain(*(product(s, repeat=i) for i in range(1, depth+1)))) + _subdomains = {u"www", u"www1", u"www2", @@ -728,6 +732,10 @@ def build_config(override_path=None, **kwargs): _not_subdomains = {u"nonexistent"} +_subdomains = _make_subdomains_product(_subdomains) + +_not_subdomains = _make_subdomains_product(_not_subdomains) + class ConfigBuilder(config.ConfigBuilder): """serve config diff --git a/tools/serve/test_serve.py b/tools/serve/test_serve.py index 1c089b506738ee..62a6e74f980427 100644 --- a/tools/serve/test_serve.py +++ b/tools/serve/test_serve.py @@ -1,6 +1,7 @@ +import json +import os import pickle import platform -import os import pytest @@ -75,3 +76,11 @@ def test_pickle(): # Ensure that the config object can be pickled with ConfigBuilder() as c: pickle.dumps(c) + + +def test_config_json_length(): + # we serialize the config as JSON for pytestrunner and put it in an env + # variable, which on Windows must have a length <= 0x7FFF (int16) + with ConfigBuilder() as c: + data = json.dumps(c.as_dict()) + assert len(data) <= 0x7FFF diff --git a/tools/wptserve/tests/test_config.py b/tools/wptserve/tests/test_config.py index 2ee8287710e91e..45f138f131d3bc 100644 --- a/tools/wptserve/tests/test_config.py +++ b/tools/wptserve/tests/test_config.py @@ -1,3 +1,4 @@ +import json import logging import pickle @@ -43,6 +44,16 @@ def test_logger_preserved(): assert c.logger is logger +def test_as_dict(): + with config.ConfigBuilder() as c: + assert c.as_dict() is not None + + +def test_as_dict_is_json(): + with config.ConfigBuilder() as c: + assert json.dumps(c.as_dict()) is not None + + def test_init_basic_prop(): with config.ConfigBuilder(browser_host="foo.bar") as c: assert c.browser_host == "foo.bar" diff --git a/tools/wptserve/wptserve/config.py b/tools/wptserve/wptserve/config.py index cb5435fdef4c20..29c3d16b38e9a5 100644 --- a/tools/wptserve/wptserve/config.py +++ b/tools/wptserve/wptserve/config.py @@ -75,7 +75,9 @@ def json_types(obj): return {key: json_types(value) for key, value in iteritems(obj)} if (isinstance(obj, string_types) or isinstance(obj, integer_types) or - isinstance(obj, float)): + isinstance(obj, float) or + isinstance(obj, bool) or + obj is None): return obj if isinstance(obj, list) or hasattr(obj, "__iter__"): return [json_types(value) for value in obj]