Skip to content

Use tempfile for creating a file in home directory for a IO test #40122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 2, 2021
Merged
10 changes: 6 additions & 4 deletions pandas/tests/io/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import mmap
import os
from pathlib import Path
import tempfile

import pytest

Expand Down Expand Up @@ -119,10 +120,11 @@ def test_infer_compression_from_path(self, extension, expected, path_type):
@pytest.mark.parametrize("path_type", [str, CustomFSPath, Path])
def test_get_handle_with_path(self, path_type):
# ignore LocalPath: it creates strange paths: /absolute/~/sometest
filename = path_type("~/sometest")
with icom.get_handle(filename, "w") as handles:
assert os.path.isabs(handles.handle.name)
assert os.path.expanduser(filename) == handles.handle.name
with tempfile.TemporaryDirectory(dir=Path.home()) as tmp:
filename = path_type("~/" + Path(tmp).name + "/sometest")
with icom.get_handle(filename, "w") as handles:
assert Path(handles.handle.name).is_absolute()
assert os.path.expanduser(filename) == handles.handle.name

def test_get_handle_with_buffer(self):
input_buffer = StringIO()
Expand Down