def set_deep_attr_test(self): """Test setdeepattr.""" # pylint: disable=attribute-defined-outside-init # pylint: disable=no-member class O(object): pass a = O() a.b = O() a.b1 = 1 a.b.c = O() a.b.c1 = "ř" # set to a new attribute iutil.setdeepattr(a, "b.c.d", True) self.assertEqual(a.b.c.d, True) # override existing attribute iutil.setdeepattr(a, "b.c", 1234) self.assertEqual(a.b.c, 1234) # "" is actually a valid attribute name # that can be only accessed by getattr iutil.setdeepattr(a, "", 1234) self.assertEqual(getattr(a, ""), 1234) iutil.setdeepattr(a, "b.", 123) self.assertEqual(iutil.getdeepattr(a, "b."), 123) # error should raise AttributeError with self.assertRaises(AttributeError): iutil.setdeepattr(a, "b.c.d.e.f.g.h", 1234)
def input(self, args, key): try: idx = int(key) - 1 if idx >= 0 and idx < len(self.visible_fields): if self.visible_fields[idx].aux == self.CHECK: setdeepattr( self.args, self.visible_fields[idx].attribute, not getdeepattr( self.args, self.visible_fields[idx][1])) self.redraw() self.apply() else: ScreenHandler.push_screen_modal(self.dialog, self.visible_fields[idx]) self.redraw() if self.dialog.value is not None: setdeepattr(self.args, self.visible_fields[idx].attribute, self.dialog.value) self.apply() return InputState.PROCESSED except ValueError: pass return NormalTUISpoke.input(self, args, key)
def input(self, args, key): try: idx = int(key) - 1 if idx >= 0 and idx < len(self.visible_fields): if self.visible_fields[idx].aux == self.CHECK: setdeepattr(self.args, self.visible_fields[idx].attribute, not getdeepattr(self.args, self.visible_fields[idx][1])) self.app.redraw() self.apply() else: self.app.switch_screen_modal(self.dialog, self.visible_fields[idx]) if self.dialog.value is not None: setdeepattr(self.args, self.visible_fields[idx].attribute, self.dialog.value) self.apply() return True except ValueError: pass return NormalTUISpoke.input(self, args, key)
def input(self, args, key): try: idx = int(key) - 1 if idx >= 0 and idx < len(self.edit_fields): if self.edit_fields[idx].aux == self.CHECK: setdeepattr(self.args, self.edit_fields[idx].attribute, not getdeepattr(self.args, self.edit_fields[idx][1])) self.app.redraw() self.apply() else: self.app.switch_screen_modal(self.dialog, self.edit_fields[idx]) if self.dialog.value is not None: setdeepattr(self.args, self.edit_fields[idx].attribute, self.dialog.value) self.apply() return True except ValueError: pass return NormalTUISpoke.input(self, args, key)