Skip to content

Commit 2d63d73

Browse files
Jammy2211claude
authored andcommitted
Add test_mode_samples() accessor for PYAUTO_TEST_MODE_SAMPLES
Number of fake samples the test-mode sampler bypass writes (default 4 = historical behaviour; values below 4 raise). Consumed by PyAutoFit's _build_fake_samples to write size-realistic samples.csv outputs (PyAutoFit#1379; design locked on PyAutoFit#1378). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 4a1f6ea commit 2d63d73

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

autoconf/test_mode.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,30 @@ def is_test_mode():
2121
return test_mode_level() > 0
2222

2323

24+
def test_mode_samples():
25+
"""
26+
Return the number of fake samples the test-mode sampler bypass writes.
27+
28+
Controlled by ``PYAUTO_TEST_MODE_SAMPLES`` (default 4, the historical
29+
bypass sample count — unset behaviour is unchanged). Larger values make
30+
a ``PYAUTO_TEST_MODE=2``/``3`` bypass run write a ``samples.csv`` whose
31+
row count and byte size are representative of a production sampler run
32+
(N ~ 10k-100k), so resume/load timings measured against the output are
33+
honest while the fit itself completes in seconds.
34+
35+
Values below 4 raise: 4 is the minimum that preserves the bypass
36+
sample structure downstream code is tested against.
37+
"""
38+
samples = int(os.environ.get("PYAUTO_TEST_MODE_SAMPLES", "4"))
39+
if samples < 4:
40+
raise ValueError(
41+
f"PYAUTO_TEST_MODE_SAMPLES must be >= 4 (got {samples}) — 4 is "
42+
f"the minimum that preserves the test-mode bypass sample "
43+
f"structure."
44+
)
45+
return samples
46+
47+
2448
def skip_fit_output():
2549
"""
2650
Return True if fit I/O should be skipped.

test_autoconf/test_test_mode.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from autoconf.test_mode import (
1212
is_test_mode,
1313
test_mode_level,
14+
test_mode_samples,
1415
with_test_mode_segment,
1516
)
1617

@@ -54,3 +55,27 @@ def test_with_test_mode_segment__chains_with_pathlib_concat():
5455
os.environ["PYAUTO_TEST_MODE"] = "2"
5556
composed = with_test_mode_segment(Path("output")) / "results_folder"
5657
assert composed == Path("output") / "test_mode" / "results_folder"
58+
59+
60+
class TestTestModeSamples:
61+
@pytest.fixture(autouse=True)
62+
def _restore_samples_env(self):
63+
saved = os.environ.get("PYAUTO_TEST_MODE_SAMPLES")
64+
yield
65+
if saved is None:
66+
os.environ.pop("PYAUTO_TEST_MODE_SAMPLES", None)
67+
else:
68+
os.environ["PYAUTO_TEST_MODE_SAMPLES"] = saved
69+
70+
def test__env_unset_returns_historical_default_of_four(self):
71+
os.environ.pop("PYAUTO_TEST_MODE_SAMPLES", None)
72+
assert test_mode_samples() == 4
73+
74+
def test__env_set_returns_value(self):
75+
os.environ["PYAUTO_TEST_MODE_SAMPLES"] = "50000"
76+
assert test_mode_samples() == 50000
77+
78+
def test__values_below_four_raise(self):
79+
os.environ["PYAUTO_TEST_MODE_SAMPLES"] = "3"
80+
with pytest.raises(ValueError):
81+
test_mode_samples()

0 commit comments

Comments
 (0)