32 lines
995 B
Python
32 lines
995 B
Python
import pytest
|
|
|
|
import fin_defs
|
|
|
|
VALID_STOCK_TICKERS = ['TEST123', '123', 'TEST.EUR']
|
|
BAD_STOCK_TICKERS = ['TEST:EUR', 'EUR:TEST']
|
|
|
|
|
|
@pytest.mark.parametrize('ticker', VALID_STOCK_TICKERS)
|
|
def test_valid_tickers(ticker: str):
|
|
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
|
|
|
|
|
|
@pytest.mark.parametrize('ticker', BAD_STOCK_TICKERS)
|
|
def test_bad_tickers(ticker: str):
|
|
with pytest.raises(ValueError, match='ticker was not in correct format:.*'):
|
|
fin_defs.Stock(ticker, exchange=fin_defs.EXCHANGES_BY_IDS['NYSE'])
|
|
|
|
|
|
@pytest.mark.parametrize('ticker', BAD_STOCK_TICKERS)
|
|
def test_crypto_tickers(ticker):
|
|
asset = fin_defs.CryptoCurrency(ticker, 'not-known')
|
|
assert asset.names() is not None
|
|
assert asset.to_polygon_id().startswith('X:')
|
|
|
|
|
|
def test_str():
|
|
asset = fin_defs.Stock('NVO', fin_defs.EXCHANGES_BY_IDS['NYSE'])
|
|
assert str(asset) == 'stock:NVO.XNYS'
|