1818 from types import ModuleType
1919
2020
21+ TESTED_MODULES = (griffe , griffecli )
22+ test_all_modules = pytest .mark .parametrize ("tested_module" , TESTED_MODULES )
23+
24+
25+ @pytest .fixture (name = "inventory" , scope = "module" )
26+ def _fixture_inventory () -> Inventory :
27+ inventory_file = Path (__file__ ).parent .parent / "site" / "objects.inv"
28+ if not inventory_file .exists ():
29+ pytest .skip ("The objects inventory is not available." ) # ty: ignore[call-non-callable]
30+ with inventory_file .open ("rb" ) as file :
31+ return Inventory .parse_sphinx (file )
32+
33+
2134def _load_modules (* modules : ModuleType ) -> griffe .GriffeLoader :
2235 loader = griffe .GriffeLoader (
2336 extensions = griffe .load_extensions (
@@ -92,15 +105,6 @@ def _get_public_objects(public_api: griffe.Module) -> list[griffe.Object | griff
92105 return list (_yield_public_objects (public_api , modulelevel = False , inherited = True , special = True ))
93106
94107
95- @pytest .fixture (name = "inventory" , scope = "module" )
96- def _fixture_inventory () -> Inventory :
97- inventory_file = Path (__file__ ).parent .parent / "site" / "objects.inv"
98- if not inventory_file .exists ():
99- pytest .skip ("The objects inventory is not available." ) # ty: ignore[call-non-callable]
100- with inventory_file .open ("rb" ) as file :
101- return Inventory .parse_sphinx (file )
102-
103-
104108def test_alias_proxies () -> None :
105109 """The Alias class has all the necessary methods and properties."""
106110 internal_api = _get_internal_api (griffe )
@@ -116,7 +120,7 @@ def test_alias_proxies() -> None:
116120 assert name in alias_members
117121
118122
119- @pytest . mark . parametrize ( "tested_module" , [ griffe , griffecli ])
123+ @test_all_modules
120124def test_exposed_objects (tested_module : ModuleType ) -> None :
121125 """All public objects in the internal API are exposed under `griffe`."""
122126 modulelevel_internal_objects = _get_modulelevel_internal_objects (_get_internal_api (tested_module ))
@@ -128,7 +132,7 @@ def test_exposed_objects(tested_module: ModuleType) -> None:
128132 assert not not_exposed , "Objects not exposed:\n " + "\n " .join (sorted (not_exposed ))
129133
130134
131- @pytest . mark . parametrize ( "tested_module" , [ griffe , griffecli ])
135+ @test_all_modules
132136def test_unique_names (tested_module : ModuleType ) -> None :
133137 """All internal objects have unique names."""
134138 modulelevel_internal_objects = _get_modulelevel_internal_objects (_get_public_api (tested_module ))
@@ -139,7 +143,7 @@ def test_unique_names(tested_module: ModuleType) -> None:
139143 assert not non_unique , "Non-unique names:\n " + "\n " .join (str (paths ) for paths in non_unique )
140144
141145
142- @pytest . mark . parametrize ( "tested_module" , [ griffe , griffecli ])
146+ @test_all_modules
143147def test_single_locations (tested_module : ModuleType ) -> None :
144148 """All objects have a single public location."""
145149
@@ -159,7 +163,7 @@ def _public_path(obj: griffe.Object | griffe.Alias) -> bool:
159163 )
160164
161165
162- @pytest . mark . parametrize ( "tested_module" , [ griffe , griffecli ])
166+ @test_all_modules
163167def test_api_matches_inventory (inventory : Inventory , tested_module : ModuleType ) -> None :
164168 """All public objects are added to the inventory."""
165169 ignore_names = {"__getattr__" , "__init__" , "__repr__" , "__str__" , "__post_init__" }
@@ -183,13 +187,12 @@ def test_api_matches_inventory(inventory: Inventory, tested_module: ModuleType)
183187
184188def test_inventory_matches_api (inventory : Inventory ) -> None :
185189 """The inventory doesn't contain any additional Python object."""
186- tested_modules = (griffe , griffecli )
187- loader = _load_modules (* tested_modules )
190+ loader = _load_modules (* TESTED_MODULES )
188191 not_in_api = []
189192 public_objects = []
190193 public_api_paths = set ()
191194
192- for tested_module in tested_modules :
195+ for tested_module in TESTED_MODULES :
193196 public_api = _get_public_api (tested_module , loader = loader )
194197 module_public_objects = _get_public_objects (public_api )
195198 public_api_paths .add (tested_module .__name__ )
@@ -206,7 +209,7 @@ def test_inventory_matches_api(inventory: Inventory) -> None:
206209 assert not not_in_api , msg .format (paths = "\n " .join (sorted (not_in_api )))
207210
208211
209- @pytest . mark . parametrize ( "tested_module" , [ griffe , griffecli ])
212+ @test_all_modules
210213def test_no_module_docstrings_in_internal_api (tested_module : ModuleType ) -> None :
211214 """No module docstrings should be written in our internal API.
212215
0 commit comments