def test_from_dict(self): m = MethodMeta.from_dict(self.serialized.copy()) self.assertEqual(m.takes.to_dict(), self.takes.to_dict()) self.assertEqual(m.defaults, self.serialized["defaults"]) self.assertEqual(m.tags, []) self.assertEqual(m.writeable, True) self.assertEqual(m.label, "") self.assertEqual(m.returns.to_dict(), MapMeta().to_dict())
def test_from_dict(self): m = MethodMeta.from_dict(self.serialized.copy()) self.assertEqual(m.takes.to_dict(), self.takes.to_dict()) self.assertEqual(m.defaults, self.serialized["defaults"]) self.assertEqual(m.tags, ()) self.assertEqual(m.writeable, True) self.assertEqual(m.label, "") self.assertEqual(m.returns.to_dict(), MapMeta().to_dict())
def _set_block_children(self): # reconfigure block with new children child_list = [self.create_meta()] child_list += list(self._create_default_attributes()) child_list += list(self.create_attributes()) child_list += list(self.create_methods()) for part in self.parts.values(): child_list += list(part.create_attributes()) child_list += list(part.create_methods()) self.methods_writeable = {} writeable_functions = {} children = OrderedDict() for name, child, writeable_func in child_list: if isinstance(child, MethodMeta): # Set if the method is writeable if child.only_in is None: states = [ state for state in self.stateMachine.possible_states if state not in (sm.DISABLING, sm.DISABLED) ] else: states = child.only_in for state in states: assert state in self.stateMachine.possible_states, \ "State %s is not one of the valid states %s" % \ (state, self.stateMachine.possible_states) # Make a copy otherwise all instances will own the same one child = MethodMeta.from_dict(child.to_dict()) self.register_method_writeable(child, states) elif isinstance(child, Attribute): child.meta.set_writeable(writeable_func is not None) children[name] = child if writeable_func: writeable_functions[name] = functools.partial( self.call_writeable_function, writeable_func) self.block.replace_endpoints(children) self.block.set_writeable_functions(writeable_functions)