From f2b293f25e69fff47b0f1bf9cb55da32cbdc08f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BRIOL?= Date: Tue, 16 Jan 2024 07:17:21 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Add=20temporary=20directory=20creat?= =?UTF-8?q?ion=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zcollection/tests/fs.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/zcollection/tests/fs.py b/zcollection/tests/fs.py index fbbb89e..b1becf3 100644 --- a/zcollection/tests/fs.py +++ b/zcollection/tests/fs.py @@ -8,6 +8,7 @@ """ from typing import Any, Iterator import pathlib +import tempfile import fsspec import fsspec.implementations.memory @@ -23,6 +24,11 @@ S3_IMPORT_EXCEPTION = str(err) +def tempdir(tmpdir) -> pathlib.Path: + """Create a temporary directory.""" + return pathlib.Path(tempfile.mkdtemp(dir=str(tmpdir))) + + class Local: """Local files system.""" @@ -30,7 +36,7 @@ def __init__(self, tmpdir, protocol) -> None: #: The filesystem. self.fs: fsspec.AbstractFileSystem = fsspec.filesystem(protocol) #: The root directory. - self.root = pathlib.Path(tmpdir) + self.root = tempdir(pathlib.Path(tmpdir)) #: The collection directory. self.collection: pathlib.Path = self.root.joinpath('collection') #: The view directory.