fix(output): apply positive-integral export guard to to_one mode

CSVEmitter.export_to_csv raised ValueError only in intensity mode;
degenerate exports with --normalize-to-one silently wrote all-zero
CSV files. The guard now runs before the mode split and no file is
written in either mode.
This commit is contained in:
2026-10-01 23:02:33 +03:00
parent ee7aedc80a
commit 62bf7fdac2
2 changed files with 28 additions and 13 deletions
+17 -2
View File
@@ -66,7 +66,7 @@ def make_single_config(**over: Any) -> SpectrumConfig:
)
def make_degenerate_config() -> SpectrumConfig:
def make_degenerate_config(**over: Any) -> SpectrumConfig:
"""Multi-branch config where every endpoint lies below m_nu."""
return SpectrumConfig(
Z_parent=43,
@@ -75,6 +75,7 @@ def make_degenerate_config() -> SpectrumConfig:
endpoint_MeV=0.294,
e_step_MeV=0.001,
neutrino_mass_MeV=0.35,
**over,
branches=[
BranchConfig(endpoint_MeV=0.294, transition_type="F2", intensity=0.98),
BranchConfig(endpoint_MeV=0.200, transition_type="F2U", intensity=0.02),
@@ -329,8 +330,22 @@ class TestCSVExportCoreSemantics:
spectrum = BetaSpectrum.from_config(config)
analyzer = BetaSpectrumAnalyzer(spectrum, config)
path = str(tmp_path / "degenerate.csv")
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="non-positive"):
analyzer.export_to_csv(path)
assert not (tmp_path / "degenerate.csv").exists()
def test_degenerate_export_raises_in_normalize_to_one_mode(
self, tmp_path: Any
) -> None:
"""The positive-integral guard must apply in to_one mode too:
no all-zero CSV may be written for a degenerate spectrum."""
config = make_degenerate_config(normalize_to_one=True)
spectrum = BetaSpectrum.from_config(config)
analyzer = BetaSpectrumAnalyzer(spectrum, config)
path = str(tmp_path / "degenerate_to_one.csv")
with pytest.raises(ValueError, match="non-positive"):
analyzer.export_to_csv(path)
assert not (tmp_path / "degenerate_to_one.csv").exists()
def test_concise_values_match_full(self, tmp_path: Any) -> None:
config = make_multi_config()