Skip to content

Commit c8c2ed2

Browse files
authored
Merge pull request #471 from fredthomsen/RefactorH2ConfigTests
Update H2Configuration test to use init params
2 parents a9b611a + 5b5141f commit c8c2ed2

File tree

1 file changed

+55
-10
lines changed

1 file changed

+55
-10
lines changed

test/test_config.py

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,87 @@ def test_defaults(self):
3131

3232
@pytest.mark.parametrize('option_name', boolean_config_options)
3333
@pytest.mark.parametrize('value', [None, 'False', 1])
34-
def test_boolean_config_options_reject_non_bools(self, option_name, value):
34+
def test_boolean_config_options_reject_non_bools_init(
35+
self, option_name, value
36+
):
3537
"""
3638
The boolean config options raise an error if you try to set a value
37-
that isn't a boolean.
39+
that isn't a boolean via the initializer.
3840
"""
39-
config = h2.config.H2Configuration()
41+
with pytest.raises(ValueError):
42+
h2.config.H2Configuration(**{option_name: value})
4043

44+
@pytest.mark.parametrize('option_name', boolean_config_options)
45+
@pytest.mark.parametrize('value', [None, 'False', 1])
46+
def test_boolean_config_options_reject_non_bools_attr(
47+
self, option_name, value
48+
):
49+
"""
50+
The boolean config options raise an error if you try to set a value
51+
that isn't a boolean via attribute setter.
52+
"""
53+
config = h2.config.H2Configuration()
4154
with pytest.raises(ValueError):
4255
setattr(config, option_name, value)
4356

4457
@pytest.mark.parametrize('option_name', boolean_config_options)
4558
@pytest.mark.parametrize('value', [True, False])
46-
def test_boolean_config_option_is_reflected(self, option_name, value):
59+
def test_boolean_config_option_is_reflected_init(self, option_name, value):
4760
"""
4861
The value of the boolean config options, when set, is reflected
49-
in the value.
62+
in the value via the initializer.
63+
"""
64+
config = h2.config.H2Configuration(**{option_name: value})
65+
assert getattr(config, option_name) == value
66+
67+
@pytest.mark.parametrize('option_name', boolean_config_options)
68+
@pytest.mark.parametrize('value', [True, False])
69+
def test_boolean_config_option_is_reflected_attr(self, option_name, value):
70+
"""
71+
The value of the boolean config options, when set, is reflected
72+
in the value via attribute setter.
5073
"""
5174
config = h2.config.H2Configuration()
5275
setattr(config, option_name, value)
5376
assert getattr(config, option_name) == value
5477

5578
@pytest.mark.parametrize('header_encoding', [True, 1, object()])
56-
def test_header_encoding_must_be_false_str_none(self, header_encoding):
79+
def test_header_encoding_must_be_false_str_none_init(
80+
self, header_encoding
81+
):
5782
"""
5883
The value of the ``header_encoding`` setting must be False, a string,
59-
or None.
84+
or None via the initializer.
6085
"""
61-
config = h2.config.H2Configuration()
86+
with pytest.raises(ValueError):
87+
h2.config.H2Configuration(header_encoding=header_encoding)
6288

89+
@pytest.mark.parametrize('header_encoding', [True, 1, object()])
90+
def test_header_encoding_must_be_false_str_none_attr(
91+
self, header_encoding
92+
):
93+
"""
94+
The value of the ``header_encoding`` setting must be False, a string,
95+
or None via attribute setter.
96+
"""
97+
config = h2.config.H2Configuration()
6398
with pytest.raises(ValueError):
6499
config.header_encoding = header_encoding
65100

66101
@pytest.mark.parametrize('header_encoding', [False, 'ascii', None])
67-
def test_header_encoding_is_reflected(self, header_encoding):
102+
def test_header_encoding_is_reflected_init(self, header_encoding):
103+
"""
104+
The value of ``header_encoding``, when set, is reflected in the value
105+
via the initializer.
106+
"""
107+
config = h2.config.H2Configuration(header_encoding=header_encoding)
108+
assert config.header_encoding == header_encoding
109+
110+
@pytest.mark.parametrize('header_encoding', [False, 'ascii', None])
111+
def test_header_encoding_is_reflected_attr(self, header_encoding):
68112
"""
69-
The value of ``header_encoding``, when set, is reflected in the value.
113+
The value of ``header_encoding``, when set, is reflected in the value
114+
via the attribute setter.
70115
"""
71116
config = h2.config.H2Configuration()
72117
config.header_encoding = header_encoding

0 commit comments

Comments
 (0)