def test_enterText_Should_DoNothing_When_UserCancelsOperation(self): # Setup xbmc.Keyboard.stubConfirmed = False control = Mock() validator = Mock() updater = Mock() # Test enterText(control=control, validator=validator.validate, updater=updater.update) # Verify verifyZeroInteractions(validator) verifyZeroInteractions(updater)
def test_enterText_Should_NotUpdateControlAndModel_When_UserEnteredTextFailsValidation(self): # Setup xbmc.Keyboard.stubConfirmed = True xbmc.Keyboard.stubText = 'Bubba' control = Mock() updater = Mock() validator = Mock() when(validator).validate(any()).thenRaise(Exception('Invalid name')) # Test enterText(control=control, validator=validator.validate, updater=updater.update) # Verify verifyZeroInteractions(updater) verify(control, 0).setLabel(any(str), any(str))
def readInput(self): ok = False if self.type == str: ok, value = enterText(control=self.widget, validator=self.validator) elif self.type in ( int, Seconds, ): ok, value = enterNumeric(control=self.widget, validator=self.validator, current=self.store.get(self.key)) elif self.type == NegativeSeconds: ok, value = enterNumeric(control=self.widget, validator=self.validator, current=str( int(self.store.get(self.key)) * -1)) if value != '0': value = '-' + value elif self.type == bool and type( self.widget) == xbmcgui.ControlRadioButton: ok, value = True, ['False', 'True'][self.widget.isSelected()] else: log.warn('readinput() not activated for type %s and widget %s' % (self.type, type(self.widget))) if ok: self.store.put(self.key, value) self.render( ) # re-render since enterNumeric(...) doesn't handle special cases like Seconds
def test_enterText_Should_UpdateModelAndControl_When_UserInputIsValid(self): # Setup xbmc.Keyboard.stubConfirmed = True xbmc.Keyboard.stubText = "Bubba" control = Mock() when(control).getLabel().thenReturn('Name') validator = Mock() updater = Mock() # Test enterText(control=control, validator=validator.validate, updater=updater.update) # Verify verify(validator, 1).validate('Bubba') # TODO: type(xbmc.ControlButton) fails for Mock #verify(control, 1).setLabel(any(str), any(str)) verify(updater, 1).update('Bubba')
def test_enterText_Should_NotUpdateControlAndModel_When_UserEnteredTextFailsValidation( self): # Setup xbmc.Keyboard.stubConfirmed = True xbmc.Keyboard.stubText = 'Bubba' control = Mock() updater = Mock() validator = Mock() when(validator).validate(any()).thenRaise(Exception('Invalid name')) # Test enterText(control=control, validator=validator.validate, updater=updater.update) # Verify verifyZeroInteractions(updater) verify(control, 0).setLabel(any(str), any(str))
def test_enterText_Should_UpdateModelAndControl_When_UserInputIsValid( self): # Setup xbmc.Keyboard.stubConfirmed = True xbmc.Keyboard.stubText = "Bubba" control = Mock() when(control).getLabel().thenReturn('Name') validator = Mock() updater = Mock() # Test enterText(control=control, validator=validator.validate, updater=updater.update) # Verify verify(validator, 1).validate('Bubba') # TODO: type(xbmc.ControlButton) fails for Mock #verify(control, 1).setLabel(any(str), any(str)) verify(updater, 1).update('Bubba')
def readInput(self): ok = False if self.type == str: ok, value = enterText(control=self.widget, validator=self.validator) elif self.type in (int, Seconds,): ok, value = enterNumeric(control=self.widget, validator=self.validator, current=self.store.get(self.key)) elif self.type == NegativeSeconds: ok, value = enterNumeric(control=self.widget, validator=self.validator, current= str(int(self.store.get(self.key)) * -1)) if value != '0': value = '-' + value elif self.type == bool and type(self.widget) == xbmcgui.ControlRadioButton: ok, value = True, ['False', 'True'][self.widget.isSelected()] else: log.warn('readinput() not activated for type %s and widget %s' % (self.type, type(self.widget))) if ok: self.store.put(self.key, value) self.render() # re-render since enterNumeric(...) doesn't handle special cases like Seconds