mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
add empty line after some tests.
This commit is contained in:
parent
e007601f0d
commit
e9a00b75c5
@ -13,6 +13,7 @@ from gunicorn.http.parser import RequestParser
|
|||||||
from gunicorn.config import Config
|
from gunicorn.config import Config
|
||||||
from gunicorn.six import BytesIO
|
from gunicorn.six import BytesIO
|
||||||
|
|
||||||
|
|
||||||
def data_source(fname):
|
def data_source(fname):
|
||||||
buf = BytesIO()
|
buf = BytesIO()
|
||||||
with open(fname) as handle:
|
with open(fname) as handle:
|
||||||
@ -21,6 +22,7 @@ def data_source(fname):
|
|||||||
buf.write(line.encode('latin1'))
|
buf.write(line.encode('latin1'))
|
||||||
return buf
|
return buf
|
||||||
|
|
||||||
|
|
||||||
class request(object):
|
class request(object):
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.fname = os.path.join(dirname, "requests", name)
|
self.fname = os.path.join(dirname, "requests", name)
|
||||||
|
|||||||
@ -24,6 +24,7 @@ def cfg_file():
|
|||||||
def paster_ini():
|
def paster_ini():
|
||||||
return os.path.join(dirname, "..", "examples", "frameworks", "pylonstest", "nose.ini")
|
return os.path.join(dirname, "..", "examples", "frameworks", "pylonstest", "nose.ini")
|
||||||
|
|
||||||
|
|
||||||
class AltArgs(object):
|
class AltArgs(object):
|
||||||
def __init__(self, args=None):
|
def __init__(self, args=None):
|
||||||
self.args = args or []
|
self.args = args or []
|
||||||
@ -35,6 +36,7 @@ class AltArgs(object):
|
|||||||
def __exit__(self, exc_type, exc_inst, traceback):
|
def __exit__(self, exc_type, exc_inst, traceback):
|
||||||
sys.argv = self.orig
|
sys.argv = self.orig
|
||||||
|
|
||||||
|
|
||||||
class NoConfigApp(Application):
|
class NoConfigApp(Application):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(NoConfigApp, self).__init__("no_usage", prog="gunicorn_test")
|
super(NoConfigApp, self).__init__("no_usage", prog="gunicorn_test")
|
||||||
@ -51,6 +53,7 @@ def test_defaults():
|
|||||||
for s in config.KNOWN_SETTINGS:
|
for s in config.KNOWN_SETTINGS:
|
||||||
assert c.settings[s.name].validator(s.default) == c.settings[s.name].get()
|
assert c.settings[s.name].validator(s.default) == c.settings[s.name].get()
|
||||||
|
|
||||||
|
|
||||||
def test_property_access():
|
def test_property_access():
|
||||||
c = config.Config()
|
c = config.Config()
|
||||||
for s in config.KNOWN_SETTINGS:
|
for s in config.KNOWN_SETTINGS:
|
||||||
@ -92,6 +95,7 @@ def test_property_access():
|
|||||||
# No setting for name
|
# No setting for name
|
||||||
pytest.raises(AttributeError, c.set, "baz", "bar")
|
pytest.raises(AttributeError, c.set, "baz", "bar")
|
||||||
|
|
||||||
|
|
||||||
def test_bool_validation():
|
def test_bool_validation():
|
||||||
c = config.Config()
|
c = config.Config()
|
||||||
assert c.preload_app is False
|
assert c.preload_app is False
|
||||||
@ -104,6 +108,7 @@ def test_bool_validation():
|
|||||||
pytest.raises(ValueError, c.set, "preload_app", "zilch")
|
pytest.raises(ValueError, c.set, "preload_app", "zilch")
|
||||||
pytest.raises(TypeError, c.set, "preload_app", 4)
|
pytest.raises(TypeError, c.set, "preload_app", 4)
|
||||||
|
|
||||||
|
|
||||||
def test_pos_int_validation():
|
def test_pos_int_validation():
|
||||||
c = config.Config()
|
c = config.Config()
|
||||||
assert c.workers == 1
|
assert c.workers == 1
|
||||||
@ -118,6 +123,7 @@ def test_pos_int_validation():
|
|||||||
pytest.raises(ValueError, c.set, "workers", -21)
|
pytest.raises(ValueError, c.set, "workers", -21)
|
||||||
pytest.raises(TypeError, c.set, "workers", c)
|
pytest.raises(TypeError, c.set, "workers", c)
|
||||||
|
|
||||||
|
|
||||||
def test_str_validation():
|
def test_str_validation():
|
||||||
c = config.Config()
|
c = config.Config()
|
||||||
assert c.proc_name == "gunicorn"
|
assert c.proc_name == "gunicorn"
|
||||||
@ -125,6 +131,7 @@ def test_str_validation():
|
|||||||
assert c.proc_name == "foo"
|
assert c.proc_name == "foo"
|
||||||
pytest.raises(TypeError, c.set, "proc_name", 2)
|
pytest.raises(TypeError, c.set, "proc_name", 2)
|
||||||
|
|
||||||
|
|
||||||
def test_str_to_list_validation():
|
def test_str_to_list_validation():
|
||||||
c = config.Config()
|
c = config.Config()
|
||||||
assert c.forwarded_allow_ips == ["127.0.0.1"]
|
assert c.forwarded_allow_ips == ["127.0.0.1"]
|
||||||
@ -136,6 +143,7 @@ def test_str_to_list_validation():
|
|||||||
assert c.forwarded_allow_ips == []
|
assert c.forwarded_allow_ips == []
|
||||||
pytest.raises(TypeError, c.set, "forwarded_allow_ips", 1)
|
pytest.raises(TypeError, c.set, "forwarded_allow_ips", 1)
|
||||||
|
|
||||||
|
|
||||||
def test_callable_validation():
|
def test_callable_validation():
|
||||||
c = config.Config()
|
c = config.Config()
|
||||||
def func(a, b):
|
def func(a, b):
|
||||||
@ -145,6 +153,7 @@ def test_callable_validation():
|
|||||||
pytest.raises(TypeError, c.set, "pre_fork", 1)
|
pytest.raises(TypeError, c.set, "pre_fork", 1)
|
||||||
pytest.raises(TypeError, c.set, "pre_fork", lambda x: True)
|
pytest.raises(TypeError, c.set, "pre_fork", lambda x: True)
|
||||||
|
|
||||||
|
|
||||||
def test_callable_validation_for_string():
|
def test_callable_validation_for_string():
|
||||||
from os.path import isdir as testfunc
|
from os.path import isdir as testfunc
|
||||||
assert config.validate_callable(-1)("os.path.isdir") == testfunc
|
assert config.validate_callable(-1)("os.path.isdir") == testfunc
|
||||||
@ -183,12 +192,14 @@ def test_cmd_line_invalid_setting(capsys):
|
|||||||
_, err = capsys.readouterr()
|
_, err = capsys.readouterr()
|
||||||
assert "error: unrecognized arguments: -q" in err
|
assert "error: unrecognized arguments: -q" in err
|
||||||
|
|
||||||
|
|
||||||
def test_app_config():
|
def test_app_config():
|
||||||
with AltArgs():
|
with AltArgs():
|
||||||
app = NoConfigApp()
|
app = NoConfigApp()
|
||||||
for s in config.KNOWN_SETTINGS:
|
for s in config.KNOWN_SETTINGS:
|
||||||
assert app.cfg.settings[s.name].validator(s.default) == app.cfg.settings[s.name].get()
|
assert app.cfg.settings[s.name].validator(s.default) == app.cfg.settings[s.name].get()
|
||||||
|
|
||||||
|
|
||||||
def test_load_config():
|
def test_load_config():
|
||||||
with AltArgs(["prog_name", "-c", cfg_file()]):
|
with AltArgs(["prog_name", "-c", cfg_file()]):
|
||||||
app = NoConfigApp()
|
app = NoConfigApp()
|
||||||
@ -196,6 +207,7 @@ def test_load_config():
|
|||||||
assert app.cfg.workers == 3
|
assert app.cfg.workers == 3
|
||||||
assert app.cfg.proc_name == "fooey"
|
assert app.cfg.proc_name == "fooey"
|
||||||
|
|
||||||
|
|
||||||
def test_load_config_explicit_file():
|
def test_load_config_explicit_file():
|
||||||
with AltArgs(["prog_name", "-c", "file:%s" % cfg_file()]):
|
with AltArgs(["prog_name", "-c", "file:%s" % cfg_file()]):
|
||||||
app = NoConfigApp()
|
app = NoConfigApp()
|
||||||
@ -203,6 +215,7 @@ def test_load_config_explicit_file():
|
|||||||
assert app.cfg.workers == 3
|
assert app.cfg.workers == 3
|
||||||
assert app.cfg.proc_name == "fooey"
|
assert app.cfg.proc_name == "fooey"
|
||||||
|
|
||||||
|
|
||||||
def test_load_config_module():
|
def test_load_config_module():
|
||||||
with AltArgs(["prog_name", "-c", "python:%s" % cfg_module()]):
|
with AltArgs(["prog_name", "-c", "python:%s" % cfg_module()]):
|
||||||
app = NoConfigApp()
|
app = NoConfigApp()
|
||||||
@ -210,18 +223,21 @@ def test_load_config_module():
|
|||||||
assert app.cfg.workers == 3
|
assert app.cfg.workers == 3
|
||||||
assert app.cfg.proc_name == "fooey"
|
assert app.cfg.proc_name == "fooey"
|
||||||
|
|
||||||
|
|
||||||
def test_cli_overrides_config():
|
def test_cli_overrides_config():
|
||||||
with AltArgs(["prog_name", "-c", cfg_file(), "-b", "blarney"]):
|
with AltArgs(["prog_name", "-c", cfg_file(), "-b", "blarney"]):
|
||||||
app = NoConfigApp()
|
app = NoConfigApp()
|
||||||
assert app.cfg.bind == ["blarney"]
|
assert app.cfg.bind == ["blarney"]
|
||||||
assert app.cfg.proc_name == "fooey"
|
assert app.cfg.proc_name == "fooey"
|
||||||
|
|
||||||
|
|
||||||
def test_cli_overrides_config_module():
|
def test_cli_overrides_config_module():
|
||||||
with AltArgs(["prog_name", "-c", "python:%s" % cfg_module(), "-b", "blarney"]):
|
with AltArgs(["prog_name", "-c", "python:%s" % cfg_module(), "-b", "blarney"]):
|
||||||
app = NoConfigApp()
|
app = NoConfigApp()
|
||||||
assert app.cfg.bind == ["blarney"]
|
assert app.cfg.bind == ["blarney"]
|
||||||
assert app.cfg.proc_name == "fooey"
|
assert app.cfg.proc_name == "fooey"
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def create_config_file(request):
|
def create_config_file(request):
|
||||||
default_config = os.path.join(os.path.abspath(os.getcwd()),
|
default_config = os.path.join(os.path.abspath(os.getcwd()),
|
||||||
@ -235,6 +251,7 @@ def create_config_file(request):
|
|||||||
|
|
||||||
return default
|
return default
|
||||||
|
|
||||||
|
|
||||||
def test_default_config_file(create_config_file):
|
def test_default_config_file(create_config_file):
|
||||||
assert config.get_default_config_file() == create_config_file.name
|
assert config.get_default_config_file() == create_config_file.name
|
||||||
|
|
||||||
@ -242,6 +259,7 @@ def test_default_config_file(create_config_file):
|
|||||||
app = NoConfigApp()
|
app = NoConfigApp()
|
||||||
assert app.cfg.bind == ["0.0.0.0:9090"]
|
assert app.cfg.bind == ["0.0.0.0:9090"]
|
||||||
|
|
||||||
|
|
||||||
def test_post_request():
|
def test_post_request():
|
||||||
c = config.Config()
|
c = config.Config()
|
||||||
|
|
||||||
|
|||||||
@ -62,6 +62,7 @@ def test_statsd_fail():
|
|||||||
logger.warning("No impact on logging")
|
logger.warning("No impact on logging")
|
||||||
logger.exception("No impact on logging")
|
logger.exception("No impact on logging")
|
||||||
|
|
||||||
|
|
||||||
def test_instrument():
|
def test_instrument():
|
||||||
logger = Statsd(Config())
|
logger = Statsd(Config())
|
||||||
# Capture logged messages
|
# Capture logged messages
|
||||||
@ -96,6 +97,7 @@ def test_instrument():
|
|||||||
assert logger.sock.msgs[1] == b"gunicorn.requests:1|c|@1.0"
|
assert logger.sock.msgs[1] == b"gunicorn.requests:1|c|@1.0"
|
||||||
assert logger.sock.msgs[2] == b"gunicorn.request.status.200:1|c|@1.0"
|
assert logger.sock.msgs[2] == b"gunicorn.request.status.200:1|c|@1.0"
|
||||||
|
|
||||||
|
|
||||||
def test_prefix():
|
def test_prefix():
|
||||||
c = Config()
|
c = Config()
|
||||||
c.set("statsd_prefix", "test.")
|
c.set("statsd_prefix", "test.")
|
||||||
@ -105,6 +107,7 @@ def test_prefix():
|
|||||||
logger.info("Blah", extra={"mtype": "gauge", "metric": "gunicorn.test", "value": 666})
|
logger.info("Blah", extra={"mtype": "gauge", "metric": "gunicorn.test", "value": 666})
|
||||||
assert logger.sock.msgs[0] == b"test.gunicorn.test:666|g"
|
assert logger.sock.msgs[0] == b"test.gunicorn.test:666|g"
|
||||||
|
|
||||||
|
|
||||||
def test_prefix_no_dot():
|
def test_prefix_no_dot():
|
||||||
c = Config()
|
c = Config()
|
||||||
c.set("statsd_prefix", "test")
|
c.set("statsd_prefix", "test")
|
||||||
@ -114,6 +117,7 @@ def test_prefix_no_dot():
|
|||||||
logger.info("Blah", extra={"mtype": "gauge", "metric": "gunicorn.test", "value": 666})
|
logger.info("Blah", extra={"mtype": "gauge", "metric": "gunicorn.test", "value": 666})
|
||||||
assert logger.sock.msgs[0] == b"test.gunicorn.test:666|g"
|
assert logger.sock.msgs[0] == b"test.gunicorn.test:666|g"
|
||||||
|
|
||||||
|
|
||||||
def test_prefix_multiple_dots():
|
def test_prefix_multiple_dots():
|
||||||
c = Config()
|
c = Config()
|
||||||
c.set("statsd_prefix", "test...")
|
c.set("statsd_prefix", "test...")
|
||||||
@ -123,6 +127,7 @@ def test_prefix_multiple_dots():
|
|||||||
logger.info("Blah", extra={"mtype": "gauge", "metric": "gunicorn.test", "value": 666})
|
logger.info("Blah", extra={"mtype": "gauge", "metric": "gunicorn.test", "value": 666})
|
||||||
assert logger.sock.msgs[0] == b"test.gunicorn.test:666|g"
|
assert logger.sock.msgs[0] == b"test.gunicorn.test:666|g"
|
||||||
|
|
||||||
|
|
||||||
def test_prefix_nested():
|
def test_prefix_nested():
|
||||||
c = Config()
|
c = Config()
|
||||||
c.set("statsd_prefix", "test.asdf.")
|
c.set("statsd_prefix", "test.asdf.")
|
||||||
|
|||||||
@ -18,6 +18,7 @@ from gunicorn import six
|
|||||||
dirname = os.path.dirname(__file__)
|
dirname = os.path.dirname(__file__)
|
||||||
random.seed()
|
random.seed()
|
||||||
|
|
||||||
|
|
||||||
def uri(data):
|
def uri(data):
|
||||||
ret = {"raw": data}
|
ret = {"raw": data}
|
||||||
parts = urlparse(data)
|
parts = urlparse(data)
|
||||||
@ -37,6 +38,7 @@ def uri(data):
|
|||||||
ret["fragment"] = parts.fragment or ''
|
ret["fragment"] = parts.fragment or ''
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def load_py(fname):
|
def load_py(fname):
|
||||||
config = globals().copy()
|
config = globals().copy()
|
||||||
config["uri"] = uri
|
config["uri"] = uri
|
||||||
@ -44,6 +46,7 @@ def load_py(fname):
|
|||||||
execfile_(fname, config)
|
execfile_(fname, config)
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
class request(object):
|
class request(object):
|
||||||
def __init__(self, fname, expect):
|
def __init__(self, fname, expect):
|
||||||
self.fname = fname
|
self.fname = fname
|
||||||
@ -266,6 +269,7 @@ class request(object):
|
|||||||
matcher(req, exp["body"], sizer)
|
matcher(req, exp["body"], sizer)
|
||||||
assert req.trailers == exp.get("trailers", [])
|
assert req.trailers == exp.get("trailers", [])
|
||||||
|
|
||||||
|
|
||||||
class badrequest(object):
|
class badrequest(object):
|
||||||
def __init__(self, fname):
|
def __init__(self, fname):
|
||||||
self.fname = fname
|
self.fname = fname
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user