Skip to content

Commit 9a5f846

Browse files
authored
TST : Removed ensure_clean from test_common_basic.py #62425 (#62856)
1 parent 99c7898 commit 9a5f846

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

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

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from inspect import signature
88
from io import StringIO
99
import os
10-
from pathlib import Path
1110
import sys
1211

1312
import numpy as np
@@ -615,16 +614,16 @@ def test_sub_character(all_parsers, csv_dir_path):
615614

616615

617616
@pytest.mark.parametrize("filename", ["sé-es-vé.csv", "ru-sй.csv", "中文文件名.csv"])
618-
def test_filename_with_special_chars(all_parsers, filename):
617+
def test_filename_with_special_chars(all_parsers, filename, tmp_path):
619618
# see gh-15086.
620619
parser = all_parsers
621620
df = DataFrame({"a": [1, 2, 3]})
622621

623-
with tm.ensure_clean(filename) as path:
624-
df.to_csv(path, index=False)
622+
path = tmp_path / filename
623+
df.to_csv(path, index=False)
625624

626-
result = parser.read_csv(path)
627-
tm.assert_frame_equal(result, df)
625+
result = parser.read_csv(path)
626+
tm.assert_frame_equal(result, df)
628627

629628

630629
def test_read_table_same_signature_as_read_csv(all_parsers):
@@ -786,22 +785,22 @@ def test_dict_keys_as_names(all_parsers):
786785

787786
@pytest.mark.xfail(using_string_dtype() and HAS_PYARROW, reason="TODO(infer_string)")
788787
@xfail_pyarrow # UnicodeDecodeError: 'utf-8' codec can't decode byte 0xed in position 0
789-
def test_encoding_surrogatepass(all_parsers):
788+
def test_encoding_surrogatepass(all_parsers, tmp_path):
790789
# GH39017
791790
parser = all_parsers
792791
content = b"\xed\xbd\xbf"
793792
decoded = content.decode("utf-8", errors="surrogatepass")
794793
expected = DataFrame({decoded: [decoded]}, index=[decoded * 2])
795794
expected.index.name = decoded * 2
796795

797-
with tm.ensure_clean() as path:
798-
Path(path).write_bytes(
799-
content * 2 + b"," + content + b"\n" + content * 2 + b"," + content
800-
)
801-
df = parser.read_csv(path, encoding_errors="surrogatepass", index_col=0)
802-
tm.assert_frame_equal(df, expected)
803-
with pytest.raises(UnicodeDecodeError, match="'utf-8' codec can't decode byte"):
804-
parser.read_csv(path)
796+
path = tmp_path / "test_encoding.csv"
797+
path.write_bytes(
798+
content * 2 + b"," + content + b"\n" + content * 2 + b"," + content
799+
)
800+
df = parser.read_csv(path, encoding_errors="surrogatepass", index_col=0)
801+
tm.assert_frame_equal(df, expected)
802+
with pytest.raises(UnicodeDecodeError, match="'utf-8' codec can't decode byte"):
803+
parser.read_csv(path)
805804

806805

807806
def test_malformed_second_line(all_parsers):
@@ -835,15 +834,15 @@ def test_short_multi_line(all_parsers):
835834
tm.assert_frame_equal(result, expected)
836835

837836

838-
def test_read_seek(all_parsers):
837+
def test_read_seek(all_parsers, tmp_path):
839838
# GH48646
840839
parser = all_parsers
841840
prefix = "### DATA\n"
842841
content = "nkey,value\ntables,rectangular\n"
843-
with tm.ensure_clean() as path:
844-
Path(path).write_text(prefix + content, encoding="utf-8")
845-
with open(path, encoding="utf-8") as file:
846-
file.readline()
847-
actual = parser.read_csv(file)
848-
expected = parser.read_csv(StringIO(content))
842+
path = tmp_path / "test_seek.csv"
843+
path.write_text(prefix + content, encoding="utf-8")
844+
with open(path, encoding="utf-8") as file:
845+
file.readline()
846+
actual = parser.read_csv(file)
847+
expected = parser.read_csv(StringIO(content))
849848
tm.assert_frame_equal(actual, expected)

0 commit comments

Comments
 (0)