Example #1
0
class TestTableMetaSerialization(unittest.TestCase):
    def setUp(self):
        self.sam = StringArrayMeta()
        self.serialized = OrderedDict()
        self.serialized["typeid"] = "malcolm:core/TableMeta:1.0"
        self.serialized["elements"] = dict(c1=self.sam.to_dict())
        self.serialized["description"] = "desc"
        self.serialized["tags"] = ()
        self.serialized["writeable"] = True
        self.serialized["label"] = "Name"

    def test_to_dict(self):
        tm = TableMeta("desc")
        tm.set_label("Name")
        tm.set_elements(dict(c1=self.sam))
        tm.set_writeable(True)
        assert tm.to_dict() == self.serialized

    def test_from_dict(self):
        tm = TableMeta.from_dict(self.serialized)
        assert tm.description == "desc"
        assert len(tm.elements) == 1
        assert tm.elements["c1"].to_dict() == self.sam.to_dict()
        assert tm.tags == ()
        assert tm.writeable == True
        assert tm.label == "Name"
Example #2
0
class TestSerialization(unittest.TestCase):

    def setUp(self):
        self.sam = StringArrayMeta()
        self.serialized = OrderedDict()
        self.serialized["typeid"] = "malcolm:core/MapMeta:1.0"
        self.serialized["elements"] = dict(c1=self.sam.to_dict())
        self.serialized["elements"]["c1"]["label"] = "C1"
        self.serialized["description"] = "desc"
        self.serialized["tags"] = ()
        self.serialized["writeable"] = False
        self.serialized["label"] = ""
        self.serialized["required"] = ("c1",)

    def test_to_dict(self):
        tm = MapMeta("desc")
        tm.set_elements(dict(c1=self.sam))
        tm.set_required(["c1"])
        assert tm.to_dict() == self.serialized

    def test_from_dict(self):
        tm = MapMeta.from_dict(self.serialized)
        assert tm.description == "desc"
        assert len(tm.elements) == 1
        expected = self.sam.to_dict()
        expected["label"] = "C1"
        assert tm.elements["c1"].to_dict() == expected
        assert tm.tags == ()
        assert tm.required == ("c1",)