Skip to content

Commit

Permalink
test: type confusion in ValueError in config parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
pajod committed Apr 26, 2024
1 parent f6bb775 commit 3b198bb
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ def test_bool_validation():
assert c.preload_app is False
pytest.raises(ValueError, c.set, "preload_app", "zilch")
pytest.raises(TypeError, c.set, "preload_app", 4)
pytest.raises(TypeError, c.set, "preload_app", [])
pytest.raises(TypeError, c.set, "preload_app", lambda x: True)
pytest.raises(TypeError, c.set, "preload_app", tuple())


def test_pos_int_validation():
Expand Down Expand Up @@ -159,6 +162,17 @@ def test_str_to_list_validation():
pytest.raises(TypeError, c.set, "forwarded_allow_ips", 1)


def test_dict_validation():
c = config.Config()
c.set("secure_scheme_headers", {"X-FORWARDED_PROTO": "ssl"})
assert c.secure_scheme_headers
pytest.raises(TypeError, c.set, "secure_scheme_headers", set())
pytest.raises(TypeError, c.set, "secure_scheme_headers", lambda x: True)
pytest.raises(TypeError, c.set, "secure_scheme_headers", [])
pytest.raises(TypeError, c.set, "secure_scheme_headers", tuple())
pytest.raises(TypeError, c.set, "secure_scheme_headers", (1,2,3))


def test_callable_validation():
c = config.Config()
def func(a, b):
Expand All @@ -167,6 +181,9 @@ def func(a, b):
assert c.pre_fork == func
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", [])
pytest.raises(TypeError, c.set, "pre_fork", tuple())
pytest.raises(TypeError, c.set, "pre_fork", (1,2,3))


def test_reload_engine_validation():
Expand All @@ -178,6 +195,10 @@ def test_reload_engine_validation():
assert c.reload_engine == 'poll'

pytest.raises(ConfigError, c.set, "reload_engine", "invalid")
pytest.raises(ConfigError, c.set, "reload_engine", tuple())
pytest.raises(ConfigError, c.set, "reload_engine", (1,2,3))
pytest.raises(ConfigError, c.set, "reload_engine", [])
pytest.raises(ConfigError, c.set, "reload_engine", 0)


def test_callable_validation_for_string():
Expand Down

0 comments on commit 3b198bb

Please sign in to comment.