-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add a test file for model instantiation (#12)
* test: add a test file for model instantiation * feat: minor updates * fix * fix
- Loading branch information
Showing
7 changed files
with
75 additions
and
28 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import pytest | ||
|
||
from pydiffuser.models import CONFIG_REGISTRY, MODEL_REGISTRY | ||
|
||
|
||
@pytest.fixture | ||
def config_dict(): | ||
return CONFIG_REGISTRY | ||
|
||
|
||
@pytest.fixture | ||
def model_dict(): | ||
return MODEL_REGISTRY |
This file was deleted.
Oops, something went wrong.
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,43 @@ | ||
from inspect import signature | ||
|
||
import pytest | ||
|
||
from pydiffuser.models.core.base import MODEL_KWARGS | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"name", | ||
[ | ||
("abp"), | ||
("aoup"), | ||
("bm"), | ||
("levy"), | ||
("mips"), | ||
("rtp"), | ||
("smoluchowski"), | ||
("vicsek"), | ||
], | ||
) | ||
def test_models(config_dict, model_dict, name): | ||
config = config_dict[name]() | ||
model = model_dict[name].from_config(config=config) # instantiation from config | ||
ens = model.generate() | ||
shape = (config.realization, config.length, config.dimension) | ||
assert ens.microstate.shape == shape | ||
|
||
ens = model.generate(realization=5, length=50, dimension=2) | ||
with pytest.raises(AssertionError): | ||
assert ens.microstate.shape == (5, 50, 2) | ||
assert ens.microstate.shape == shape | ||
|
||
kwargs = config_dict[name].show_fields() | ||
params = list(signature(model_dict[name].__init__).parameters.keys()) | ||
args = ( | ||
[kwargs[param] for param in params[1:]] | ||
if MODEL_KWARGS not in params | ||
else ([kwargs[param] for param in params[1:-1]]) | ||
) | ||
model_v2 = model_dict[name](*args) # instantiation without config | ||
|
||
ens_v2 = model_v2.generate(realization=5, length=50, dimension=2) | ||
assert ens_v2.microstate.shape == (5, 50, 2) |