Exemplo n.º 1
0
 def test_junk_words_not_passed_to_callback(self):
     junk = ['the', 'your']
     dispatcher = commands.Dispatcher(junk=junk)
     callback = unittest.mock.Mock()
     dispatcher.register_starts_with('test word', callback)
     dispatcher.dispatch('the test your word the your one the two your the')
     callback.assert_called_once_with(('test', 'word', 'one', 'two'))
Exemplo n.º 2
0
 def test_junk_words_ignored(self):
     junk = ['the', 'your']
     dispatcher = commands.Dispatcher(junk=junk)
     callback = unittest.mock.Mock()
     dispatcher.register('test word', callback)
     dispatcher.dispatch('the test your word the')
     callback.assert_called_once_with(('test', 'word'))
Exemplo n.º 3
0
 def __init__(self):
     self._microphone = microphone.Microphone()
     self._speech = speech.SpeechRecognizer(self._microphone)
     self._lights = lights.Lights()
     self._keywords = commands.Dispatcher()
     self._commands = commands.Dispatcher(junk=config.GRAMMAR_JUNK)
     self._happiness = 0  # Value that goes from -3 to 3
     self._brightness = 2 # Value that goes from 0 to 3
     self._hue = 0.0
     self._animations = collections.deque()
     self._push_animation(self._idle_animation())
     self._listen_animation = self._create_pulse_animation(80.0, 2.0)
     self._state_lock = threading.RLock()
     # Configure the keywords and their associated callbacks.
     for w in config.WAKE_WORDS:
         self._keywords.register(w, self._wake)
     for w in config.HAPPY_WORDS:
         self._keywords.register(w, self._increment_happiness, 1)
     for w in config.SAD_WORDS:
         self._keywords.register(w, self._increment_happiness, -1)
     # Configure the command parsing based on Jackson's grammar (from
     # commands.gram).  Right now this is all manual configuration and
     # care must be taken to ensure the logic below and commands.gram
     # are kept up to date.
     self._commands.register('wink', self._wink)
     self._commands.register('spectrum', self._spectrum)
     self._commands.register('sparkle', self._sparkle)
     self._commands.register('knight rider', self._knight_rider)
     self._commands.register('brighter', self._increment_brightness, 1)
     self._commands.register('dimmer', self._increment_brightness, -1)
     self._commands.register_starts_with('show me', self._change_animation)
     self._commands.register_starts_with('light up', self._change_color)
     self._commands.register_starts_with('change', self._change)
     self._commands.register_starts_with('set', self._change)
     self._commands.register_starts_with('update', self._change)
     self._commands.register_starts_with('modify', self._change)
     self._commands.register_starts_with('make', self._change)
Exemplo n.º 4
0
 def test_register_single_word_dispatches_correctly(self):
     dispatcher = commands.Dispatcher()
     callback = unittest.mock.Mock()
     dispatcher.register('test', callback)
     dispatcher.dispatch('test')
     callback.assert_called_once_with(('test', ))
Exemplo n.º 5
0
 def test_dispatch_none_is_ignored(self):
     dispatcher = commands.Dispatcher()
     callback = unittest.mock.Mock()
     dispatcher.register('test', callback)
     dispatcher.dispatch(None)
     callback.assert_not_called()
Exemplo n.º 6
0
 def test_registered_args_and_kwargs_passed_to_callback(self):
     dispatcher = commands.Dispatcher()
     callback = unittest.mock.Mock()
     dispatcher.register('test', callback, 'bar', baz='baz')
     dispatcher.dispatch('test')
     callback.assert_called_once_with(('test', ), 'bar', baz='baz')
Exemplo n.º 7
0
 def test_non_registered_command_not_called(self):
     dispatcher = commands.Dispatcher()
     callback = unittest.mock.Mock()
     dispatcher.register('foo', callback)
     dispatcher.dispatch('test')
     callback.assert_not_called()
Exemplo n.º 8
0
 def test_register_starts_with_dispatches_correctly(self):
     dispatcher = commands.Dispatcher()
     callback = unittest.mock.Mock()
     dispatcher.register_starts_with('test word', callback)
     dispatcher.dispatch('test word one two')
     callback.assert_called_once_with(('test', 'word', 'one', 'two'))