11from typing import AsyncIterator
22
33import pytest
4- from aiohttp .client_exceptions import ClientError
54
65from quantflow .data .fed import FederalReserve
76from quantflow .data .fiscal_data import FiscalData
87from quantflow .data .fmp import FMP
8+ from quantflow_tests .utils import skip_network_issue
99
10- pytestmark = pytest . mark . skipif ( not FMP ().key , reason = "No FMP API key found" )
10+ skip_fmp = not FMP ().key
1111
1212
1313@pytest .fixture
@@ -16,49 +16,46 @@ async def fmp() -> AsyncIterator[FMP]:
1616 yield fmp
1717
1818
19+ @pytest .mark .skipif (skip_fmp , reason = "No FMP API key found" )
1920def test_client (fmp : FMP ) -> None :
2021 assert fmp .url
2122 assert fmp .key
2223
2324
25+ @pytest .mark .skipif (skip_fmp , reason = "No FMP API key found" )
2426async def test_historical (fmp : FMP ) -> None :
2527 df = await fmp .prices ("BTCUSD" , fmp .freq .one_hour )
2628 assert df ["close" ] is not None
2729
2830
31+ @pytest .mark .skipif (skip_fmp , reason = "No FMP API key found" )
2932async def test_dividends (fmp : FMP ) -> None :
3033 data = await fmp .dividends ()
3134 assert data is not None
3235
3336
37+ @skip_network_issue
3438async def test_fed_yc () -> None :
35- try :
36- async with FederalReserve () as fed :
37- df = await fed .yield_curves ()
38- assert df is not None
39- assert df .shape [0 ] > 0
40- assert df .shape [1 ] == 12
41- except (ConnectionError , ClientError ) as e :
42- pytest .skip (f"Skipping test_fed due to network issue: { e } " )
39+ async with FederalReserve () as fed :
40+ df = await fed .yield_curves ()
41+ assert df is not None
42+ assert df .shape [0 ] > 0
43+ assert df .shape [1 ] == 12
4344
4445
46+ @skip_network_issue
4547async def test_fed_rates () -> None :
46- try :
47- async with FederalReserve () as fed :
48- df = await fed .ref_rates ()
49- assert df is not None
50- assert df .shape [0 ] > 0
51- assert df .shape [1 ] == 2
52- except (ConnectionError , ClientError ) as e :
53- pytest .skip (f"Skipping test_fed due to network issue: { e } " )
48+ async with FederalReserve () as fed :
49+ df = await fed .ref_rates ()
50+ assert df is not None
51+ assert df .shape [0 ] > 0
52+ assert df .shape [1 ] == 2
5453
5554
55+ @skip_network_issue
5656async def __test_fiscal_data () -> None :
57- try :
58- async with FiscalData () as fd :
59- df = await fd .securities ()
60- assert df is not None
61- assert df .shape [0 ] > 0
62- assert df .shape [1 ] == 2
63- except (ConnectionError , ClientError ) as e :
64- pytest .skip (f"Skipping test_fed due to network issue: { e } " )
57+ async with FiscalData () as fd :
58+ df = await fd .securities ()
59+ assert df is not None
60+ assert df .shape [0 ] > 0
61+ assert df .shape [1 ] == 2
0 commit comments