Skip to content

Commit ba9cb9c

Browse files
committed
copy over to async
1 parent dcd7193 commit ba9cb9c

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

qbreader/asynchronous.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ async def query(
8080
maxReturnLength: Optional[int] = 25,
8181
tossupPagination: Optional[int] = 1,
8282
bonusPagination: Optional[int] = 1,
83+
min_year: int = Year.MIN_YEAR,
84+
max_year: int = Year.CURRENT_YEAR,
8385
) -> QueryResponse:
8486
"""Query the qbreader database for questions.
8587
@@ -127,7 +129,10 @@ class type.
127129
The page of tossups to return.
128130
bonusPagination : int, default = 1
129131
The page of bonuses to return.
130-
132+
min_year : int, default = Year.MIN_YEAR
133+
The earliest year to search.
134+
max_year : int, default = Year.CURRENT_YEAR
135+
The latest year to search.
131136
Returns
132137
-------
133138
QueryResponse
@@ -184,6 +189,15 @@ class type.
184189
elif param < 1:
185190
raise ValueError(f"{name} must be at least 1.")
186191

192+
for name, year in {
193+
"minYear": min_year,
194+
"maxYear": max_year,
195+
}.items():
196+
if not isinstance(year, int):
197+
raise TypeError(
198+
f"{name} must be an integer, not {type(param).__name__}."
199+
)
200+
187201
url = BASE_URL + "/query"
188202

189203
(
@@ -209,6 +223,8 @@ class type.
209223
"maxReturnLength": maxReturnLength,
210224
"tossupPagination": tossupPagination,
211225
"bonusPagination": bonusPagination,
226+
"minYear": min_year,
227+
"maxYear": max_year,
212228
}
213229
data = api_utils.prune_none(data)
214230

tests/test_async.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,22 @@ async def test_query(self, qbr, params: dict[str, Any], expected_answer: str):
116116
)
117117
assert judgement.correct()
118118

119+
@pytest.mark.asyncio
120+
async def test_query_min_max_year_range(self, qbr):
121+
min_year = 2010
122+
max_year = 2015
123+
124+
query = await qbr.query(
125+
questionType="tossup",
126+
searchType="question",
127+
min_year=min_year,
128+
max_year=max_year,
129+
maxReturnLength=10,
130+
)
131+
132+
for tossup in query.tossups:
133+
assert min_year <= tossup.set.year <= max_year
134+
119135
@pytest.mark.asyncio
120136
@pytest.mark.parametrize(
121137
"params, exception",

0 commit comments

Comments
 (0)