def test_pyaudio(self, m1, m2): p = m2.return_value.PyAudio.return_value stream = p.open.return_value stream.is_active.return_value = False WavAudio(self.file, 'pyaudio').play() stream.stop_stream.assert_called_once() p.terminate.assert_called_once()
def hack_device(no_input, loop): click.echo( 'This command allows you to hack a Amazon-dash device built on May 2016 and earlier. ' 'Even if your device was purchased later, it is likely that it has an older firmware installed. ' ) click.echo( 'You only need to use this command if you have never connected your device to Amazon servers in ' 'the past.') click.echo( 'Sound is used to hack the device (Amazon Dash buttons include a microphone). It is recommended to ' 'use earbuds near the button. Remember to turn up the volume on your computer.' ) click.secho( 'To start the hack, place the earbuds and hold the button on your Amazon dash device for 5 seconds ' 'until the light blinks blue. Observe the led during the hack.', fg='blue') blue_light_confirm(no_input) wav_file = os.path.join(directory, 'hack.wav') WavAudio(wav_file).loop_play(loop) click.echo('What happened to the led during the hack?') click.echo( '* The LED turns green: the exploit worked! Run the amazon-dash "configure" command' ) click.echo( '* The LED turns off: the device is probably patched. If you have previously connected ' 'your device to amazon servers maybe you can run the amazon-dash "configure" command' )
def test_loop(self, m): wav_audio = WavAudio(self.file) wav_audio.loop_play(1) m.assert_called_once()
def test_get_best_play_method_error(self, m1, m2): with self.assertRaises(AudioError): WavAudio(self.file).get_best_play_method()
def test_get_best_play_method_sox(self, m1, m2): wav_audio = WavAudio(self.file) self.assertEqual(wav_audio.best_play_method, wav_audio.play_sox)
def test_get_best_play_method_pyaudio(self, m): wav_audio = WavAudio(self.file) self.assertEqual(wav_audio.best_play_method, wav_audio.play_pyaudio)
def test_sox(self, m): WavAudio(self.file, 'sox').play() m.assert_called_once_with(['play', self.file])