Files
specklepy/tests/test_base.py
T
Gergő Jedlicska 00c1e378d5 feat(base model and deserialization): base model subclasses can now be automatically deserialized
Subclassing types of Base are stored in a class attribute that can be looked up via the
`speckle_type`.

fix #50
2021-02-13 10:19:12 +01:00

41 lines
1.0 KiB
Python

import pytest
from speckle.objects.base import Base
from speckle.api import operations
@pytest.mark.parametrize(
"invalid_prop_name",
[
(""),
("@"),
("@@wow"),
("this.is.bad"),
("super/bad"),
],
)
def test_empty_prop_names(invalid_prop_name: str) -> None:
base = Base()
with pytest.raises(ValueError):
base[invalid_prop_name] = "🐛️"
class FakeBase(Base):
"""Just a test class type."""
foo: str = ""
def test_new_type_registration() -> None:
"""Test if a new subclass is registered into the type register."""
assert Base.get_registered_type("FakeBase") == FakeBase
assert Base.get_registered_type("🐺️") is None
def test_fake_base_serialization() -> None:
fake_model = FakeBase(foo="bar")
serialized = operations.serialize(fake_model)
deserialized = operations.deserialize(serialized)
assert fake_model.get_id() == deserialized.get_id()
# assert isinstance(base.test_bases[0], Base)
# assert base["@detach"].name == deserialized["@detach"].name