Example #1
0
    def from_dict(cls, name, d):
        """Create a Method instance from the serialized version of itself

        Args:
            name (str): Method instance name
            d (dict): Something that self.to_dict() would create
        """
        method = cls(name, d["description"])
        takes = MapMeta.from_dict("takes", d["takes"])
        method.set_function_takes(takes, d["defaults"])
        returns = MapMeta.from_dict("returns", d["returns"])
        method.set_function_returns(returns)
        return method
Example #2
0
 def test_from_dict(self):
     tm = MapMeta.from_dict(self.serialized)
     self.assertEquals(tm.description, "desc")
     self.assertEquals(len(tm.elements), 1)
     self.assertEquals(tm.elements["c1"].to_dict(), self.sam.to_dict())
     self.assertEquals(tm.tags, [])
     self.assertEquals(tm.required, ["c1"])
Example #3
0
 def test_from_dict(self):
     tm = MapMeta.from_dict(self.serialized)
     self.assertEquals(tm.description, "desc")
     self.assertEquals(len(tm.elements), 1)
     self.assertEquals(tm.elements["c1"].to_dict(), self.sam.to_dict())
     self.assertEquals(tm.tags, [])
     self.assertEquals(tm.required, ["c1"])
Example #4
0
 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",)
Example #5
0
    def test_from_dict_deserialize(self, am_mock):
        # prep dict
        elements = OrderedDict()
        elements["one"] = "e1"
        elements["two"] = "e2"
        required = ["one"]
        d = dict(elements=elements, required=required)
        # prep from_dict with AttributeMetas to return
        am1 = MagicMock()
        am1.name = "one"
        am2 = MagicMock()
        am2.name = "two"
        am_mock.from_dict.side_effect = [am1, am2]

        map_meta = MapMeta.from_dict("Test", d)

        self.assertEqual(am_mock.from_dict.call_args_list, [
            call("one", "e1"), call("two", "e2")])
        self.assertEqual(map_meta.name, "Test")
        self.assertEqual(map_meta.required, ["one"])
        self.assertEqual(map_meta.elements, dict(one=am1, two=am2))