From 2c91b4be61313811d878605500be2315918417b0 Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Mon, 10 Jun 2024 14:34:38 -0400 Subject: [PATCH 1/4] fix(fixtures): don't use square brackets in tempdir paths * multiple programs don't like this: gridgen, iris --- modflow_devtools/fixtures.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modflow_devtools/fixtures.py b/modflow_devtools/fixtures.py index 963fa4e..572f5a8 100644 --- a/modflow_devtools/fixtures.py +++ b/modflow_devtools/fixtures.py @@ -16,8 +16,13 @@ @pytest.fixture(scope="function") def function_tmpdir(tmpdir_factory, request) -> Generator[Path, None, None]: - node = request.node.name.replace("/", "_").replace("\\", "_").replace(":", "_") - temp = Path(tmpdir_factory.mktemp(node)) + node_name = request.node.name\ + .replace("/", "_")\ + .replace("\\", "_")\ + .replace(":", "_")\ + .replace("[", "_")\ + .replace("]", "_") + temp = Path(tmpdir_factory.mktemp(node_name)) yield Path(temp) keep = request.config.option.KEEP From 260567b44a678e9de362b74f3db65f3e8a25d13b Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Mon, 10 Jun 2024 14:37:17 -0400 Subject: [PATCH 2/4] ruff --- modflow_devtools/fixtures.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modflow_devtools/fixtures.py b/modflow_devtools/fixtures.py index 572f5a8..3e6dc12 100644 --- a/modflow_devtools/fixtures.py +++ b/modflow_devtools/fixtures.py @@ -16,12 +16,13 @@ @pytest.fixture(scope="function") def function_tmpdir(tmpdir_factory, request) -> Generator[Path, None, None]: - node_name = request.node.name\ - .replace("/", "_")\ - .replace("\\", "_")\ - .replace(":", "_")\ - .replace("[", "_")\ + node_name = ( + request.node.name.replace("/", "_") + .replace("\\", "_") + .replace(":", "_") + .replace("[", "_") .replace("]", "_") + ) temp = Path(tmpdir_factory.mktemp(node_name)) yield Path(temp) From 068c4ec823dc4052030235c5375573cf01208009 Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Mon, 10 Jun 2024 14:41:17 -0400 Subject: [PATCH 3/4] ruff after update --- modflow_devtools/misc.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modflow_devtools/misc.py b/modflow_devtools/misc.py index 08a03f4..882a9ff 100644 --- a/modflow_devtools/misc.py +++ b/modflow_devtools/misc.py @@ -2,6 +2,7 @@ import socket import sys import traceback +from _warnings import warn from ast import literal_eval from contextlib import contextmanager from functools import wraps @@ -16,8 +17,6 @@ from urllib import request from urllib.error import URLError -from _warnings import warn - @contextmanager def set_dir(path: PathLike): From cdd347ed75a94acb8ecc10f20da4e3db4822d3f3 Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Mon, 10 Jun 2024 14:56:04 -0400 Subject: [PATCH 4/4] fix tests --- autotest/test_fixtures.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/autotest/test_fixtures.py b/autotest/test_fixtures.py index b9fa5b5..7470745 100644 --- a/autotest/test_fixtures.py +++ b/autotest/test_fixtures.py @@ -37,11 +37,23 @@ def test_function_scoped_tmpdir_slash_in_name(function_tmpdir, name): # node name might have slashes if test function is parametrized # (e.g., test_function_scoped_tmpdir_slash_in_name[a/slash]) - replaced1 = name.replace("/", "_").replace("\\", "_").replace(":", "_") - replaced2 = name.replace("/", "_").replace("\\", "__").replace(":", "_") + replaced1 = ( + name.replace("/", "_") + .replace("\\", "_") + .replace(":", "_") + .replace("[", "") + .replace("]", "") + ) + replaced2 = ( + name.replace("/", "_") + .replace("\\", "__") + .replace(":", "_") + .replace("[", "") + .replace("]", "") + ) assert ( - f"{inspect.currentframe().f_code.co_name}[{replaced1}]" in function_tmpdir.stem - or f"{inspect.currentframe().f_code.co_name}[{replaced2}]" + f"{inspect.currentframe().f_code.co_name}_{replaced1}_" in function_tmpdir.stem + or f"{inspect.currentframe().f_code.co_name}_{replaced2}_" in function_tmpdir.stem )