Skip to content

Commit

Permalink
TST/CI: fixes and workarounds for various API issues
Browse files Browse the repository at this point in the history
  • Loading branch information
theOehrly committed Jul 25, 2024
1 parent 9763d1a commit 93bfdde
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
8 changes: 5 additions & 3 deletions docs/ergast.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,19 @@ 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``
of the response:

.. doctest::

>>> standings.description
>>> standings.description # doctest: +SKIP
season round
0 1958 11
1 1959 9
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion fastf1/req.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions fastf1/tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions fastf1/tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 93bfdde

Please sign in to comment.