コード例 #1
0
ファイル: test_base.py プロジェクト: eraschle/speckle-py
def test_fake_base_serialization() -> None:
    fake_model = FakeModel(foo="bar")

    serialized = operations.serialize(fake_model)
    deserialized = operations.deserialize(serialized)

    assert fake_model.get_id() == deserialized.get_id()
コード例 #2
0
    def test_serialize(self, base):
        serialized = operations.serialize(base)
        deserialized = operations.deserialize(serialized)

        assert base.get_id() == deserialized.get_id()
        assert base.units == "mm"
        assert isinstance(base.test_bases[0], Base)
        assert base["@detach"].name == deserialized["@detach"].name
コード例 #3
0
def test_serialized_brep_attributes(brep: Brep):
    transport = MemoryTransport()
    serialized = operations.serialize(brep, [transport])
    serialized_dict = json.loads(serialized)

    removed_keys = ["Surfaces", "Curve3D", "Curve2D", "Vertices", "Trims"]

    for k in removed_keys:
        assert k not in serialized_dict.keys()
コード例 #4
0
    def test_serialize(self, base):
        serialized = operations.serialize(base)
        deserialized = operations.deserialize(serialized)

        assert base.get_id() == deserialized.get_id()
        assert base.units == "mm"
        assert isinstance(base.test_bases[0], Base)
        assert base["@revit_thing"].speckle_type == "SpecialRevitFamily"
        assert base["@detach"].name == deserialized["@detach"].name
コード例 #5
0
    def test_detaching(self, mesh):
        transport = MemoryTransport()
        serialized = operations.serialize(mesh, [transport])
        deserialized = operations.deserialize(serialized, transport)

        serialized_dict = json.loads(serialized)

        assert serialized_dict["detach_this"]["speckle_type"] == "reference"
        assert serialized_dict["@detach"]["speckle_type"] == "reference"
        assert serialized_dict["origin"]["speckle_type"] == "reference"
        assert serialized_dict["@detached_list"][-1]["speckle_type"] == "reference"
        assert mesh.get_id() == deserialized.get_id()
コード例 #6
0
    def test_chunking(self, mesh):
        transport = MemoryTransport()
        serialized = operations.serialize(mesh, [transport])
        deserialized = operations.deserialize(serialized, transport)

        serialized_dict = json.loads(serialized)

        assert len(serialized_dict["vertices"]) == 3
        assert len(serialized_dict["@(100)colours"]) == 3
        assert len(serialized_dict["@()default_chunk"]) == 1
        assert serialized_dict["vertices"][0]["speckle_type"] == "reference"
        assert serialized_dict["@(100)colours"][0]["speckle_type"] == "reference"
        assert serialized_dict["@()default_chunk"][0]["speckle_type"] == "reference"
        assert mesh.get_id() == deserialized.get_id()
コード例 #7
0
def test_transform_serialisation(transform: Transform):
    serialized = operations.serialize(transform)
    deserialized = operations.deserialize(serialized)

    assert transform.get_id() == deserialized.get_id()
コード例 #8
0
class SpeckleSub(ExampleSub, speckle_type="custom_speckle_sub"):
    """
    Example custom type name registration.

    This is an optional feature.
    The default value of the speckle_type is generated from the name of the class, but
    optionally it may be overridden. This is useful, since the speckle_type has to be
    unique for each subclass of speckle Base.
    """

    magic: str = "trick"


if __name__ == "__main__":
    # example usage
    custom_sub = SpeckleSub(
        foo=123,
        magic="trick",
        bar="baric",
        extra=123,
    )
    # support for dynamic attributes
    custom_sub.extra_extra = "what is this?"
    debug(custom_sub.json())

    serialized = operations.serialize(custom_sub)
    deserialized = operations.deserialize(serialized)
    # the only difference should be between the two data is that the deserialized
    # instance id attribute is not None.
    debug(deserialized.json())