Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TST/CI: fixes and workarounds for various API issues
Browse files Browse the repository at this point in the history
theOehrly committed Jul 25, 2024

Verified

This commit was signed with the committer’s verified signature.
theOehrly Philipp Schaefer
1 parent 9763d1a commit 5246743
Showing 4 changed files with 18 additions and 8 deletions.
8 changes: 5 additions & 3 deletions docs/ergast.rst
Original file line number Diff line number Diff line change
@@ -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
@@ -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
9 changes: 8 additions & 1 deletion fastf1/req.py
Original file line number Diff line number Diff line change
@@ -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):
3 changes: 3 additions & 0 deletions fastf1/tests/test_cache.py
Original file line number Diff line number Diff line change
@@ -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
@@ -58,6 +59,8 @@ def _test_cache_used_and_clear(tmpdir):
content = fobj.read()
mocker.get('https://ergast.com/api/f1/2020/5.json',
content=content, status_code=200)
mocker.get('http://api.jolpi.ca/ergast/f1/2020/5.json',
content=content, status_code=200)

with open('fastf1/testing/reference_data/2020_05_FP2/'
'ergast_race_result.raw', 'rb') as fobj:
6 changes: 2 additions & 4 deletions fastf1/tests/test_events.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5246743

Please sign in to comment.