1
0
fin-defs/test/test_data.py

32 lines
995 B
Python
Raw Normal View History

2024-05-27 21:03:16 +00:00
import pytest
import fin_defs
2024-10-27 16:24:12 +00:00
VALID_STOCK_TICKERS = ['TEST123', '123', 'TEST.EUR']
BAD_STOCK_TICKERS = ['TEST:EUR', 'EUR:TEST']
2024-05-27 21:03:16 +00:00
2024-10-27 16:24:12 +00:00
@pytest.mark.parametrize('ticker', VALID_STOCK_TICKERS)
2024-09-01 16:05:05 +00:00
def test_valid_tickers(ticker: str):
2024-10-27 16:24:12 +00:00
asset = fin_defs.Stock(ticker, exchange=fin_defs.EXCHANGES_BY_IDS['NYSE'])
assert asset.names() is not None
assert asset.to_polygon_id() is not None
2024-09-01 17:37:28 +00:00
2024-09-01 16:05:05 +00:00
2024-10-27 16:24:12 +00:00
@pytest.mark.parametrize('ticker', BAD_STOCK_TICKERS)
2024-09-01 16:05:05 +00:00
def test_bad_tickers(ticker: str):
2024-10-27 15:18:21 +00:00
with pytest.raises(ValueError, match='ticker was not in correct format:.*'):
2024-09-01 17:37:28 +00:00
fin_defs.Stock(ticker, exchange=fin_defs.EXCHANGES_BY_IDS['NYSE'])
2024-05-27 21:03:16 +00:00
2024-10-27 16:24:12 +00:00
@pytest.mark.parametrize('ticker', BAD_STOCK_TICKERS)
2024-05-27 21:03:16 +00:00
def test_crypto_tickers(ticker):
2024-10-27 16:24:12 +00:00
asset = fin_defs.CryptoCurrency(ticker, 'not-known')
assert asset.names() is not None
assert asset.to_polygon_id().startswith('X:')
2024-05-27 21:03:16 +00:00
def test_str():
2024-10-27 15:18:21 +00:00
asset = fin_defs.Stock('NVO', fin_defs.EXCHANGES_BY_IDS['NYSE'])
assert str(asset) == 'stock:NVO.XNYS'