Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Commit 7e9b9f9

Browse files
committed
Updates tests with success case
1 parent f263a8d commit 7e9b9f9

1 file changed

Lines changed: 42 additions & 18 deletions

File tree

tests/unit/test__pandas_helpers.py

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,7 +2256,16 @@ def fast_download_stream(
22562256

22572257
@pytest.mark.skipif(pandas is None, reason="Requires `pandas`")
22582258
@pytest.mark.skipif(isinstance(pyarrow, mock.Mock), reason="Requires `pyarrow`")
2259-
def test_download_arrow_row_iterator_timeout(module_under_test):
2259+
@pytest.mark.parametrize(
2260+
"sleep_time, timeout, should_timeout",
2261+
[
2262+
(0.1, 0.05, True), # Timeout case
2263+
(0, 10.0, False), # Success case
2264+
],
2265+
)
2266+
def test_download_arrow_row_iterator_with_timeout(
2267+
module_under_test, sleep_time, timeout, should_timeout
2268+
):
22602269
bq_schema = [schema.SchemaField("name", "STRING")]
22612270

22622271
# Mock page with to_arrow method
@@ -2268,30 +2277,41 @@ def test_download_arrow_row_iterator_timeout(module_under_test):
22682277
mock_page.__iter__ = lambda self: iter(["row1"])
22692278
mock_page._columns = [["foo"]]
22702279

2271-
def slow_pages():
2280+
def pages_gen():
22722281
# First page yields quickly
22732282
yield mock_page
2274-
# Sleep to exceed timeout
2275-
time.sleep(0.1)
2283+
if sleep_time > 0:
2284+
time.sleep(sleep_time)
22762285
yield mock_page
22772286

2278-
# Timeout of 0.05s
2279-
timeout = 0.05
22802287
iterator = module_under_test.download_arrow_row_iterator(
2281-
slow_pages(), bq_schema, timeout=timeout
2288+
pages_gen(), bq_schema, timeout=timeout
22822289
)
22832290

2284-
# First item should succeed
2291+
# First item should always succeed
22852292
next(iterator)
22862293

2287-
# Second item should fail with TimeoutError
2288-
with pytest.raises(concurrent.futures.TimeoutError):
2289-
next(iterator)
2294+
if should_timeout:
2295+
with pytest.raises(concurrent.futures.TimeoutError):
2296+
next(iterator)
2297+
else:
2298+
# Should succeed and complete
2299+
results = list(iterator)
2300+
assert len(results) == 1 # 1 remaining item
22902301

22912302

22922303
@pytest.mark.skipif(pandas is None, reason="Requires `pandas`")
22932304
@pytest.mark.skipif(isinstance(pyarrow, mock.Mock), reason="Requires `pyarrow`")
2294-
def test_download_dataframe_row_iterator_timeout(module_under_test):
2305+
@pytest.mark.parametrize(
2306+
"sleep_time, timeout, should_timeout",
2307+
[
2308+
(0.1, 0.05, True), # Timeout case
2309+
(0, 10.0, False), # Success case
2310+
],
2311+
)
2312+
def test_download_dataframe_row_iterator_with_timeout(
2313+
module_under_test, sleep_time, timeout, should_timeout
2314+
):
22952315
bq_schema = [schema.SchemaField("name", "STRING")]
22962316
dtypes = {}
22972317

@@ -2301,17 +2321,21 @@ def test_download_dataframe_row_iterator_timeout(module_under_test):
23012321
mock_page.__iter__ = lambda self: iter(["row1"])
23022322
mock_page._columns = [["foo"]]
23032323

2304-
def slow_pages():
2324+
def pages_gen():
23052325
yield mock_page
2306-
time.sleep(0.1)
2326+
if sleep_time > 0:
2327+
time.sleep(sleep_time)
23072328
yield mock_page
23082329

2309-
timeout = 0.05
23102330
iterator = module_under_test.download_dataframe_row_iterator(
2311-
slow_pages(), bq_schema, dtypes, timeout=timeout
2331+
pages_gen(), bq_schema, dtypes, timeout=timeout
23122332
)
23132333

23142334
next(iterator)
23152335

2316-
with pytest.raises(concurrent.futures.TimeoutError):
2317-
next(iterator)
2336+
if should_timeout:
2337+
with pytest.raises(concurrent.futures.TimeoutError):
2338+
next(iterator)
2339+
else:
2340+
results = list(iterator)
2341+
assert len(results) == 1

0 commit comments

Comments
 (0)