Skip to content

Commit

Permalink
Fixes for new tests
Browse files Browse the repository at this point in the history
Fixes for new `test_to_csv` and `test_request_from_left_limit` to
prevent flaky behavior.
  • Loading branch information
maread99 committed Feb 15, 2024
1 parent 7376d0b commit 087f27f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion tests/test_base_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -6361,9 +6361,11 @@ def assert_output_as_original_files(paths: list[Path]):
# verify can pass non-base interval
clean_temp_test_dir()
df = prices.get("10T")
df = df[df.columns.sort_values()]
paths = prices.to_csv(temp_dir, "10T")
prices_reloaded = csv.PricesCsv(temp_dir, symbols, calendars)
df_reloaded = prices_reloaded.get("10T")
df_reloaded = df_reloaded[df_reloaded.columns.sort_values()]
assert_frame_equal(df, df_reloaded)

# verify can pass get_params
Expand All @@ -6381,7 +6383,7 @@ def assert_output_as_original_files(paths: list[Path]):
clean_temp_test_dir()
match = re.escape(
"It was not possible to export prices as an error was raised when prices were"
f" requested for interval {TDInterval.T1}. The error is included at the top of"
f" requested for interval {prices.bis.T1}. The error is included at the top of"
" the traceback.\nNB prices have not been exported for any interval."
)
with pytest.raises(errors.PricesUnavailableForExport, match=match):
Expand Down
15 changes: 11 additions & 4 deletions tests/test_yahoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ class TestRequestDataIntraday:
@pytest.mark.filterwarnings("ignore:Prices from Yahoo are missing for:UserWarning")
@pytest.mark.filterwarnings("ignore:A value is trying to be set on a:FutureWarning")
@pytest.mark.filterwarnings("ignore:'S' is deprecated:FutureWarning")
def test_request_from_left_limit(self):
def test_request_from_left_limit(self, one_min):
"""Test data requests from left limit.
The Yahoo API appears to exhibit flaky behaviour when requesting
Expand Down Expand Up @@ -953,8 +953,10 @@ def test_request_from_left_limit(self):
if not rl < table.pt.last_ts:
# <= bi.as_minutes as rl is 'now' + bi and that bi can all be
# trading minutes beyond the right of the last indice
# + one_min to provide for processing between getting calendar
# and evaluating minutes
num_mins = len(cal.minutes_in_range(table.pt.last_ts, rl))
assert num_mins <= bi.as_minutes
assert num_mins <= bi.as_minutes + 1
else:
ll = prices.limit_daily
assert table.pt.first_ts == prices.cc.date_to_session(ll, "next")
Expand All @@ -979,8 +981,10 @@ def test_request_from_left_limit(self):
if not rl < table.pt.last_ts:
# <= bi.as_minutes as rl is 'now' + bi and that bi can all be
# trading minutes beyond the right of the last indice
# + one_min to provide for processing between getting calendar
# and evaluating minutes
num_mins = len(cal.minutes_in_range(table.pt.last_ts, rl))
assert num_mins <= bi.as_minutes
assert num_mins <= bi.as_minutes + 1
else:
ll = prices.limit_daily
assert table.pt.first_ts == prices.cc.date_to_session(ll, "next")
Expand All @@ -1000,7 +1004,10 @@ def verify_limit_intraday_bi(self, prices: m.PricesYahoo):
len_mins = []
for cal in prices.calendars_unique:
len_mins.append(len(cal.minutes_in_range(prices.limits[bi][0], limit)))
assert (1 + bi.as_minutes) == min(len_mins)
# NB the number of trading minutes will be less than 1 + bi during the
# period between a session close and one bi prior to that close (unless
# calendar 24h)
assert (1 + bi.as_minutes) >= min(len_mins)

def test_prices_us(self, pricess):
"""Verify return from specific fixture."""
Expand Down

0 comments on commit 087f27f

Please sign in to comment.