Skip to content

Commit 5b5141f

Browse files
committed
Split H2Config initializer and setter tests
Split H2Configuration tests into initializer and attribute setter tests.
1 parent c1047cc commit 5b5141f

File tree

1 file changed

+51
-17
lines changed

1 file changed

+51
-17
lines changed

test/test_config.py

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,54 +31,88 @@ 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
"""
3941
with pytest.raises(ValueError):
40-
config = h2.config.H2Configuration(**{option_name: value})
42+
h2.config.H2Configuration(**{option_name: value})
4143

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+
"""
4253
config = h2.config.H2Configuration()
4354
with pytest.raises(ValueError):
4455
setattr(config, option_name, value)
4556

4657
@pytest.mark.parametrize('option_name', boolean_config_options)
4758
@pytest.mark.parametrize('value', [True, False])
48-
def test_boolean_config_option_is_reflected(self, option_name, value):
59+
def test_boolean_config_option_is_reflected_init(self, option_name, value):
4960
"""
5061
The value of the boolean config options, when set, is reflected
51-
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.
5273
"""
5374
config = h2.config.H2Configuration()
5475
setattr(config, option_name, value)
5576
assert getattr(config, option_name) == value
5677

57-
config = h2.config.H2Configuration(**{option_name: value})
58-
assert getattr(config, option_name) == value
78+
@pytest.mark.parametrize('header_encoding', [True, 1, object()])
79+
def test_header_encoding_must_be_false_str_none_init(
80+
self, header_encoding
81+
):
82+
"""
83+
The value of the ``header_encoding`` setting must be False, a string,
84+
or None via the initializer.
85+
"""
86+
with pytest.raises(ValueError):
87+
h2.config.H2Configuration(header_encoding=header_encoding)
5988

6089
@pytest.mark.parametrize('header_encoding', [True, 1, object()])
61-
def test_header_encoding_must_be_false_str_none(self, header_encoding):
90+
def test_header_encoding_must_be_false_str_none_attr(
91+
self, header_encoding
92+
):
6293
"""
6394
The value of the ``header_encoding`` setting must be False, a string,
64-
or None.
95+
or None via attribute setter.
6596
"""
6697
config = h2.config.H2Configuration()
67-
6898
with pytest.raises(ValueError):
6999
config.header_encoding = header_encoding
70100

71-
with pytest.raises(ValueError):
72-
config = h2.config.H2Configuration(header_encoding=header_encoding)
101+
@pytest.mark.parametrize('header_encoding', [False, 'ascii', None])
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
73109

74110
@pytest.mark.parametrize('header_encoding', [False, 'ascii', None])
75-
def test_header_encoding_is_reflected(self, header_encoding):
111+
def test_header_encoding_is_reflected_attr(self, header_encoding):
76112
"""
77-
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.
78115
"""
79116
config = h2.config.H2Configuration()
80117
config.header_encoding = header_encoding
81118
assert config.header_encoding == header_encoding
82-
83-
config = h2.config.H2Configuration(header_encoding=header_encoding)
84-
assert config.header_encoding == header_encoding

0 commit comments

Comments
 (0)