Skip to content

Commit 207d855

Browse files
committed
Fixes for new tests
Fixes for new `test_to_csv` and `test_request_from_left_limit` to prevent flaky behavior.
1 parent e041323 commit 207d855

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

tests/test_base_prices.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6361,9 +6361,11 @@ def assert_output_as_original_files(paths: list[Path]):
63616361
# verify can pass non-base interval
63626362
clean_temp_test_dir()
63636363
df = prices.get("10T")
6364+
df = df[df.columns.sort_values()]
63646365
paths = prices.to_csv(temp_dir, "10T")
63656366
prices_reloaded = csv.PricesCsv(temp_dir, symbols, calendars)
63666367
df_reloaded = prices_reloaded.get("10T")
6368+
df_reloaded = df_reloaded[df_reloaded.columns.sort_values()]
63676369
assert_frame_equal(df, df_reloaded)
63686370

63696371
# verify can pass get_params
@@ -6381,7 +6383,7 @@ def assert_output_as_original_files(paths: list[Path]):
63816383
clean_temp_test_dir()
63826384
match = re.escape(
63836385
"It was not possible to export prices as an error was raised when prices were"
6384-
f" requested for interval {TDInterval.T1}. The error is included at the top of"
6386+
f" requested for interval {prices.bis.T1}. The error is included at the top of"
63856387
" the traceback.\nNB prices have not been exported for any interval."
63866388
)
63876389
with pytest.raises(errors.PricesUnavailableForExport, match=match):

tests/test_yahoo.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ class TestRequestDataIntraday:
924924
@pytest.mark.filterwarnings("ignore:Prices from Yahoo are missing for:UserWarning")
925925
@pytest.mark.filterwarnings("ignore:A value is trying to be set on a:FutureWarning")
926926
@pytest.mark.filterwarnings("ignore:'S' is deprecated:FutureWarning")
927-
def test_request_from_left_limit(self):
927+
def test_request_from_left_limit(self, one_min):
928928
"""Test data requests from left limit.
929929
930930
The Yahoo API appears to exhibit flaky behaviour when requesting
@@ -953,8 +953,10 @@ def test_request_from_left_limit(self):
953953
if not rl < table.pt.last_ts:
954954
# <= bi.as_minutes as rl is 'now' + bi and that bi can all be
955955
# trading minutes beyond the right of the last indice
956+
# + one_min to provide for processing between getting calendar
957+
# and evaluating minutes
956958
num_mins = len(cal.minutes_in_range(table.pt.last_ts, rl))
957-
assert num_mins <= bi.as_minutes
959+
assert num_mins <= bi.as_minutes + 1
958960
else:
959961
ll = prices.limit_daily
960962
assert table.pt.first_ts == prices.cc.date_to_session(ll, "next")
@@ -979,8 +981,10 @@ def test_request_from_left_limit(self):
979981
if not rl < table.pt.last_ts:
980982
# <= bi.as_minutes as rl is 'now' + bi and that bi can all be
981983
# trading minutes beyond the right of the last indice
984+
# + one_min to provide for processing between getting calendar
985+
# and evaluating minutes
982986
num_mins = len(cal.minutes_in_range(table.pt.last_ts, rl))
983-
assert num_mins <= bi.as_minutes
987+
assert num_mins <= bi.as_minutes + 1
984988
else:
985989
ll = prices.limit_daily
986990
assert table.pt.first_ts == prices.cc.date_to_session(ll, "next")
@@ -1000,7 +1004,10 @@ def verify_limit_intraday_bi(self, prices: m.PricesYahoo):
10001004
len_mins = []
10011005
for cal in prices.calendars_unique:
10021006
len_mins.append(len(cal.minutes_in_range(prices.limits[bi][0], limit)))
1003-
assert (1 + bi.as_minutes) == min(len_mins)
1007+
# NB the number of trading minutes will be less than 1 + bi during the
1008+
# period between a session close and one bi prior to that close (unless
1009+
# calendar 24h)
1010+
assert (1 + bi.as_minutes) >= min(len_mins)
10041011

10051012
def test_prices_us(self, pricess):
10061013
"""Verify return from specific fixture."""

0 commit comments

Comments
 (0)