def test_should_return_next_seq(self): sert(xmod._next_seq(0)).to_equal(1) for i in range(1, 255): sert(xmod._next_seq(i)).to_equal(i + 1) sert(xmod._next_seq(255)).to_equal(1) sert(xmod._next_seq(256)).to_equal(2) sert(xmod._next_seq(257)).to_equal(3)
def test_should_set_wav_file(self): filename = 'abc.wav' sert(tx.wav_file).to_equal(None) tx.set_wav_filename(filename) sert(tx.wav_file).to_equal(filename)
def test_should_clear_record_session(self): filename = None tx.record_session = True tx.set_wav_filename(filename) sert(tx.record_session).is_false()
def test_should_call_set_config(self): d = src.dispatcher.Dispatcher() d.set_config = Mock() d.exec_line('set wx yz') sert(d.set_config).called_once_with('wx yz')
def test_should_update_start_time(self): tx.run() sert(tx.started_at).to_equal(0) tx.write_bytes([65]) sert(tx.started_at).to_equal(123)
def test_should_call_peek(self): d = src.dispatcher.Dispatcher() d.peek = Mock() d.exec_line('peek') sert(d.peek).called_once()
def test_should_call_script(self): d = src.dispatcher.Dispatcher() d.script = Mock() d.exec_line('script abc.txt') sert(d.script).called_once_with('abc.txt')
def test_should_return_true_value(self): d = src.dispatcher.Dispatcher() d.done = True ans = d.is_done() sert(ans).is_true()
def test_should_return_false_value(self): d = src.dispatcher.Dispatcher() d.done = False ans = d.is_done() sert(ans).is_false()
def test_should_reset_prompt(self): d.proc_serial() sert(d.prompt).to_equal('serial> ') d.quit() sert(d.prompt).to_equal('> ')
def test_should_reset_cmd_proc(self): d.proc_serial() sert(d.prompt).not_equal(None) d.quit() sert(d.cmd_proc).to_equal(None)
def test_should_echo(self, mock_i): txt = 'some text' d = src.dispatcher.Dispatcher() d.echo(txt) sert(mock_i).called_once_with(txt)
def test_should_stop_transport(self): d = src.dispatcher.Dispatcher() d.transport = Mock() cmd = d.stop_transport() sert(d.transport.stop_it).called_once()
def test_should_handle_read_ini_error(self, mock_i, mock_e, mock_open): mock_open.side_effect = IOError('bad thing') d = src.dispatcher.Dispatcher(targs(init='abc.ini')) sert(mock_i).called_once_with('Reading init script abc.ini') sert(mock_e).called_once_with('Error reading abc.ini')
def test_should_call_help(self): d = src.dispatcher.Dispatcher() d.help = Mock() d.exec_line('help') sert(d.help).called_once()
def test_should_set_value_true_value(self): d = src.dispatcher.Dispatcher() d.done = False d.force_done() sert(d.done).is_true()
def test_should_call_listen(self): d = src.dispatcher.Dispatcher() d.listen = Mock() d.exec_line('listen 4 5') sert(d.listen).called_once_with('4 5')
def test_should_call_quit(self): d = src.dispatcher.Dispatcher() d.quit = Mock() d.exec_line('quit') sert(d.quit).called_once()
def test_should_call_wait(self): d = src.dispatcher.Dispatcher() d.wait = Mock() d.exec_line('wait 15') sert(d.wait).called_once_with('15')
def test_should_call_subproc(self): d = src.dispatcher.Dispatcher() d.cmd_proc = Mock() d.exec_line('ab cd ef') sert(d.cmd_proc.exec_line).called_once_with('ab cd ef')
def test_should_call_show_config(self): d = src.dispatcher.Dispatcher() d.show_config = Mock() d.exec_line('show ab cd') sert(d.show_config).called_once_with('ab cd')
def test_should_call_echo(self): d = src.dispatcher.Dispatcher() d.echo = Mock() d.exec_line('echo abc') sert(d.echo).called_once_with('abc')
def test_should_return_none_for_bad_key(self): key = 'bad-key' d = src.dispatcher.Dispatcher() ans = d._get_config_val(key) sert(ans).to_equal(None)
def test_should_call_proc_serial(self): d = src.dispatcher.Dispatcher() d.proc_serial = Mock() d.exec_line('serial a scmd') sert(d.proc_serial).called_once_with('a scmd')
def test_should_clear_session_buffer(self): filename = None tx.session_buffer = [33, 44] tx.set_wav_filename(filename) sert(tx.session_buffer).to_equal([])
def test_should_call_proc_kermit(self): d = src.dispatcher.Dispatcher() d.proc_kermit = Mock() d.exec_line('kermit a kcmd') sert(d.proc_kermit).called_once_with('a kcmd')
def test_should_set_record_session(self): filename = 'abc.wav' sert(tx.record_session).is_false() tx.set_wav_filename(filename) sert(tx.record_session).is_true()
def test_should_call_proc_xmodem(self): d = src.dispatcher.Dispatcher() d.proc_xmodem = Mock() d.exec_line('xmodem a xcmd') sert(d.proc_xmodem).called_once_with('a xcmd')
def test_should_open_pyaudio(self): mock_pa = mock_txpa.get_instance sert(mock_pa, 'open').not_called() tx.run() sert(mock_pa, 'open').called_once()
def test_should_return_false(self, mock_stdin): mock_stdin.read = Mock(return_value='xyz') xmod._send_bytes = Mock(return_value=False) ans = xmod.send_file('STDIN') sert(ans).is_false()