Esempio n. 1
0
    def test_deserializing_no_value(self, operator, registry, tmpdir,
                                    serializer):
        slot = JSONSerialSlot(operator.TestSlot,
                              obj_class=MyObj,
                              registry=registry)

        with h5py.File(str(tmpdir / "test.h5"), "a") as f:
            group = f.create_group("test")
            slot.deserialize(group)
            assert not operator.TestSlot.ready()
Esempio n. 2
0
    def test_deserializing(self, operator, registry, tmpdir, serializer):
        slot = JSONSerialSlot(operator.TestSlot,
                              obj_class=MyObj,
                              registry=registry)

        with h5py.File(str(tmpdir / "test.h5"), "a") as f:
            group = f.create_group("test")
            group.attrs["TestSlot"] = '{"val": 14, "__serializer_version": 1}'
            slot.deserialize(group)
            assert operator.TestSlot.ready()
            assert MyObj(14) == operator.TestSlot.value
Esempio n. 3
0
    def test_serializing(self, operator, registry, tmpdir, serializer):
        operator.TestSlot.setValue(MyObj(42))
        slot = JSONSerialSlot(operator.TestSlot,
                              obj_class=MyObj,
                              registry=registry)

        with h5py.File(str(tmpdir / "test.h5"), "a") as f:
            group = f.create_group("test")
            slot.serialize(group)
            assert group.attrs[
                "TestSlot"] == '{"val": 42, "__serializer_version": 1}'
Esempio n. 4
0
    def __init__(self, topLevelOperator, projectFileGroupName):
        self.VERSION = 1

        slots = [
            SerialListSlot(topLevelOperator.LabelNames),
            SerialListSlot(topLevelOperator.LabelColors, transform=lambda x: tuple(x.flat)),
            SerialListSlot(topLevelOperator.PmapColors, transform=lambda x: tuple(x.flat)),
            JSONSerialSlot(topLevelOperator.ModelInfo, obj_class=ModelInfo),
            SerialBlockSlot(
                topLevelOperator.LabelImages,
                topLevelOperator.LabelInputs,
                topLevelOperator.NonzeroLabelBlocks,
                name="LabelSets",
                subname="labels{:03d}",
                selfdepends=False,
                shrink_to_bb=True,
            ),
            BinarySlot(topLevelOperator.ModelBinary),
        ]

        super().__init__(projectFileGroupName, slots)
Esempio n. 5
0
 def test_serial_slot_raises_if_instantiated_with_unknown_type(
         self, operator, registry):
     with pytest.raises(ValueError):
         JSONSerialSlot(operator.TestSlot,
                        obj_class=MyObj,
                        registry=registry)