Skip to content

Commit efe1865

Browse files
authored
Merge pull request #11767 from internetarchive/pytest-v9-strict
updates for pytest v9
2 parents 91ae121 + e2bc0ba commit efe1865

File tree

7 files changed

+50
-56
lines changed

7 files changed

+50
-56
lines changed

openlibrary/catalog/add_book/tests/test_match.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ def test_normalize(title, normalized):
7373

7474

7575
mk_norm_conversions = [
76-
("Hello I'm a title.", "helloi'matitle"),
7776
("Hello I'm a title.", "helloi'matitle"),
7877
('Forgotten Titles: A Novel.', 'forgottentitlesanovel'),
7978
('Kitāb Yatīmat ud-Dahr', 'kitābyatīmatuddahr'),

openlibrary/tests/catalog/test_utils.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -206,20 +206,20 @@ def test_remove_trailing_dot():
206206
@pytest.mark.parametrize(
207207
('year', 'expected'),
208208
[
209-
('1999-01', 1999),
210-
('1999', 1999),
211-
('01-1999', 1999),
212-
('May 5, 1999', 1999),
213-
('May 5, 19999', None),
214-
('1999-01-01', 1999),
215-
('1999/1/1', 1999),
216-
('01-01-1999', 1999),
217-
('1/1/1999', 1999),
218-
('199', None),
219-
('19990101', None),
220-
(None, None),
221-
(1999, 1999),
222-
(19999, None),
209+
pytest.param('1999-01', 1999, id="ISO_month"),
210+
pytest.param('1999', 1999, id="plain_year_str"),
211+
pytest.param('01-1999', 1999, id="US_month_year"),
212+
pytest.param('May 5, 1999', 1999, id="full_date_text"),
213+
pytest.param('May 5, 19999', None, id="out_of_range_year"),
214+
pytest.param('1999-01-01', 1999, id="ISO_full_date"),
215+
pytest.param('1999/1/1', 1999, id="slashed_date"),
216+
pytest.param('01-01-1999', 1999, id="dashed_date_euro_us"),
217+
pytest.param('1/1/1999', 1999, id="shorthand_date"),
218+
pytest.param('199', None, id="too_short_year"),
219+
pytest.param('19990101', None, id="unformatted_string"),
220+
pytest.param(None, None, id="null_input"),
221+
pytest.param(1999, 1999, id="integer_input"),
222+
pytest.param(19999, None, id="integer_out_of_range"),
223223
],
224224
)
225225
def test_publication_year(year, expected) -> None:

openlibrary/tests/fastapi/test_search.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,6 @@ def test_openapi_contains_search_endpoint(self, client):
351351
assert 'paths' in openapi
352352
assert '/search.json' in openapi['paths']
353353

354-
@pytest.mark.xfail(
355-
reason="FastAPI doesn't propagate descriptions from Pydantic models used via Depends(). "
356-
"See: https://github.com/tiangolo/fastapi/discussions/10410"
357-
)
358354
def test_openapi_parameters_have_descriptions(self, client):
359355
"""Test that query parameters in the OpenAPI spec have descriptions.
360356

openlibrary/utils/tests/test_ddc.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
# Src: https://www.oclc.org/bibformats/en/0xx/082.html
1111
TESTS_FROM_OCLC = [
1212
("370.19'342", ['370.19342'], "Segmentation (prime) marks"),
13-
("370.19/342", ['370.19342'], "Segmentation (prime) marks"),
13+
("370.19/342", ['370.19342'], "Segmentation (prime) marks 2"),
1414
("j574", ['j574', '574'], "Juvenile works."),
1515
("[E]", ['[E]'], "Juvenile works with [E]"),
1616
("[Fic]", ['[Fic]'], "Juvenile works with [Fic]."),
1717
("658.404 92", ['658.404 92'], "Dewey numbers followed by 92 or 920."),
18-
("658.404 920", ['658.404 920'], "Dewey numbers followed by 92 or 920."),
18+
("658.404 920", ['658.404 920'], "Dewey numbers followed by 92 or 920. 2"),
1919
("942.082 [B]", ['942.082 B'], "Uppercase B in post-1971 numbers."),
2020
(
2121
"*657.6",
@@ -27,10 +27,10 @@
2727
"*735.29 735.42",
2828
['735.29*', '735.42'],
2929
"LC assigned Dewey numbers according to both the 14th and the 15th editions of "
30-
"the Dewey schedules.",
30+
"the Dewey schedules. 2",
3131
),
3232
("081s", ['081 s'], "Series numbers."),
33-
("081 s", ['081 s'], "Series numbers."),
33+
("081 s", ['081 s'], "Series numbers. 2"),
3434
(
3535
"(015.73)",
3636
['015.73 s'],
@@ -39,17 +39,17 @@
3939
(
4040
"015.73 s",
4141
['015.73 s'],
42-
"Parentheses indicating Dewey numbers assigned to a series.",
42+
"Parentheses indicating Dewey numbers assigned to a series. 2",
4343
),
4444
(
4545
"(015.73) 015.791",
4646
['015.73 s', '015.791'],
4747
"Two Dewey numbers: one in parentheses, one not.",
4848
),
4949
("-222.14", ['-222.14'], "Dewey numbers with minus signs."),
50-
("-222.14 (927.5)", ['-222.14', '927.5 s'], "Dewey numbers with minus signs."),
50+
("-222.14 (927.5)", ['-222.14', '927.5 s'], "Dewey numbers with minus signs. 2"),
5151
("[320.9777]", ['320.9777'], "Dewey numbers in brackets."),
52-
("[016.3584] 012", ['016.3584'], "Dewey numbers in brackets."),
52+
("[016.3584] 012", ['016.3584'], "Dewey numbers in brackets. 2"),
5353
(
5454
"081s [370.19'342]",
5555
['081 s', '370.19342'],
@@ -60,8 +60,8 @@
6060
TESTS = [
6161
('123', ['123'], 'whole number'),
6262
('1', ['001'], 'whole number padding'),
63-
('hello world!', [], 'junk'),
64-
('978123412341', [], 'junk'),
63+
('hello world!', [], 'junk text'),
64+
('978123412341', [], 'junk isbn'),
6565
(
6666
'338.9/009171/7 019',
6767
['338.90091717'],
@@ -136,7 +136,7 @@ def test_normalize_ddc_prefix(prefix, normed, name):
136136

137137
RANGE_TESTS = [
138138
(['0', '3'], ['000', '003'], 'Single numbers'),
139-
(['100', '300'], ['100', '300'], 'Single numbers'),
139+
(['100', '300'], ['100', '300'], 'Bigger single numbers'),
140140
(['100', '*'], ['100', '*'], 'Star'),
141141
]
142142

openlibrary/utils/tests/test_lcc.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,26 @@ def test_to_short_lcc(sortable_lcc, raw_lcc, short_lcc, name):
4343

4444

4545
INVALID_TESTS = [
46-
('6113 .136', 'dewey decimal'),
47-
('9608 BOOK NOT YET IN LC', 'noise'),
48-
('#M8184', 'hash prefixed'),
49-
('', 'empty'),
50-
('MLCS 92/14990', 'too much class'),
51-
('PZ123.234.234', 'too much decimal'),
52-
# The following are "real world" data from open library
53-
('IN PROCESS', 'noise'),
54-
('African Section Pamphlet Coll', 'real ol data'),
55-
('Microfilm 99/20', 'real ol data'),
56-
('Microfilm 61948 E', 'real ol data'),
57-
('Microfiche 92/80965 (G)', 'real ol data'),
58-
('MLCSN+', 'real ol data'),
59-
('UNCLASSIFIED 809 (S)', 'real ol data'),
60-
('CPB Box no. 1516 vol. 17', 'CPB box number'),
46+
pytest.param('6113 .136', id='dewey_decimal'),
47+
pytest.param('9608 BOOK NOT YET IN LC', id='noise_lc_missing'),
48+
pytest.param('#M8184', id='hash_prefixed'),
49+
pytest.param('', id='empty_string'),
50+
pytest.param('MLCS 92/14990', id='excessive_class_info'),
51+
pytest.param('PZ123.234.234', id='too_many_decimals'),
52+
# "Real world" data from Open Library
53+
pytest.param('IN PROCESS', id='noise_in_process'),
54+
pytest.param('African Section Pamphlet Coll', id='ol_african_section'),
55+
pytest.param('Microfilm 99/20', id='ol_microfilm_99_20'),
56+
pytest.param('Microfilm 61948 E', id='ol_microfilm_61948'),
57+
pytest.param('Microfiche 92/80965 (G)', id='ol_microfiche_92'),
58+
pytest.param('MLCSN+', id='ol_mlcsn_plus'),
59+
pytest.param('UNCLASSIFIED 809 (S)', id='ol_unclassified_809'),
60+
pytest.param('CPB Box no. 1516 vol. 17', id='cpb_box_number'),
6161
]
6262

6363

64-
@pytest.mark.parametrize(
65-
('text', 'name'), INVALID_TESTS, ids=[t[-1] for t in INVALID_TESTS]
66-
)
67-
def test_invalid_lccs(text, name):
64+
@pytest.mark.parametrize('text', INVALID_TESTS)
65+
def test_invalid_lccs(text):
6866
assert short_lcc_to_sortable_lcc(text) is None
6967

7068

@@ -107,14 +105,14 @@ def test_wagner_2019_to_short_lcc(sortable_lcc, short_lcc, name):
107105
('A', 'A', 'Single letter'),
108106
('ADC', 'ADC', 'multi letter'),
109107
('A5', 'A--0005', 'Alphanum'),
110-
('A5.00', 'A--0005.00', 'Alphanum'),
108+
('A5.00', 'A--0005.00', 'Alphanum 2'),
111109
('A10', 'A--0010', 'Alphanum trailing 0'),
112110
('A10.5', 'A--0010.5', 'Alphanum with decimal'),
113111
('A10.', 'A--0010', 'Alphanum with trailing decimal'),
114112
('A10.C', 'A--0010.00000000.C', 'Alphanum with partial cutter'),
115113
('F349.N2 A77', 'F--0349.00000000.N2 A77', '2 cutters'),
116114
('123', None, 'Invalid returns None'),
117-
('*B55', None, 'Invalid returns None'),
115+
('*B55', None, 'Invalid also returns None'),
118116
]
119117

120118

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module = ["openlibrary.core.wikidata", "openlibrary.core.yearly_reading_goals"]
3737
disallow_untyped_defs = true
3838

3939
[tool.pytest.ini_options]
40+
strict = true
4041
asyncio_mode = "strict"
4142
asyncio_default_fixture_loop_scope = "function"
4243
filterwarnings = [

scripts/tests/test_isbndb.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ def test_isbndb_get_languages(language, expected, get_isbndb_data):
124124
@pytest.mark.parametrize(
125125
('year', 'expected'),
126126
[
127-
(2000, "2000"),
128-
("2000", "2000"),
129-
("December 2000", "2000"),
130-
("-", None),
131-
("123", None),
132-
(None, None),
127+
pytest.param(2000, "2000", id="integer_year"),
128+
pytest.param("2000", "2000", id="string_year"),
129+
pytest.param("December 2000", "2000", id="full_date_string"),
130+
pytest.param("-", None, id="invalid_placeholder"),
131+
pytest.param("123", None, id="too_short_string"),
132+
pytest.param(None, None, id="null_input"),
133133
],
134134
)
135135
def test_isbndb_get_year(year, expected, get_isbndb_data):

0 commit comments

Comments
 (0)