-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ability to serialize model_collection
- Loading branch information
Showing
5 changed files
with
89 additions
and
3 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,72 @@ | ||
import unittest | ||
|
||
from easyreflectometry.experiment.model import Model | ||
from easyreflectometry.experiment.model_collection import ModelCollection | ||
|
||
|
||
class TestModelCollection(unittest.TestCase): | ||
def test_default(self): | ||
# When Then | ||
collection = ModelCollection() | ||
|
||
# Expect | ||
assert collection.name == 'EasyModels' | ||
assert collection.interface is None | ||
assert len(collection) == 2 | ||
assert collection[0].name == 'EasyModel' | ||
assert collection[1].name == 'EasyModel' | ||
|
||
def test_from_pars(self): | ||
# When | ||
model_1 = Model(name='Model1') | ||
model_2 = Model(name='Model2') | ||
model_3 = Model(name='Model3') | ||
|
||
# Then | ||
collection = ModelCollection(model_1, model_2, model_3) | ||
|
||
# Expect | ||
assert collection.name == 'EasyModels' | ||
assert collection.interface is None | ||
assert len(collection) == 3 | ||
assert collection[0].name == 'Model1' | ||
assert collection[1].name == 'Model2' | ||
assert collection[2].name == 'Model3' | ||
|
||
def test_add_model(self): | ||
# When | ||
model_1 = Model(name='Model1') | ||
model_2 = Model(name='Model2') | ||
|
||
# Then | ||
collection = ModelCollection(model_1) | ||
collection.add_model(model_2) | ||
|
||
# Expect | ||
assert len(collection) == 2 | ||
assert collection[0].name == 'Model1' | ||
assert collection[1].name == 'Model2' | ||
|
||
def test_delete_model(self): | ||
# When | ||
model_1 = Model(name='Model1') | ||
model_2 = Model(name='Model2') | ||
|
||
# Then | ||
collection = ModelCollection(model_1, model_2) | ||
collection.remove_model(0) | ||
|
||
# Expect | ||
assert len(collection) == 1 | ||
assert collection[0].name == 'Model2' | ||
|
||
def test_as_dict(self): | ||
# When | ||
model_1 = Model(name='Model1') | ||
collection = ModelCollection(model_1) | ||
|
||
# Then | ||
dict_repr = collection.as_dict() | ||
|
||
# Expect | ||
assert dict_repr['data'][0]['resolution_function'] == {'smearing': 'PercentageFhwm', 'constant': 5.0} |