diff --git a/tests/conftest.py b/tests/conftest.py index e1db2a3..3524bc9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -75,6 +75,17 @@ def _pickle_new_prices(symbols: str, path: pathlib.Path): file.close() +CAL_START = "1986-03-13" +XLON = xcals.get_calendar("XLON", start=CAL_START) +CAL_MAPPING = { + "AZN.L": XLON, + "BARC.L": XLON, + "MSFT": xcals.get_calendar("XNYS", start=CAL_START), + "9988.HK": xcals.get_calendar("XHKG", start=CAL_START), +} +DELAY_MAPPING = {"AZN.L": 15, "BARC.L": 15, "MSFT": 0, "9988.HK": 15} + + def _unpickle_prices(path: pathlib.Path, class_mocker) -> mp.PricesYahoo: """Reconstruct an instance of `PricesYahoo` to use in testing""" file = open(path, "rb") @@ -87,7 +98,9 @@ def _mock_now(*args, **kwargs) -> pd.Timestamp: # reconstruct each of the data instances symbols = pickle.load(file) - prices = mp.PricesYahoo(symbols) + calendars = {s: CAL_MAPPING[s] for s in symbols} + delays = {s: DELAY_MAPPING[s] for s in symbols} + prices = mp.PricesYahoo(symbols, calendars=calendars, delays=delays) for bi in prices.bis: data = prices._pdata[bi] diff --git a/tests/test_analysis.py b/tests/test_analysis.py index c649830..d308e11 100644 --- a/tests/test_analysis.py +++ b/tests/test_analysis.py @@ -298,13 +298,16 @@ def tz(self) -> abc.Iterator[ZoneInfo]: yield ZoneInfo("Europe/London") def test_constructor_raises(self): + prices = mp.PricesYahoo( + "AZN.L, MSFT", calendars=["XLON", "XNYS"], delays=[15, 0] + ) msg = re.escape( "The Analysis class requires a `prices` instance that gets" "price data for a single symbol, although the past instance" " gets prices for 2: ['AZN.L', 'MSFT']." ) with pytest.raises(ValueError, match=msg): - analysis.Analysis(mp.PricesYahoo("AZN.L, MSFT")) + analysis.Analysis(prices) def test_prices(self, analy, prices_analysis): assert analy.prices is prices_analysis @@ -1399,13 +1402,14 @@ def tz(self) -> abc.Iterator[ZoneInfo]: yield ZoneInfo("America/New_York") def test_constructor_raises(self): + prices = mp.PricesYahoo("MSFT", calendars="XNYS", delays=0) msg = re.escape( "The Compare class requires a `prices` instance that gets" "price data for multiple symbols, although the past instance" "gets prices for only one: MSFT." ) with pytest.raises(ValueError, match=msg): - analysis.Compare(mp.PricesYahoo("MSFT")) + analysis.Compare(prices) def test_prices(self, analy, prices_compare): assert analy.prices is prices_compare