Skip to content

Commit

Permalink
Clean up lazy fixture usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
edtechre committed Mar 17, 2024
1 parent 7fa458a commit f003d21
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
8 changes: 4 additions & 4 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def test_set_cached(self, alpaca_df, symbols, mock_cache):
assert sym_df.equals(alpaca_df[alpaca_df["symbol"] == sym])

@pytest.mark.usefixtures("scope")
@pytest.mark.parametrize("query_symbols", [[], "symbols"])
@pytest.mark.parametrize("query_symbols", [[], LazyFixture("symbols")])
def test_get_cached_when_empty(self, mock_cache, query_symbols, request):
query_symbols = get_fixture(request, query_symbols)
cache_mixin = DataSourceCacheMixin()
Expand Down Expand Up @@ -503,11 +503,11 @@ class TestYFinance:
"param_symbols, expected_df, expected_rows",
[
(
"symbols",
"yfinance_df",
LazyFixture("symbols"),
LazyFixture("yfinance_df"),
2020,
),
(["SPY"], "yfinance_single_df", 505),
(["SPY"], LazyFixture("yfinance_single_df"), 505),
],
)
@pytest.mark.usefixtures("setup_ds_cache")
Expand Down
4 changes: 3 additions & 1 deletion tests/test_indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ def test_call_when_indicators_empty_then_error(self, data_source_df):
with pytest.raises(ValueError, match="No indicators were added."):
ind_set(data_source_df)

@pytest.mark.parametrize("df", [pd.DataFrame(), "data_source_df"])
@pytest.mark.parametrize(
"df", [pd.DataFrame(), LazyFixture("data_source_df")]
)
def test_call(self, df, hhv_ind, llv_ind, disable_parallel, request):
df = get_fixture(request, df)
ind_set = IndicatorSet()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def _assert_models(self, models, expected_model_syms):
"param_test_data",
[
pd.DataFrame(columns=["symbol", "date"]),
"test_data",
LazyFixture("test_data"),
],
)
def test_train_models(
Expand Down
12 changes: 6 additions & 6 deletions tests/test_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,16 +1174,16 @@ def _fetch_data(
class TestStrategy:
@pytest.mark.parametrize(
"data_source",
[FakeDataSource(), "data_source_df"],
[FakeDataSource(), LazyFixture("data_source_df")],
)
@pytest.mark.parametrize(
"executions",
[
"executions_train_only",
"executions_only",
"executions_with_indicators",
"executions_with_models",
"executions_with_models_and_indicators",
LazyFixture("executions_train_only"),
LazyFixture("executions_only"),
LazyFixture("executions_with_indicators"),
LazyFixture("executions_with_models"),
LazyFixture("executions_with_models_and_indicators"),
],
)
def test_walkforward(
Expand Down
11 changes: 9 additions & 2 deletions tests/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from typing import NamedTuple


class LazyFixture(NamedTuple):
name: str


def get_fixture(request, param):
if isinstance(param, str):
return request.getfixturevalue(param)
if isinstance(param, LazyFixture):
return request.getfixturevalue(param.name)
return param

0 comments on commit f003d21

Please sign in to comment.