Isolate legacy range-grid features
This commit is contained in:
@@ -759,22 +759,76 @@ def test_window_setups_too_short_returns_empty():
|
||||
|
||||
|
||||
def test_sr_research_variant_is_explicit_and_validated(monkeypatch):
|
||||
monkeypatch.setenv("BACKTEST_SR_VARIANT", "production_control")
|
||||
assert bt._sr_research_variant() == "production_control"
|
||||
for variant in (
|
||||
"production_control",
|
||||
"legacy_range_grid_touch",
|
||||
"legacy_range_grid_neutral",
|
||||
):
|
||||
monkeypatch.setenv("BACKTEST_SR_VARIANT", variant)
|
||||
assert bt._sr_research_variant() == variant
|
||||
monkeypatch.setenv("BACKTEST_SR_VARIANT", "not-a-variant")
|
||||
with pytest.raises(ValueError, match="Unknown BACKTEST_SR_VARIANT"):
|
||||
bt._sr_research_variant()
|
||||
|
||||
|
||||
def test_geometry_neutral_strength_is_enforced_after_zone_clustering():
|
||||
@pytest.mark.parametrize(
|
||||
("variant", "neutral_strength"),
|
||||
[
|
||||
("legacy_range_grid_touch", False),
|
||||
("legacy_range_grid_neutral", True),
|
||||
],
|
||||
)
|
||||
def test_window_setups_routes_explicit_range_grid(
|
||||
monkeypatch,
|
||||
variant,
|
||||
neutral_strength,
|
||||
):
|
||||
captured = {}
|
||||
|
||||
def fake_detector(*args, **kwargs):
|
||||
captured.update(kwargs)
|
||||
return []
|
||||
|
||||
monkeypatch.setenv("BACKTEST_SR_VARIANT", variant)
|
||||
monkeypatch.setattr(bt, "detect_sr_levels_legacy", fake_detector)
|
||||
records = [
|
||||
SimpleNamespace(
|
||||
date=date(2024, 1, 1) + timedelta(days=i),
|
||||
open=100.0,
|
||||
high=101.0,
|
||||
low=99.0,
|
||||
close=100.0,
|
||||
volume=1_000_000,
|
||||
)
|
||||
for i in range(bt.MIN_LOOKBACK)
|
||||
]
|
||||
assert bt._window_setups(records, {}, {}) == []
|
||||
assert captured == {
|
||||
"include_pivots": False,
|
||||
"neutral_strength": neutral_strength,
|
||||
"explicit_range_grid": True,
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"variant",
|
||||
["legacy_geometry_neutral", "legacy_range_grid_neutral"],
|
||||
)
|
||||
def test_neutral_strength_is_enforced_after_zone_clustering(variant):
|
||||
levels = [
|
||||
SimpleNamespace(strength=100),
|
||||
SimpleNamespace(strength=75),
|
||||
]
|
||||
result = bt._apply_zone_strength_variant(levels, "legacy_geometry_neutral")
|
||||
result = bt._apply_zone_strength_variant(levels, variant)
|
||||
assert [level.strength for level in result] == [50, 50]
|
||||
|
||||
|
||||
def test_touch_strength_survives_post_cluster_research_hook():
|
||||
levels = [SimpleNamespace(strength=82), SimpleNamespace(strength=37)]
|
||||
result = bt._apply_zone_strength_variant(levels, "legacy_range_grid_touch")
|
||||
assert [level.strength for level in result] == [82, 37]
|
||||
|
||||
|
||||
def test_backtest_entry_bounds_validate_dates(monkeypatch):
|
||||
monkeypatch.setenv("BACKTEST_ENTRY_START", "2024-07-01")
|
||||
monkeypatch.setenv("BACKTEST_ENTRY_END", "2024-12-31")
|
||||
|
||||
Reference in New Issue
Block a user