From 93bfddee53608a34b7275151a3f3f60eac5fb3fa Mon Sep 17 00:00:00 2001 From: theOehrly <23384863+theOehrly@users.noreply.github.com> Date: Thu, 25 Jul 2024 22:23:35 +0200 Subject: [PATCH] TST/CI: fixes and workarounds for various API issues --- docs/ergast.rst | 8 +++++--- fastf1/req.py | 9 ++++++++- fastf1/tests/test_cache.py | 5 +++-- fastf1/tests/test_events.py | 6 ++---- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/docs/ergast.rst b/docs/ergast.rst index a2b05eef5..34d096b0f 100644 --- a/docs/ergast.rst +++ b/docs/ergast.rst @@ -206,9 +206,11 @@ response. When 'pandas' is selected as result type, these endpoints return a :class:`~fastf1.ergast.interface.ErgastMultiResponse`. One such endpoint is the constructor standings endpoint. +.. TODO: the following doctests are skipped because of the broken Ergast API + .. doctest:: - >>> standings = ergast.get_constructor_standings() + >>> standings = ergast.get_constructor_standings() # doctest: +SKIP Called without any 'season' specifier, it returns standings for multiple seasons. An overview over the returned data is available as a ``.description`` @@ -216,7 +218,7 @@ of the response: .. doctest:: - >>> standings.description + >>> standings.description # doctest: +SKIP season round 0 1958 11 1 1959 9 @@ -237,7 +239,7 @@ The first element in ``.content`` is associated with the first row of the .. doctest:: - >>> standings.content[0] + >>> standings.content[0] # doctest: +SKIP position positionText ... constructorName constructorNationality 0 1 1 ... Vanwall British 1 2 2 ... Ferrari Italian diff --git a/fastf1/req.py b/fastf1/req.py index 57a198c5b..46cc669b7 100644 --- a/fastf1/req.py +++ b/fastf1/req.py @@ -110,7 +110,14 @@ class _SessionWithRateLimiting(requests.Session): # soft limit 4 calls/sec _CallsPerIntervalLimitRaise(200, 60*60, "ergast.com: 200 calls/h") # hard limit 200 calls/h - ] + ], + # general limits on all other APIs + re.compile(r"^https?://.+\..+"): [ + _MinIntervalLimitDelay(0.25), + # soft limit 4 calls/sec + _CallsPerIntervalLimitRaise(500, 60 * 60, "any API: 500 calls/h") + # hard limit 200 calls/h + ], } def send(self, request, **kwargs): diff --git a/fastf1/tests/test_cache.py b/fastf1/tests/test_cache.py index 5c0e04d0d..53f1905a5 100644 --- a/fastf1/tests/test_cache.py +++ b/fastf1/tests/test_cache.py @@ -2,6 +2,7 @@ import os import fastf1._api +import fastf1.ergast.interface import fastf1.testing from fastf1 import Cache from fastf1.logger import LoggingManager @@ -56,13 +57,13 @@ def _test_cache_used_and_clear(tmpdir): with open('fastf1/testing/reference_data/2020_05_FP2/' 'ergast_race.raw', 'rb') as fobj: content = fobj.read() - mocker.get('https://ergast.com/api/f1/2020/5.json', + mocker.get(f'{fastf1.ergast.interface.BASE_URL}/2020/5.json', content=content, status_code=200) with open('fastf1/testing/reference_data/2020_05_FP2/' 'ergast_race_result.raw', 'rb') as fobj: content = fobj.read() - mocker.get('https://ergast.com/api/f1/2020/5/results.json', + mocker.get(f'{fastf1.ergast.interface.BASE_URL}/2020/5/results.json', content=content, status_code=200) # rainy and short session, good for fast test/quick loading diff --git a/fastf1/tests/test_events.py b/fastf1/tests/test_events.py index 2efc5baf2..0d4d5f50a 100644 --- a/fastf1/tests/test_events.py +++ b/fastf1/tests/test_events.py @@ -237,10 +237,8 @@ def test_event_get_session_name(backend): assert event.get_session_name('Sprint') == 'Sprint' # Sprint Qualifying format introduced for 2024 - if ((backend == 'f1timing') - and (datetime.datetime.now() < datetime.datetime(2024, 4, 21))): - # disables this test until the data should be available - # TODO: remove early exit at any time after 2024/04/21 + if backend == 'f1timing': + # disables this test for the broken livetiming backend -> TODO return event = fastf1.get_event(2024, 5, backend=backend) assert event.year == 2024