Skip to content

Commit 1dff7aa

Browse files
committed
fix bugbear liniting issues
1 parent 5ed1cf4 commit 1dff7aa

8 files changed

+24
-11
lines changed

src/wtforms/widgets/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def html_params(**kwargs):
7979
elif v is False:
8080
pass
8181
else:
82-
params.append(f'{str(k)}="{escape(v)}"')
82+
params.append(f'{str(k)}="{escape(v)}"') # noqa: B907
8383
return " ".join(params)
8484

8585

tests/test_csrf.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ class Meta:
9999
def test_various_failures(self):
100100
with pytest.raises(TypeError):
101101
self.F()
102-
with pytest.raises(Exception):
102+
with pytest.raises(Exception) as e:
103103
self.F(meta={"csrf_secret": None})
104+
(msg,) = e.value.args
105+
assert msg == "must set `csrf_secret` on class Meta for SessionCSRF to work"
104106

105107
def test_no_time_limit(self):
106108
session = {}

tests/validators/test_anyof.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ def formatter(values):
3737
dummy_field.data = 4
3838
with pytest.raises(ValidationError) as e:
3939
validator(dummy_form, dummy_field)
40-
assert str(e.value) == "test 9::8::7"
40+
(msg,) = e.value.args
41+
assert msg == "test 9::8::7"

tests/validators/test_data_required.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ def test_data_required_clobber(dummy_form, dummy_field):
3333
dummy_field.data = ""
3434
dummy_field.errors = ["Invalid Integer Value"]
3535
assert len(dummy_field.errors) == 1
36-
with pytest.raises(StopValidation):
36+
with pytest.raises(StopValidation) as e:
3737
validator(dummy_form, dummy_field)
38-
assert len(dummy_field.errors) == 0
38+
assert len(dummy_field.errors) == 0
39+
(msg,) = e.value.args
40+
assert msg == "This field is required."
3941

4042

4143
@pytest.mark.parametrize(
@@ -53,7 +55,8 @@ def test_data_required_messages(dummy_form, dummy_field, validator, message):
5355

5456
with pytest.raises(StopValidation) as e:
5557
validator(dummy_form, dummy_field)
56-
assert str(e.value) == message
58+
(msg,) = e.value.args
59+
assert msg == message
5760

5861

5962
def test_required_passes(dummy_form, dummy_field):

tests/validators/test_input_required.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ def test_input_required_error_message(dummy_form, dummy_field, validator, messag
4343

4444
with pytest.raises(StopValidation) as e:
4545
validator(dummy_form, dummy_field)
46-
assert str(e.value) == message
46+
(msg,) = e.value.args
47+
assert msg == message

tests/validators/test_lazy_proxy.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ def test_lazy_proxy_raises(really_lazy_proxy):
1414
"""
1515
Tests that the validators support lazy translation strings for messages.
1616
"""
17-
with pytest.raises(Exception):
17+
with pytest.raises(Exception) as e:
1818
str(really_lazy_proxy)
19+
(msg,) = e.value.args
20+
assert msg == (
21+
"Translator function called during form declaration: "
22+
"it should be called at response time."
23+
)
1924

2025

2126
def test_lazy_proxy_fixture(really_lazy_proxy):

tests/validators/test_length.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,5 @@ def test_length_messages(dummy_form, dummy_field, validator, message):
5555

5656
with pytest.raises(ValidationError) as e:
5757
validator(dummy_form, dummy_field)
58-
assert str(e.value) == message
58+
(msg,) = e.value.args
59+
assert message in msg

tests/validators/test_optional.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ def test_input_optional_raises(data_v, raw_data_v, dummy_form, dummy_field):
2727

2828
with pytest.raises(StopValidation):
2929
validator(dummy_form, dummy_field)
30-
assert validator.field_flags == {"optional": True}
30+
assert validator.field_flags == {"optional": True}
3131

3232
dummy_field.errors = ["Invalid Integer Value"]
3333
assert len(dummy_field.errors) == 1
3434

3535
with pytest.raises(StopValidation):
3636
validator(dummy_form, dummy_field)
37-
assert len(dummy_field.errors) == 0
37+
assert len(dummy_field.errors) == 0

0 commit comments

Comments
 (0)