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