def test_moving_data(self, dirs, empty_dest): dirs.old_file.ensure() if empty_dest: dirs.new.ensure(dir=True) standarddir._move_data(str(dirs.old), str(dirs.new)) assert not dirs.old_file.exists() assert dirs.new_file.exists()
def test_already_existing(self, dirs, caplog): dirs.old_file.ensure() dirs.new_file.ensure() with caplog.at_level(logging.ERROR): standarddir._move_data(str(dirs.old), str(dirs.new)) expected = "Failed to move data from {} as {} is non-empty!".format( dirs.old, dirs.new) assert caplog.messages[-1] == expected
def test_deleting_error(self, dirs, monkeypatch, mocker, caplog): """When there was an error it should be logged.""" mock = mocker.Mock(side_effect=OSError('error')) monkeypatch.setattr(standarddir.shutil, 'move', mock) dirs.old_file.ensure() with caplog.at_level(logging.ERROR): standarddir._move_data(str(dirs.old), str(dirs.new)) expected = "Failed to move data from {} to {}: error".format( dirs.old, dirs.new) assert caplog.messages[-1] == expected
def test_no_old_dir(self, dirs, caplog): """Nothing should happen without any old directory.""" standarddir._move_data(str(dirs.old), str(dirs.new)) assert not any( rec.message.startswith('Migrating data from') for rec in caplog.records)
def test_no_old_dir(self, dirs, caplog): """Nothing should happen without any old directory.""" standarddir._move_data(str(dirs.old), str(dirs.new)) assert not any(rec.message.startswith('Migrating data from') for rec in caplog.records)