Skip to content

Commit 7537dca

Browse files
committed
test: update tests
1 parent 8174298 commit 7537dca

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

tests/conftest.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,22 @@ def synthetic_env(mocker):
111111
}
112112

113113
# Return only requested symbols to keep shapes consistent with the user's input
114-
def _filtered_get_dict(symbols):
114+
def _filtered_get_dict(symbols, first_date=None, last_date=None):
115115
"""Return a dict with only the requested symbols/objects from fake_assets.
116116
117117
Supports both symbol strings and already constructed Asset-like objects
118118
(with attribute `symbol`). This ensures that the number of assets in
119119
assets_ror matches the number of symbols passed to EfficientFrontier
120120
(and hence its bounds).
121+
122+
Parameters
123+
----------
124+
symbols : list
125+
List of symbols or Asset-like objects.
126+
first_date : str, optional
127+
First date parameter (ignored in mock, kept for signature compatibility).
128+
last_date : str, optional
129+
Last date parameter (ignored in mock, kept for signature compatibility).
121130
"""
122131
result = {}
123132
for s in symbols:
@@ -132,7 +141,9 @@ def _filtered_get_dict(symbols):
132141
# This is needed for tests that create their own test objects
133142
from okama.common.make_asset_list import ListMaker
134143
# Call the original unmocked method
135-
original_result = ListMaker.__dict__['_get_asset_obj_dict'].__func__([s])
144+
original_result = ListMaker.__dict__['_get_asset_obj_dict'].__func__(
145+
[s], first_date=first_date, last_date=last_date
146+
)
136147
result.update(original_result)
137148
else:
138149
# Otherwise, it's a symbol string -> take from our predefined fake_assets

tests/portfolio/mc/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def _get_or_make(symbol: str):
5353
_cache[symbol] = FakeAsset(symbol, _series_for(symbol), currency="RUB" if symbol.endswith(".INDX") else "USD")
5454
return _cache[symbol]
5555

56-
def _filtered_get_dict(symbols):
56+
def _filtered_get_dict(symbols, first_date=None, last_date=None):
5757
res = {}
5858
for s in symbols:
5959
if hasattr(s, "symbol"):

tests/test_rebalance.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,21 @@
77
from okama.common.helpers import rebalancing as rb
88

99

10-
@mark.rebalance
1110
def test_validate_period_failing():
1211
with pytest.raises(ValueError):
1312
ok.Rebalance(period="not existing")
1413

1514

16-
@mark.rebalance
1715
def test_validate_abs_deviation_big_failing():
1816
with pytest.raises(ValueError, match=r"Absolute deviation must be less or equal to 1."):
1917
ok.Rebalance(abs_deviation=1.5)
2018

2119

22-
@mark.rebalance
2320
def test_validate_abs_deviation_small_failing():
2421
with pytest.raises(ValueError, match=r"Absolute deviation must be positive."):
2522
ok.Rebalance(abs_deviation=-100)
2623

2724

28-
@mark.rebalance
2925
def test_validate_rel_deviation_failing():
3026
with pytest.raises(ValueError, match=r"Relative deviation must be positive."):
3127
ok.Rebalance(rel_deviation=-100)
@@ -56,7 +52,6 @@ def test_rebalance_by_condition_events_with_mock(mocker):
5652
assert (res.events == "abs").any()
5753

5854

59-
@mark.rebalance
6055
def test_check_if_rebalancing_required_series_abs():
6156
# Series: trigger by absolute deviation
6257
r = ok.Rebalance(period="none", abs_deviation=0.05)
@@ -69,7 +64,6 @@ def test_check_if_rebalancing_required_series_abs():
6964
assert cond_abs is True
7065

7166

72-
@mark.rebalance
7367
def test_check_if_rebalancing_required_series_rel():
7468
# Series: trigger only by relative deviation
7569
r = ok.Rebalance(period="none", rel_deviation=0.08)
@@ -82,7 +76,6 @@ def test_check_if_rebalancing_required_series_rel():
8276
assert cond_abs is False
8377

8478

85-
@mark.rebalance
8679
def test_check_if_rebalancing_required_series_no_trigger():
8780
# Series: no trigger for both thresholds
8881
r = ok.Rebalance(period="none", abs_deviation=0.2, rel_deviation=0.5)
@@ -95,7 +88,6 @@ def test_check_if_rebalancing_required_series_no_trigger():
9588
assert cond_abs is False
9689

9790

98-
@mark.rebalance
9991
def test_check_if_rebalancing_required_dataframe_last_row_rel():
10092
# DataFrame + Series: only the last row is considered (iloc[-1])
10193
r = ok.Rebalance(period="none", rel_deviation=0.05)
@@ -110,7 +102,6 @@ def test_check_if_rebalancing_required_dataframe_last_row_rel():
110102
assert cond_abs is False
111103

112104

113-
@mark.rebalance
114105
def test_assets_weights_ts_no_rebalancing_manual():
115106
# No rebalancing at all: assets weights should be equal to manual calculation
116107
idx = pd.period_range("2020-01", "2020-03", freq="M")
@@ -146,7 +137,6 @@ def test_assets_weights_ts_no_rebalancing_manual():
146137
pdt.assert_frame_equal(weights_ts, weights_manual, atol=1e-12, rtol=1e-12)
147138

148139

149-
@mark.rebalance
150140
def test_return_ror_ts_no_rebalancing_manual():
151141
# Verify portfolio return series equals manual pct_change of wealth index in no-rebalancing case
152142
idx = pd.period_range("2020-01", "2020-03", freq="M")

0 commit comments

Comments
 (0)