def test_FileManager_put_fail(): """ The on_put_fail signal is emitted when a problem is encountered. """ fm = FileManager() fm.on_put_fail = mock.MagicMock() with mock.patch('mu.modes.microbit.microfs.put', side_effect=Exception('boom')): fm.put('foo.py') fm.on_put_fail.emit.assert_called_once_with('foo.py')
def test_FileManager_put_fail(): """ The on_put_fail signal is emitted when a problem is encountered. """ fm = FileManager() fm.on_put_fail = mock.MagicMock() with mock.patch('mu.modes.microbit.microfs.get_serial', side_effect=Exception('boom')): fm.put('foo.py') fm.on_put_fail.emit.assert_called_once_with('foo.py')
def test_FileManager_put(): """ The on_put_file signal is emitted with the name of the effected file when microfs.put completes successfully. """ fm = FileManager() fm.on_put_file = mock.MagicMock() mock_put = mock.MagicMock() path = os.path.join('directory', 'foo.py') with mock.patch('mu.modes.microbit.microfs.put', mock_put): fm.put(path) mock_put.assert_called_once_with(path, target=None) fm.on_put_file.emit.assert_called_once_with('foo.py')
def test_FileManager_put(): """ The on_put_file signal is emitted with the name of the effected file when microfs.put completes successfully. """ fm = FileManager() fm.on_put_file = mock.MagicMock() mock_put = mock.MagicMock() mock_serial = mock.MagicMock() path = os.path.join('directory', 'foo.py') with mock.patch('mu.modes.microbit.microfs.put', mock_put),\ mock.patch('mu.modes.microbit.microfs.get_serial', mock_serial): fm.put(path) mock_put.assert_called_once_with(path, mock_serial().__enter__()) fm.on_put_file.emit.assert_called_once_with('foo.py')