Skip to content

Commit 4cc280e

Browse files
test(test_cmd): minor refactoring tests (#1833)
1 parent 7c8af2d commit 4cc280e

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

tests/test_cmd.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55

66

77
# https://docs.python.org/3/howto/unicode.html
8-
def test_valid_utf8_encoded_strings():
9-
valid_strings = (
8+
@pytest.mark.parametrize(
9+
"s",
10+
[
1011
"",
1112
"ascii",
1213
"🤦🏻‍♂️",
1314
"﷽",
1415
"\u0000",
15-
)
16-
assert all(s == cmd._try_decode(s.encode("utf-8")) for s in valid_strings)
16+
],
17+
)
18+
def test_valid_utf8_encoded_strings(s: str):
19+
assert s == cmd._try_decode(s.encode("utf-8"))
1720

1821

1922
# A word of caution: just because an encoding can be guessed for a given
@@ -22,24 +25,25 @@ def test_valid_utf8_encoded_strings():
2225
# https://docs.python.org/3/library/codecs.html#standard-encodings
2326

2427

25-
# Pick a random, non-utf8 encoding to test.
26-
def test_valid_cp1250_encoded_strings():
27-
valid_strings = (
28+
@pytest.mark.parametrize(
29+
"s",
30+
[
2831
"",
2932
"ascii",
3033
"äöüß",
3134
"ça va",
3235
"jak se máte",
33-
)
34-
for s in valid_strings:
35-
assert cmd._try_decode(s.encode("cp1250")) or True
36+
],
37+
)
38+
def test_valid_cp1250_encoded_strings(s: str):
39+
"""Pick a random, non-utf8 encoding to test."""
40+
# We just want to make sure it doesn't raise an exception
41+
cmd._try_decode(s.encode("cp1250"))
3642

3743

3844
def test_invalid_bytes():
39-
invalid_bytes = (b"\x73\xe2\x9d\xff\x00",)
40-
for s in invalid_bytes:
41-
with pytest.raises(CharacterSetDecodeError):
42-
cmd._try_decode(s)
45+
with pytest.raises(CharacterSetDecodeError):
46+
cmd._try_decode(b"\x73\xe2\x9d\xff\x00")
4347

4448

4549
def test_always_fail_decode():

0 commit comments

Comments
 (0)