Skip to content

Commit 137184c

Browse files
committed
TST: Avoid time.sleep in tests
1 parent 5614c7c commit 137184c

File tree

4 files changed

+9
-26
lines changed

4 files changed

+9
-26
lines changed

pandas/tests/io/excel/test_style.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import contextlib
2-
import time
32
import uuid
43

54
import numpy as np
@@ -324,18 +323,10 @@ def test_styler_to_s3(s3_bucket_public, s3so):
324323
target_file = f"{uuid.uuid4()}.xlsx"
325324
df = DataFrame({"x": [1, 2, 3], "y": [2, 4, 6]})
326325
styler = df.style.set_sticky(axis="index")
327-
styler.to_excel(f"s3://{mock_bucket_name}/{target_file}", storage_options=s3so)
328-
timeout = 5
329-
while True:
330-
if target_file in (obj.key for obj in s3_bucket_public.objects.all()):
331-
break
332-
time.sleep(0.1)
333-
timeout -= 0.1
334-
assert timeout > 0, "Timed out waiting for file to appear on moto"
335-
result = read_excel(
336-
f"s3://{mock_bucket_name}/{target_file}", index_col=0, storage_options=s3so
337-
)
338-
tm.assert_frame_equal(result, df)
326+
uri = f"s3://{mock_bucket_name}/{target_file}"
327+
styler.to_excel(uri, storage_options=s3so)
328+
result = read_excel(uri, index_col=0, storage_options=s3so)
329+
tm.assert_frame_equal(result, df)
339330

340331

341332
@pytest.mark.parametrize("merge_cells", [True, False, "columns"])

pandas/tests/io/json/test_pandas.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import json
88
import os
99
import sys
10-
import time
1110
import uuid
1211

1312
import numpy as np
@@ -2019,14 +2018,10 @@ def test_to_s3(self, s3_bucket_public, s3so):
20192018
mock_bucket_name = s3_bucket_public.name
20202019
target_file = f"{uuid.uuid4()}.json"
20212020
df = DataFrame({"x": [1, 2, 3], "y": [2, 4, 6]})
2022-
df.to_json(f"s3://{mock_bucket_name}/{target_file}", storage_options=s3so)
2023-
timeout = 5
2024-
while True:
2025-
if target_file in (obj.key for obj in s3_bucket_public.objects.all()):
2026-
break
2027-
time.sleep(0.1)
2028-
timeout -= 0.1
2029-
assert timeout > 0, "Timed out waiting for file to appear on moto"
2021+
uri = f"s3://{mock_bucket_name}/{target_file}"
2022+
df.to_json(uri, storage_options=s3so)
2023+
result = read_json(uri, storage_options=s3so)
2024+
tm.assert_frame_equal(result, df)
20302025

20312026
def test_json_pandas_nulls(self, nulls_fixture):
20322027
# GH 31615

pandas/tests/io/pytables/test_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def create_h5_and_return_checksum(tmp_path, track_times):
9090
checksum_0_tt_true = create_h5_and_return_checksum(tmp_path, track_times=True)
9191

9292
# sleep is necessary to create h5 with different creation time
93-
time.sleep(1)
93+
time.sleep(0.5)
9494

9595
checksum_1_tt_false = create_h5_and_return_checksum(tmp_path, track_times=False)
9696
checksum_1_tt_true = create_h5_and_return_checksum(tmp_path, track_times=True)

pandas/tests/io/test_compression.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import sys
77
import tarfile
88
import textwrap
9-
import time
109
import zipfile
1110

1211
import numpy as np
@@ -186,7 +185,6 @@ def test_gzip_reproducibility_file_name():
186185
with tm.ensure_clean() as path:
187186
path = Path(path)
188187
df.to_csv(path, compression=compression_options)
189-
time.sleep(0.1)
190188
output = path.read_bytes()
191189
df.to_csv(path, compression=compression_options)
192190
assert output == path.read_bytes()
@@ -209,7 +207,6 @@ def test_gzip_reproducibility_file_object():
209207
buffer = io.BytesIO()
210208
df.to_csv(buffer, compression=compression_options, mode="wb")
211209
output = buffer.getvalue()
212-
time.sleep(0.1)
213210
buffer = io.BytesIO()
214211
df.to_csv(buffer, compression=compression_options, mode="wb")
215212
assert output == buffer.getvalue()

0 commit comments

Comments
 (0)