Skip to content

Commit 3ffed9b

Browse files
committed
test: bind canonical futures examples per client
1 parent 521fbae commit 3ffed9b

3 files changed

Lines changed: 26 additions & 12 deletions

File tree

‎oilpriceapi/async_resources.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,12 @@ class AsyncFuturesResource:
320320
Methods accept either a slug or a friendly contract code (``"BZ"``,
321321
``"CL"``, ``"NG"``, ...), normalized via
322322
:func:`normalize_futures_slug`.
323+
324+
Examples:
325+
>>> await client.futures.latest("brent")
326+
>>> await client.futures.latest("wti")
327+
>>> await client.futures.latest("gasoil")
328+
>>> await client.futures.latest("eu-carbon")
323329
"""
324330

325331
def __init__(self, client):

‎oilpriceapi/resources/futures.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
Valid slugs: ``brent``, ``wti``, ``gasoil``, ``natural-gas``,
1414
``ttf-gas``, ``lng-jkm``, ``eu-carbon``, ``uk-carbon`` (+ continuous slugs
1515
``continuous/brent`` and ``continuous/wti``).
16+
17+
Examples:
18+
>>> client.futures.latest("brent")
19+
>>> client.futures.latest("wti")
20+
>>> client.futures.latest("gasoil")
21+
>>> client.futures.latest("eu-carbon")
1622
"""
1723

1824
from datetime import date, datetime

‎tests/test_release_readiness.py‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,20 @@ def test_examples_defer_mutable_allowances_to_product_facts() -> None:
8888

8989

9090
def test_packaged_futures_examples_prefer_instrument_generic_slugs() -> None:
91-
futures_sources = "\n".join(
92-
(ROOT / path).read_text()
93-
for path in (
94-
"oilpriceapi/resources/futures.py",
95-
"oilpriceapi/async_resources.py",
96-
)
97-
)
98-
99-
for example_line in re.findall(r"(?m)^\s*(?:>>>|\.\.\.)\s+.*$", futures_sources):
100-
assert not re.search(r"[\"'](?:ice|eua)-", example_line)
101-
assert 'client.futures.latest("brent")' in futures_sources
102-
assert 'client.futures.curve("wti")' in futures_sources
91+
for path in (
92+
"oilpriceapi/resources/futures.py",
93+
"oilpriceapi/async_resources.py",
94+
):
95+
source = (ROOT / path).read_text()
96+
example_lines = re.findall(r"(?m)^\s*(?:>>>|\.\.\.)\s+.*$", source)
97+
examples = "\n".join(example_lines)
98+
99+
for example_line in example_lines:
100+
assert not re.search(r"[\"'](?:ice|eua)-", example_line)
101+
for canonical_slug in ("brent", "wti", "gasoil", "eu-carbon"):
102+
assert canonical_slug in examples, (
103+
f"{path} examples omit {canonical_slug}"
104+
)
103105

104106

105107
def test_publish_gate_audits_and_installs_the_built_wheel() -> None:

0 commit comments

Comments
 (0)