Skip to content

Commit cf515a5

Browse files
authored
TST: Use uuid instead of random chars for temp files (#45996)
1 parent c4baf5d commit cf515a5

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

pandas/_testing/contexts.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
from contextlib import contextmanager
44
import os
55
from pathlib import Path
6-
import random
76
from shutil import rmtree
8-
import string
97
import tempfile
108
from typing import (
119
IO,
1210
Any,
1311
)
12+
import uuid
1413

1514
import numpy as np
1615

@@ -107,9 +106,7 @@ def ensure_clean(filename=None, return_filelike: bool = False, **kwargs: Any):
107106

108107
if filename is None:
109108
filename = ""
110-
filename = (
111-
"".join(random.choices(string.ascii_letters + string.digits, k=30)) + filename
112-
)
109+
filename = str(uuid.uuid4()) + filename
113110
path = folder / filename
114111

115112
path.touch()

pandas/tests/io/parser/common/test_file_buffer_url.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import os
1010
import platform
1111
from urllib.error import URLError
12+
import uuid
1213

1314
import pytest
1415

@@ -87,7 +88,7 @@ def test_nonexistent_path(all_parsers):
8788
# gh-14086: raise more helpful FileNotFoundError
8889
# GH#29233 "File foo" instead of "File b'foo'"
8990
parser = all_parsers
90-
path = f"{tm.rands(10)}.csv"
91+
path = f"{uuid.uuid4()}.csv"
9192

9293
msg = r"\[Errno 2\]"
9394
with pytest.raises(FileNotFoundError, match=msg) as e:
@@ -255,7 +256,7 @@ def test_internal_eof_byte_to_file(all_parsers):
255256
parser = all_parsers
256257
data = b'c1,c2\r\n"test \x1a test", test\r\n'
257258
expected = DataFrame([["test \x1a test", " test"]], columns=["c1", "c2"])
258-
path = f"__{tm.rands(10)}__.csv"
259+
path = f"__{uuid.uuid4()}__.csv"
259260

260261
with tm.ensure_clean(path) as path:
261262
with open(path, "wb") as f:

pandas/tests/io/parser/test_encoding.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
Tests encoding functionality during parsing
33
for all of the parsers defined in parsers.py
44
"""
5-
65
from io import BytesIO
76
import os
87
import tempfile
8+
import uuid
99

1010
import numpy as np
1111
import pytest
@@ -54,7 +54,7 @@ def test_utf16_bom_skiprows(all_parsers, sep, encoding):
5454
4,5,6""".replace(
5555
",", sep
5656
)
57-
path = f"__{tm.rands(10)}__.csv"
57+
path = f"__{uuid.uuid4()}__.csv"
5858
kwargs = {"sep": sep, "skiprows": 2}
5959
utf8 = "utf-8"
6060

pandas/tests/io/pytables/conftest.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import uuid
2+
13
import pytest
24

35
import pandas._testing as tm
@@ -6,7 +8,7 @@
68
@pytest.fixture
79
def setup_path():
810
"""Fixture for setup path"""
9-
return f"tmp.__{tm.rands(10)}__.h5"
11+
return f"tmp.__{uuid.uuid4()}__.h5"
1012

1113

1214
@pytest.fixture(scope="module", autouse=True)

pandas/tests/io/test_pickle.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from pathlib import Path
2222
import pickle
2323
import shutil
24+
import uuid
2425
from warnings import (
2526
catch_warnings,
2627
filterwarnings,
@@ -248,7 +249,7 @@ def test_legacy_sparse_warning(datapath, typ):
248249

249250
@pytest.fixture
250251
def get_random_path():
251-
return f"__{tm.rands(10)}__.pickle"
252+
return f"__{uuid.uuid4()}__.pickle"
252253

253254

254255
class TestCompression:

0 commit comments

Comments
 (0)