From 087f27ff8ff648bade9b4248cf21fe40319f41ff Mon Sep 17 00:00:00 2001 From: Marcus Read Date: Thu, 15 Feb 2024 22:05:54 +0000 Subject: [PATCH] Fixes for new tests Fixes for new `test_to_csv` and `test_request_from_left_limit` to prevent flaky behavior. --- tests/test_base_prices.py | 4 +++- tests/test_yahoo.py | 15 +++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/test_base_prices.py b/tests/test_base_prices.py index da9f43d..bda1002 100644 --- a/tests/test_base_prices.py +++ b/tests/test_base_prices.py @@ -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 @@ -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): diff --git a/tests/test_yahoo.py b/tests/test_yahoo.py index 4772211..fe54fce 100644 --- a/tests/test_yahoo.py +++ b/tests/test_yahoo.py @@ -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 @@ -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") @@ -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") @@ -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."""