Skip to content

Commit ba2cb48

Browse files
authored
TST: Avoid time.sleep in tests (#62503)
1 parent c8213d1 commit ba2cb48

File tree

3 files changed

+8
-25
lines changed

3 files changed

+8
-25
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
@@ -2016,14 +2015,10 @@ def test_to_s3(self, s3_bucket_public, s3so):
20162015
mock_bucket_name = s3_bucket_public.name
20172016
target_file = f"{uuid.uuid4()}.json"
20182017
df = DataFrame({"x": [1, 2, 3], "y": [2, 4, 6]})
2019-
df.to_json(f"s3://{mock_bucket_name}/{target_file}", storage_options=s3so)
2020-
timeout = 5
2021-
while True:
2022-
if target_file in (obj.key for obj in s3_bucket_public.objects.all()):
2023-
break
2024-
time.sleep(0.1)
2025-
timeout -= 0.1
2026-
assert timeout > 0, "Timed out waiting for file to appear on moto"
2018+
uri = f"s3://{mock_bucket_name}/{target_file}"
2019+
df.to_json(uri, storage_options=s3so)
2020+
result = read_json(uri, storage_options=s3so)
2021+
tm.assert_frame_equal(result, df)
20272022

20282023
def test_json_pandas_nulls(self, nulls_fixture):
20292024
# GH 31615

pandas/tests/io/test_compression.py

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

1110
import numpy as np
@@ -193,7 +192,6 @@ def test_gzip_reproducibility_file_name(temp_file):
193192
# test for filename
194193
path = temp_file
195194
df.to_csv(path, compression=compression_options)
196-
time.sleep(0.1)
197195
output = path.read_bytes()
198196
df.to_csv(path, compression=compression_options)
199197
assert output == path.read_bytes()
@@ -216,7 +214,6 @@ def test_gzip_reproducibility_file_object():
216214
buffer = io.BytesIO()
217215
df.to_csv(buffer, compression=compression_options, mode="wb")
218216
output = buffer.getvalue()
219-
time.sleep(0.1)
220217
buffer = io.BytesIO()
221218
df.to_csv(buffer, compression=compression_options, mode="wb")
222219
assert output == buffer.getvalue()

0 commit comments

Comments
 (0)