Пример #1
0
def test_ensuredirectoryexists_recreate(ensure_directory_exists_fixture):
    """Test ensure_directory_exists with recreating the target directory"""
    mock_exists, mock_makedirs, mock_rmtree = ensure_directory_exists_fixture
    mock_exists.side_effect = [True, False]
    utils.ensure_directory_exists('/foo', clean=True)
    mock_rmtree.assert_called_once_with('/foo')
    mock_makedirs.assert_called_once_with('/foo')
Пример #2
0
def test_ensuredirectoryexists_create(ensure_directory_exists_fixture, clean):
    """Test ensure_directory_exists with non existent target directory"""
    mock_exists, mock_makedirs, mock_rmtree = ensure_directory_exists_fixture
    mock_exists.return_value = False
    utils.ensure_directory_exists('/foo', clean)
    mock_rmtree.assert_not_called()
    mock_makedirs.assert_called_once_with('/foo')
Пример #3
0
def test_ensuredirectoryexists_noop(ensure_directory_exists_fixture):
    """Test ensure_directory_exists with existent target directory"""
    mock_exists, mock_makedirs, mock_rmtree = ensure_directory_exists_fixture
    mock_exists.return_value = True
    utils.ensure_directory_exists('/foo')
    mock_rmtree.assert_not_called()
    mock_makedirs.assert_not_called()
Пример #4
0
def test_ensuredirectoryexists_ignore_oserror(ensure_directory_exists_fixture):
    """Test ensure_directory_exists ignores OSError"""
    mock_exists, _, mock_rmtree = ensure_directory_exists_fixture
    mock_exists.return_value = True
    mock_rmtree.side_effect = OSError
    utils.ensure_directory_exists('/foo', clean=True)
def create_file(path, content=''):
    """ Create a file """
    utils.ensure_directory_exists(os.path.dirname(path))
    with open(path, 'w') as tmpfile:
        tmpfile.write(content)