-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose driver base classes via API (#523)
- Loading branch information
1 parent
2119d54
commit 7c0a5a7
Showing
5 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
``uwtools.api.driver`` | ||
====================== | ||
|
||
.. automodule:: uwtools.api.driver | ||
:inherited-members: | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ API | |
chgres_cube | ||
config | ||
esg_grid | ||
driver | ||
file | ||
filter_topo | ||
fv3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
API access to the ``uwtools`` driver base classes. | ||
""" | ||
|
||
import importlib | ||
import sys | ||
|
||
_CLASSNAMES = [ | ||
"Assets", | ||
"AssetsCycleBased", | ||
"AssetsCycleAndLeadtimeBased", | ||
"AssetsTimeInvariant", | ||
"Driver", | ||
"DriverCycleBased", | ||
"DriverCycleAndLeadtimeBased", | ||
"DriverTimeInvariant", | ||
] | ||
|
||
|
||
def _add_classes(): | ||
m = importlib.import_module("uwtools.drivers.driver") | ||
for classname in _CLASSNAMES: | ||
setattr(sys.modules[__name__], classname, getattr(m, classname)) | ||
__all__.append(classname) | ||
|
||
|
||
__all__: list[str] = [] | ||
_add_classes() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# pylint: disable=missing-function-docstring,protected-access | ||
|
||
from inspect import isclass, ismodule | ||
|
||
from pytest import mark | ||
|
||
from uwtools.api import driver as driver_api | ||
from uwtools.drivers import driver as driver_lib | ||
|
||
|
||
@mark.parametrize("classname", driver_api._CLASSNAMES) | ||
def test_driver(classname): | ||
assert getattr(driver_api, classname) is getattr(driver_lib, classname) | ||
|
||
|
||
def test_public_attributes(): | ||
# Check that the module is not accidentally exposing unexpected public attributes. Ignore | ||
# private attributes and imported modules and assert that what remains is an intentionally | ||
# exposed (driver) class. | ||
for name in dir(driver_api): | ||
obj = getattr(driver_api, name) | ||
if name.startswith("_") or ismodule(obj): | ||
continue | ||
assert isclass(obj) | ||
assert name in driver_api._CLASSNAMES |