Skip to content
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
14 changes: 7 additions & 7 deletions autofit/non_linear/paths/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import numpy as np

from autoconf import conf
from autoconf.test_mode import is_test_mode
from autofit.mapper.identifier import Identifier, IdentifierField
from autofit.non_linear.samples.summary import SamplesSummary

Expand All @@ -24,15 +25,15 @@

def _test_mode_segment() -> Optional[str]:
"""
Returns ``"test_mode"`` when ``PYAUTO_TEST_MODE`` is set in the
environment, else ``None``.
Returns ``"test_mode"`` when ``PYAUTO_TEST_MODE`` has an active
test-mode level, else ``None``.

Inserted into the output-path composition so that smoke runs land
under ``output/test_mode/...`` instead of sharing a directory with
real runs. Without this, a cached test-mode result short-circuits
a later real run at the same paths ("Fit Already Completed").
"""
return "test_mode" if os.environ.get("PYAUTO_TEST_MODE") else None
return "test_mode" if is_test_mode() else None


class AbstractPaths(ABC):
Expand Down Expand Up @@ -66,9 +67,8 @@ def __init__(

/path/to/output/folder_0/folder_1/name

If the ``PYAUTO_TEST_MODE`` environment variable is set, a
``test_mode`` segment is inserted directly after the output
root:
If ``PYAUTO_TEST_MODE`` has an active level greater than zero, a
``test_mode`` segment is inserted directly after the output root:

/path/to/output/test_mode/folder_0/folder_1/name

Expand Down Expand Up @@ -497,4 +497,4 @@ def output_model_results(self, result_info):
filename = self.output_path / "model.results"

with open_(filename, "w") as f:
f.write(result_info)
f.write(result_info)
10 changes: 10 additions & 0 deletions test_autofit/non_linear/paths/test_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ def test_output_path_excludes_segment_when_env_unset(self, monkeypatch):
paths = af.DirectoryPaths(name="name", path_prefix="prefix")
assert "test_mode" not in paths.output_path.parts

def test_output_path_excludes_segment_when_level_zero(self, monkeypatch):
monkeypatch.setenv("PYAUTO_TEST_MODE", "0")
paths = af.DirectoryPaths(name="name", path_prefix="prefix")
assert "test_mode" not in paths.output_path.parts

def test_make_path_contains_segment_when_env_set(self, monkeypatch):
monkeypatch.setenv("PYAUTO_TEST_MODE", "2")
paths = af.DirectoryPaths(name="name", path_prefix="prefix")
Expand All @@ -105,3 +110,8 @@ def test_make_path_excludes_segment_when_env_unset(self, monkeypatch):
monkeypatch.delenv("PYAUTO_TEST_MODE", raising=False)
paths = af.DirectoryPaths(name="name", path_prefix="prefix")
assert "test_mode" not in paths._make_path().parts

def test_make_path_excludes_segment_when_level_zero(self, monkeypatch):
monkeypatch.setenv("PYAUTO_TEST_MODE", "0")
paths = af.DirectoryPaths(name="name", path_prefix="prefix")
assert "test_mode" not in paths._make_path().parts
Loading