Skip to content
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

fix(fixtures): don't use square brackets in tempdir paths #160

Merged
merged 4 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions autotest/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
10 changes: 8 additions & 2 deletions modflow_devtools/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@

@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
Expand Down
3 changes: 1 addition & 2 deletions modflow_devtools/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,8 +17,6 @@
from urllib import request
from urllib.error import URLError

from _warnings import warn


@contextmanager
def set_dir(path: PathLike):
Expand Down
Loading