def test_create_children(self, attribute_mock, method_mock): # Load up items to create mi1, mi2 = MagicMock(), MagicMock() method_mock.side_effect = [mi1, mi2] ai1, ai2 = MagicMock(), MagicMock() attribute_mock.side_effect = [ai1, ai2] # Load up refs to get group_attr = Attribute() child_attr = self.make_grouped_attr() m1 = MethodMeta() m2 = MethodMeta() BlockItem.items[("endpoint", "foo")] = ai1 self.item.ref = OrderedDict(( ("foo", group_attr), ("c", child_attr), ("a", m1), ("b", m2))) self.item.create_children() # Check it made the right thing self.assertEqual(len(self.item.children), 3) attribute_mock.assert_any_call(("endpoint", "foo"), group_attr) self.assertEqual(self.item.children[0], ai1) attribute_mock.assert_any_call(("endpoint", "c"), child_attr) ai1.add_child.assert_called_once_with(ai2) method_mock.assert_any_call(("endpoint", "a"), m1) self.assertEqual(self.item.children[1], mi1) method_mock.assert_any_call(("endpoint", "b"), m2) self.assertEqual(self.item.children[2], mi2)
def create_methods(self): method_name = self.field_name.replace(".", ":") if self.arg_meta: # Decorate set_field with a MethodMeta @method_takes(self.arg_name, self.arg_meta, REQUIRED) def set_field(params): self.set_field(params) self.method = set_field.MethodMeta writeable_func = set_field else: self.method = MethodMeta() writeable_func = None self.method.set_description(self.description) self.method.set_tags(self.tags) label = self.field_name.replace(".", " ").replace("_", " ").title() self.method.set_label(label) yield method_name, self.method, writeable_func
def create_methods(self): label, method_name = make_label_attr_name(self.field_name) if self.arg_meta: self.arg_name = method_name # Decorate set_field with a MethodMeta @method_takes(self.arg_name, self.arg_meta, REQUIRED) def set_field(params): self.set_field(params) self.method = set_field.MethodMeta writeable_func = set_field else: self.method = MethodMeta() writeable_func = None self.method.set_description(self.description) self.method.set_tags(self.tags) self.method.set_label(label) yield method_name, self.method, writeable_func
def create_methods(self): # MethodMeta instance self.method = MethodMeta(self.params.description) # TODO: set widget tag? yield self.params.name, self.method, self.caput
def create_methods(self): # MethodMeta instance self.method = MethodMeta(self.params.description) yield self.params.name, self.method, self.caput
def test_ref_children(self): self.item.ref = dict( a=MethodMeta(), b=MethodMeta(), c=Attribute()) self.assertEqual(self.item.ref_children(), 3)