-
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.
- Loading branch information
1 parent
c157980
commit ad7e43c
Showing
3 changed files
with
33 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "ampel-interface" | ||
version = "0.10.4.post0" | ||
version = "0.10.4.post1" | ||
description = "Base classes for the Ampel analysis platform" | ||
authors = ["Valery Brinnel"] | ||
maintainers = ["Jakob van Santen <[email protected]>"] | ||
|
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 |
---|---|---|
@@ -1,9 +1,37 @@ | ||
from copy import deepcopy | ||
|
||
import pytest | ||
from pydantic import ValidationError | ||
|
||
from ampel.alert.AmpelAlert import AmpelAlert | ||
from ampel.base.AmpelBaseModel import AmpelBaseModel | ||
from ampel.protocol.AmpelAlertProtocol import AmpelAlertProtocol | ||
|
||
|
||
def test_protocol(): | ||
alert = AmpelAlert(0, 0, []) | ||
assert isinstance(alert, AmpelAlertProtocol), "dataclass fields recognized as protocol" | ||
assert isinstance( | ||
alert, AmpelAlertProtocol | ||
), "dataclass fields recognized as protocol" | ||
|
||
assert alert.tag is None, "defaults are populated" | ||
|
||
class Model(AmpelBaseModel): | ||
alerts: list[AmpelAlertProtocol] | ||
|
||
# this works: AmpelAlert is a structural sub-type of AmpelAlertProtocol | ||
m = Model( | ||
alerts=[AmpelAlert(id=0, stock="stockystock", datapoints=[{"id": 0}])] | ||
) | ||
assert isinstance( | ||
m.model_dump(mode="json")["alerts"][0], dict | ||
), "dataclass serialized as dict" | ||
# this does not: pydantic does not know how to deserialize a dict to AmpelAlertProtocol | ||
with pytest.raises(ValidationError): | ||
Model(**m.model_dump(mode="json")) | ||
|
||
|
||
def test_hash(): | ||
"""AmpelAlert should be hashable""" | ||
alert = AmpelAlert(id=0, stock="stockystock", datapoints=[{"id": 0}]) | ||
assert hash(alert) != hash(deepcopy(alert)), "hash is not the same after deepcopy" |