Skip to content

Commit 54158d6

Browse files
committed
add flagrantly failing test for consistent parameter docstrings
1 parent a788a7f commit 54158d6

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

tests/test_api/test_synchronous.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
11
from __future__ import annotations
22

3+
from dataclasses import dataclass
34
from typing import Final
45

56
import pytest
67
from numpydoc.docscrape import NumpyDocString
78

89
from zarr.api import asynchronous, synchronous
910

11+
12+
@dataclass(frozen=True, slots=True)
13+
class Param:
14+
name: str
15+
desc: tuple[str, ...]
16+
type: str
17+
18+
19+
all_docstrings: dict[str, NumpyDocString] = {}
20+
21+
for name in asynchronous.__all__:
22+
obj = getattr(asynchronous, name)
23+
if callable(obj) and obj.__doc__ is not None:
24+
all_docstrings[f"asynchronous.{name}"] = NumpyDocString(obj.__doc__)
25+
26+
for name in synchronous.__all__:
27+
obj = getattr(synchronous, name)
28+
if callable(obj) and obj.__doc__ is not None:
29+
all_docstrings[f"synchronous.{name}"] = NumpyDocString(obj.__doc__)
30+
1031
MATCHED_EXPORT_NAMES: Final[tuple[str, ...]] = tuple(
1132
sorted(set(synchronous.__all__) | set(asynchronous.__all__))
1233
)
@@ -16,7 +37,7 @@
1637

1738

1839
@pytest.mark.parametrize("callable_name", MATCHED_CALLABLE_NAMES)
19-
def test_create_docstrings(callable_name: str) -> None:
40+
def test_docstring_match(callable_name: str) -> None:
2041
"""
2142
Tests that the docstrings for the sync and async define identical parameters.
2243
"""
@@ -28,3 +49,34 @@ def test_create_docstrings(callable_name: str) -> None:
2849
params_a = NumpyDocString(callable_a.__doc__)["Parameters"]
2950
params_b = NumpyDocString(callable_b.__doc__)["Parameters"]
3051
assert params_a == params_b
52+
53+
54+
@pytest.mark.parametrize(
55+
"parameter_name",
56+
[
57+
"store",
58+
"path",
59+
"filters",
60+
"codecs",
61+
"compressors",
62+
"compressor",
63+
"chunks",
64+
"shape",
65+
"dtype",
66+
"data_type",
67+
"fill_value",
68+
],
69+
)
70+
def test_docstring_consistent_parameters(parameter_name: str) -> None:
71+
"""
72+
Tests that callable exports from ``zarr.api.synchronous`` and ``zarr.api.asynchronous``
73+
document the same parameters consistently.
74+
"""
75+
matches: dict[str, Param] = {}
76+
for name in all_docstrings:
77+
docstring = all_docstrings[name]
78+
param_dict = {d.name: d for d in docstring["Parameters"]}
79+
if parameter_name in param_dict:
80+
val = param_dict[parameter_name]
81+
matches[name] = Param(name=val.name, desc=tuple(val.desc), type=val.type)
82+
assert len(set(matches.values())) == 1

0 commit comments

Comments
 (0)