Skip to content

Commit 72b4b83

Browse files
committed
Update tests for flake8-pytest-style
1 parent 5aa213f commit 72b4b83

3 files changed

Lines changed: 27 additions & 24 deletions

File tree

pyproject.toml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,33 +65,37 @@ fix = true
6565
lint.select = [
6666
"C4", # flake8-comprehensions
6767
"D", # pydocstyle
68-
"E", # pycodestyle
68+
"E", # pycodestyle errors
6969
"EM", # flake8-errmsg
7070
"F", # pyflakes
7171
"I", # isort
7272
"ICN", # flake8-import-conventions
7373
"ISC", # flake8-implicit-str-concat
7474
"LOG", # flake8-logging
7575
"PGH", # pygrep-hooks
76+
"PIE", # flake8-pie
77+
"PT", # flake8-pytest-style
7678
"PYI", # flake8-pyi
7779
"RUF022", # unsorted-dunder-all
7880
"RUF100", # unused noqa (yesqa)
7981
"UP", # pyupgrade
80-
"W", # pycodestyle
82+
"W", # pycodestyle warnings
8183
"YTT", # flake8-2020
8284
]
8385
lint.ignore = [
84-
"E203", # Whitespace before ':'
85-
"E221", # Multiple spaces before operator
86-
"E226", # Missing whitespace around arithmetic operator
87-
"E241", # Multiple spaces after ','
88-
"UP038", # Makes code slower and more verbose
86+
"E203", # Whitespace before ':'
87+
"E221", # Multiple spaces before operator
88+
"E226", # Missing whitespace around arithmetic operator
89+
"E241", # Multiple spaces after ','
90+
"PIE790", # flake8-pie: unnecessary-placeholder
91+
"UP038", # Makes code slower and more verbose
8992
]
9093
lint.per-file-ignores."tests/*" = [
9194
"D",
9295
]
9396
lint.flake8-import-conventions.aliases.datetime = "dt"
9497
lint.flake8-import-conventions.banned-from = [ "datetime" ]
98+
lint.flake8-pytest-style.parametrize-names-type = "csv"
9599
lint.isort.known-first-party = [ "humanize" ]
96100
lint.isort.required-imports = [ "from __future__ import annotations" ]
97101
lint.pydocstyle.convention = "google"
@@ -103,8 +107,6 @@ max_supported_python = "3.14"
103107
addopts = "--color=yes"
104108
filterwarnings = [
105109
"error",
106-
# https://github.com/dateutil/dateutil/issues/1314
107-
"ignore:datetime.datetime.utcfromtimestamp:DeprecationWarning:dateutil.tz.tz",
108110
]
109111
testpaths = [ "tests" ]
110112

tests/test_i18n.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ def test_naturaldelta() -> None:
8989

9090

9191
@pytest.mark.parametrize(
92-
("locale", "number", "expected_result"),
93-
(
92+
"locale, number, expected_result",
93+
[
9494
("es_ES", 1000000, "1.0 millón"),
9595
("es_ES", 3500000, "3.5 millones"),
9696
("es_ES", 1000000000, "1.0 billón"),
9797
("es_ES", 1200000000, "1.2 billones"),
9898
("es_ES", 1000000000000, "1.0 trillón"),
9999
("es_ES", 6700000000000, "6.7 trillones"),
100-
),
100+
],
101101
)
102102
def test_intword_plurals(locale: str, number: int, expected_result: str) -> None:
103103
try:
@@ -111,16 +111,16 @@ def test_intword_plurals(locale: str, number: int, expected_result: str) -> None
111111

112112

113113
@pytest.mark.parametrize(
114-
("locale", "expected_result"),
115-
(
114+
"locale, expected_result",
115+
[
116116
("ar", "5خامس"),
117117
("ar_SA", "5خامس"),
118118
("fr", "5e"),
119119
("fr_FR", "5e"),
120120
("pt", "5º"),
121121
("pt_BR", "5º"),
122122
("pt_PT", "5º"),
123-
),
123+
],
124124
)
125125
def test_langauge_codes(locale: str, expected_result: str) -> None:
126126
try:
@@ -134,16 +134,16 @@ def test_langauge_codes(locale: str, expected_result: str) -> None:
134134

135135

136136
@pytest.mark.parametrize(
137-
("locale", "number", "gender", "expected_result"),
138-
(
137+
"locale, number, gender, expected_result",
138+
[
139139
("fr_FR", 1, "male", "1er"),
140140
("fr_FR", 1, "female", "1ère"),
141141
("fr_FR", 2, "male", "2e"),
142142
("es_ES", 1, "male", "1º"),
143143
("es_ES", 5, "female", "5ª"),
144144
("it_IT", 3, "male", "3º"),
145145
("it_IT", 8, "female", "8ª"),
146-
),
146+
],
147147
)
148148
def test_ordinal_genders(
149149
locale: str, number: int, gender: str, expected_result: str
@@ -187,19 +187,17 @@ def test_default_locale_path_null__spec__(
187187
i18n = importlib.import_module("humanize.i18n")
188188
monkeypatch.setattr(i18n, "__spec__", None)
189189

190-
with pytest.raises(Exception) as excinfo:
190+
with pytest.raises(Exception, match=self.expected_msg):
191191
i18n.activate("ru_RU")
192-
assert str(excinfo.value) == self.expected_msg
193192

194193
def test_default_locale_path_undefined__spec__(
195194
self, monkeypatch: pytest.MonkeyPatch
196195
) -> None:
197196
i18n = importlib.import_module("humanize.i18n")
198197
monkeypatch.delattr(i18n, "__spec__")
199198

200-
with pytest.raises(Exception) as excinfo:
199+
with pytest.raises(Exception, match=self.expected_msg):
201200
i18n.activate("ru_RU")
202-
assert str(excinfo.value) == self.expected_msg
203201

204202
@freeze_time("2020-02-02")
205203
def test_en_locale(self) -> None:

tests/test_time.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,10 +755,13 @@ def test_precisedelta_suppress_units(
755755
def test_precisedelta_bogus_call() -> None:
756756
assert humanize.precisedelta(None) == "None"
757757

758-
with pytest.raises(ValueError):
758+
with pytest.raises(
759+
ValueError,
760+
match="Minimum unit is suppressed and no suitable replacement was found",
761+
):
759762
humanize.precisedelta(1, minimum_unit="years", suppress=["years"])
760763

761-
with pytest.raises(ValueError):
764+
with pytest.raises(ValueError, match="Minimum unit 'years' not supported"):
762765
humanize.naturaldelta(1, minimum_unit="years")
763766

764767

0 commit comments

Comments
 (0)