-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add dimensions parameter to plugin interfaces; test plugin system (#364)
- Loading branch information
1 parent
a0b0aa0
commit 7b8ef3e
Showing
6 changed files
with
101 additions
and
19 deletions.
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,71 @@ | ||
import pytest | ||
|
||
from veros.plugins import load_plugin | ||
from veros.routines import veros_routine | ||
from veros.state import get_default_state | ||
from veros.variables import Variable | ||
from veros.settings import Setting | ||
|
||
|
||
@pytest.fixture | ||
def fake_plugin(): | ||
class FakePlugin: | ||
pass | ||
|
||
def run_setup(state): | ||
plugin._setup_ran = True | ||
|
||
def run_main(state): | ||
plugin._main_ran = True | ||
|
||
plugin = FakePlugin() | ||
plugin.__name__ = "foobar" | ||
plugin._setup_ran = False | ||
plugin._main_ran = False | ||
plugin.__VEROS_INTERFACE__ = { | ||
"name": "foo", | ||
"setup_entrypoint": run_setup, | ||
"run_entrypoint": run_main, | ||
"settings": dict(mydimsetting=Setting(15, int, "bar")), | ||
"variables": dict(myvar=Variable("myvar", ("xt", "yt", "mydim"))), | ||
"dimensions": dict(mydim="mydimsetting"), | ||
"diagnostics": [], | ||
} | ||
yield plugin | ||
|
||
|
||
def test_load_plugin(fake_plugin): | ||
plugin_interface = load_plugin(fake_plugin) | ||
assert plugin_interface.name == "foo" | ||
|
||
|
||
def test_state_plugin(fake_plugin): | ||
plugin_interface = load_plugin(fake_plugin) | ||
state = get_default_state(plugin_interfaces=plugin_interface) | ||
assert "mydimsetting" in state.settings | ||
assert "mydim" in state.dimensions | ||
assert state.dimensions["mydim"] == state.settings.mydimsetting | ||
state.initialize_variables() | ||
assert "myvar" in state.variables | ||
assert state.variables.myvar.shape == (4, 4, state.settings.mydimsetting) | ||
|
||
|
||
def test_run_plugin(fake_plugin): | ||
from veros.setups.acc_basic import ACCBasicSetup | ||
|
||
class FakeSetup(ACCBasicSetup): | ||
__veros_plugins__ = (fake_plugin,) | ||
|
||
@veros_routine | ||
def set_diagnostics(self, state): | ||
pass | ||
|
||
setup = FakeSetup(override=dict(dt_tracer=100, runlen=100)) | ||
|
||
assert not fake_plugin._setup_ran | ||
setup.setup() | ||
assert fake_plugin._setup_ran | ||
|
||
assert not fake_plugin._main_ran | ||
setup.run() | ||
assert fake_plugin._main_ran |
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
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
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