def test_FileManager_on_start(): """ When a thread signals it has started, create a serial connection and then list the files. """ fm = FileManager("/dev/ttyUSB0") fm.ls = mock.MagicMock() with mock.patch('mu.modes.base.Serial') as mock_serial: fm.on_start() mock_serial.assert_called_once_with("/dev/ttyUSB0", 115200, timeout=1, parity='N') fm.ls.assert_called_once_with()
def test_FileManager_on_start_fails(): """ When a thread signals it has started, but the serial connection cannot be established, ensure that the on_list_fail is emitted to signal Mu can't get the list of files from the board (because a connection cannot be established). """ fm = FileManager("/dev/ttyUSB0") fm.on_list_fail = mock.MagicMock() mock_serial = mock.MagicMock(side_effect=Exception('BOOM!')) with mock.patch('mu.modes.base.Serial', mock_serial): fm.on_start() mock_serial.assert_called_once_with("/dev/ttyUSB0", 115200, timeout=1, parity='N') fm.on_list_fail.emit.assert_called_once_with()