예제 #1
0
    def setUp(self):
        # If ~/.cookiecutterrc is pre-existing, move it to a temp location
        self.user_config_path = os.path.expanduser('~/.cookiecutterrc')
        self.user_config_path_backup = os.path.expanduser(
            '~/.cookiecutterrc.backup'
        )
        if os.path.exists(self.user_config_path):
            self.user_config_found = True
            shutil.copy(self.user_config_path, self.user_config_path_backup)
            os.remove(self.user_config_path)
        else:
            self.user_config_found = False

        # If the default cookiecutters_dir is pre-existing, move it to a
        # temp location
        self.cookiecutters_dir = os.path.expanduser('~/.cookiecutters')
        self.cookiecutters_dir_backup = os.path.expanduser('~/.cookiecutters.backup')
        if os.path.isdir(self.cookiecutters_dir):
            self.cookiecutters_dir_found = True

            # Remove existing backups before backing up. If they exist, they're stale.
            if os.path.isdir(self.cookiecutters_dir_backup):
                utils.rmtree(self.cookiecutters_dir_backup)

            shutil.copytree(self.cookiecutters_dir, self.cookiecutters_dir_backup)
        else:
            self.cookiecutters_dir_found = False
예제 #2
0
 def setUp(self):
     if os.path.isdir('cookiecutter-pypackage'):
         utils.rmtree('cookiecutter-pypackage')
     os.mkdir('cookiecutter-pypackage/')
     if os.path.isdir('cookiecutter-trytonmodule'):
         utils.rmtree('cookiecutter-trytonmodule')
     os.mkdir('cookiecutter-trytonmodule/')
예제 #3
0
 def tearDown(self):
     with utils.work_in(config.DEFAULT_CONFIG['cookiecutters_dir']):
         if os.path.isdir('cookiecutter-pypackage'):
             utils.rmtree('cookiecutter-pypackage')
     if os.path.isdir('boilerplate'):
         utils.rmtree('boilerplate')
     super(TestGitBranch, self).tearDown()
예제 #4
0
 def test_rmtree(self):
     os.mkdir('foo')
     with open('foo/bar', "w") as f:
         f.write("Test data")
     make_readonly('foo/bar')
     utils.rmtree('foo')
     self.assertFalse(os.path.exists('foo'))
예제 #5
0
 def test_git_clone(self):
     repo_dir = vcs.clone(
         'https://github.com/audreyr/cookiecutter-pypackage.git'
     )
     self.assertEqual(repo_dir, 'cookiecutter-pypackage')
     self.assertTrue(os.path.isfile('cookiecutter-pypackage/README.rst'))
     if os.path.isdir('cookiecutter-pypackage'):
         utils.rmtree('cookiecutter-pypackage')
예제 #6
0
def test_hg_clone():
    repo_dir = vcs.clone(
        'https://bitbucket.org/pokoli/cookiecutter-trytonmodule'
    )
    assert repo_dir == 'cookiecutter-trytonmodule'
    assert os.path.isfile('cookiecutter-trytonmodule/README.rst')
    if os.path.isdir('cookiecutter-trytonmodule'):
        utils.rmtree('cookiecutter-trytonmodule')
예제 #7
0
 def test_hg_clone(self):
     repo_dir = vcs.clone(
         'https://bitbucket.org/pokoli/cookiecutter-trytonmodule'
     )
     self.assertEqual(repo_dir, 'cookiecutter-trytonmodule')
     self.assertTrue(os.path.isfile('cookiecutter-trytonmodule/README.rst'))
     if os.path.isdir('cookiecutter-trytonmodule'):
         utils.rmtree('cookiecutter-trytonmodule')
예제 #8
0
def test_git_clone_with_trailing_slash():
    repo_dir = vcs.clone(
        'https://github.com/audreyr/cookiecutter-pypackage/'
    )

    assert repo_dir == 'cookiecutter-pypackage'
    assert os.path.isfile('cookiecutter-pypackage/README.rst')

    if os.path.isdir('cookiecutter-pypackage'):
        utils.rmtree('cookiecutter-pypackage')
def bake_in_temp_dir(cookies, *args, **kwargs):
    """
    Delete the temporal directory that is created when executing the tests
    :param cookies: pytest_cookies.Cookies, cookie to be baked and its temporal files will be removed
    """
    result = cookies.bake(*args, **kwargs)
    try:
        yield result
    finally:
        rmtree(str(result.project))
예제 #10
0
def bake_in_temp_dir(cookies, *args, **kwargs):
    """
    Delete the temporal directory that is created when executing the tests
    :param cookies: pytest_cookies.Cookies,
        cookie to be baked and its temporal files will be removed
    """
    result = cookies.bake(*args, **kwargs)
    try:
        yield result
    finally:
        rmtree(str(result.project))
 def fin_remove_additional_dirs():
     if os.path.isdir('fake-project'):
         utils.rmtree('fake-project')
     if os.path.isdir('fake-project-extra'):
         utils.rmtree('fake-project-extra')
     if os.path.isdir('fake-project-templated'):
         utils.rmtree('fake-project-templated')
     if os.path.isdir('fake-project-dict'):
         utils.rmtree('fake-project-dict')
     if os.path.isdir('fake-tmp'):
         utils.rmtree('fake-tmp')
예제 #12
0
def backup_dir(original_dir, backup_dir):
    # If the default original_dir is pre-existing, move it to a temp location
    if not os.path.isdir(original_dir):
        return False

    # Remove existing backups before backing up. If they exist, they're stale.
    if os.path.isdir(backup_dir):
        utils.rmtree(backup_dir)

    shutil.copytree(original_dir, backup_dir)
    return True
예제 #13
0
 def fin_remove_additional_folders():
     if os.path.exists('inputpizzä'):
         utils.rmtree('inputpizzä')
     if os.path.exists('inputgreen'):
         utils.rmtree('inputgreen')
     if os.path.exists('inputbinary_files'):
         utils.rmtree('inputbinary_files')
     if os.path.exists('tests/custom_output_dir'):
         utils.rmtree('tests/custom_output_dir')
     if os.path.exists('inputpermissions'):
         utils.rmtree('inputpermissions')
 def fin_remove_additional_dirs():
     if os.path.isdir('fake-project'):
         utils.rmtree('fake-project')
     if os.path.isdir('fake-project-extra'):
         utils.rmtree('fake-project-extra')
     if os.path.isdir('fake-project-templated'):
         utils.rmtree('fake-project-templated')
     if os.path.isdir('fake-project-dict'):
         utils.rmtree('fake-project-dict')
     if os.path.isdir('fake-tmp'):
         utils.rmtree('fake-tmp')
예제 #15
0
 def fin_remove_additional_folders():
     directories_to_delete = [
         'tests/test-pyhooks/inputpyhooks',
         'inputpyhooks',
         'inputhooks',
         'tests/test-shellhooks',
         'tests/test-hooks',
     ]
     for directory in directories_to_delete:
         if os.path.exists(directory):
             utils.rmtree(directory)
예제 #16
0
def backup_dir(original_dir, backup_dir):
    # If the default original_dir is pre-existing, move it to a temp location
    if not os.path.isdir(original_dir):
        return False

    # Remove existing backups before backing up. If they exist, they're stale.
    if os.path.isdir(backup_dir):
        utils.rmtree(backup_dir)

    shutil.copytree(original_dir, backup_dir)
    return True
예제 #17
0
 def tearDown(self):
     if os.path.exists('inputpizzä'):
         utils.rmtree('inputpizzä')
     if os.path.exists('inputgreen'):
         utils.rmtree('inputgreen')
     if os.path.exists('inputbinary_files'):
         utils.rmtree('inputbinary_files')
     if os.path.exists('tests/custom_output_dir'):
         utils.rmtree('tests/custom_output_dir')
     if os.path.exists('inputpermissions'):
         utils.rmtree('inputpermissions')
     super(TestGenerateFiles, self).tearDown()
예제 #18
0
 def tearDown(self):
     if os.path.exists('inputpizzä'):
         utils.rmtree('inputpizzä')
     if os.path.exists('inputgreen'):
         utils.rmtree('inputgreen')
     if os.path.exists('inputbinary_files'):
         utils.rmtree('inputbinary_files')
     if os.path.exists('tests/custom_output_dir'):
         utils.rmtree('tests/custom_output_dir')
     if os.path.exists('inputpermissions'):
         utils.rmtree('inputpermissions')
     super(TestGenerateFiles, self).tearDown()
예제 #19
0
def bake_in_temp_dir(cookies, *args, **kwargs):
    """
    Delete the temporal directory that is created when executing the tests
    :param cookies: pytest_cookies.Cookies, cookie to be baked and its temporal files will be removed
    """
    result = cookies.bake(*args, **kwargs)
    try:
        # assert result.error is None
        assert result.exception is None, getattr(result.exception, 'error', result.exception)
        yield result
    finally:
        rmtree(str(result.project))
예제 #20
0
    def tearDown(self):
        utils.rmtree(self.repo_path)

        if os.path.exists('python_pre.txt'):
            os.remove('python_pre.txt')
        if os.path.exists('shell_post.txt'):
            os.remove('shell_post.txt')
        if os.path.exists('tests/shell_post.txt'):
            os.remove('tests/shell_post.txt')
        if os.path.exists('tests/test-hooks/input{{hooks}}/python_pre.txt'):
            os.remove('tests/test-hooks/input{{hooks}}/python_pre.txt')
        if os.path.exists('tests/test-hooks/input{{hooks}}/shell_post.txt'):
            os.remove('tests/test-hooks/input{{hooks}}/shell_post.txt')
예제 #21
0
def remove_additional_folders():
    """Remove some special folders which are created by the tests."""
    yield
    if os.path.exists('inputpizzä'):
        utils.rmtree('inputpizzä')
    if os.path.exists('inputgreen'):
        utils.rmtree('inputgreen')
    if os.path.exists('inputbinary_files'):
        utils.rmtree('inputbinary_files')
    if os.path.exists('tests/custom_output_dir'):
        utils.rmtree('tests/custom_output_dir')
    if os.path.exists('inputpermissions'):
        utils.rmtree('inputpermissions')
def bake_in_temp_dir(cookies: Cookies, *args: Any,
                     **kwargs: Dict[str, str]) -> Result:
    """
    Delete the temporal directory that is created when executing the tests
    :param cookies: pytest_cookies.Cookies,
        cookie to be baked and its temporal files will be removed
    """
    result = cookies.bake(*args, **kwargs)
    # print('=' * 80 + '\n', "Result info:", repr(result), '\n' + ('=' * 80))
    try:
        yield result
    finally:
        rmtree(str(result.project))
예제 #23
0
def remove_additional_folders(tmp_path):
    """Remove some special folders which are created by the tests."""
    yield
    directories_to_delete = [
        'tests/test-pyhooks/inputpyhooks',
        'inputpyhooks',
        'inputhooks',
        tmp_path.joinpath('test-shellhooks'),
        'tests/test-hooks',
    ]
    for directory in directories_to_delete:
        if os.path.exists(directory):
            utils.rmtree(directory)
예제 #24
0
    def tearDown(self):
        utils.rmtree(self.repo_path)

        if os.path.exists('python_pre.txt'):
            os.remove('python_pre.txt')
        if os.path.exists('shell_post.txt'):
            os.remove('shell_post.txt')
        if os.path.exists('tests/shell_post.txt'):
            os.remove('tests/shell_post.txt')
        if os.path.exists('tests/test-hooks/input{{hooks}}/python_pre.txt'):
            os.remove('tests/test-hooks/input{{hooks}}/python_pre.txt')
        if os.path.exists('tests/test-hooks/input{{hooks}}/shell_post.txt'):
            os.remove('tests/test-hooks/input{{hooks}}/shell_post.txt')
예제 #25
0
def bake_in_temp_dir(cookies, *args, **kwargs):
    '''
    Delete temporary directory that is created when executing tests

    Parameters
    ----------
    cookies: pytest_cookies.Cookies
        Cookie to be baked and its temporal files will be removed
    '''
    result = cookies.bake(*args, **kwargs)
    try:
        yield result
    finally:
        rmtree(str(result.project))
예제 #26
0
def test_make_sure_path_exists():
    if sys.platform.startswith("win"):
        existing_directory = os.path.abspath(os.curdir)
        uncreatable_directory = "a*b"
    else:
        existing_directory = "/usr/"
        uncreatable_directory = "/this-doesnt-exist-and-cant-be-created/"

    assert utils.make_sure_path_exists(existing_directory)
    assert utils.make_sure_path_exists("tests/blah")
    assert utils.make_sure_path_exists("tests/trailingslash/")
    assert not utils.make_sure_path_exists(uncreatable_directory)
    utils.rmtree("tests/blah/")
    utils.rmtree("tests/trailingslash/")
예제 #27
0
def test_git_clone_custom_dir():
    os.makedirs('tests/custom_dir1/custom_dir2/')
    repo_dir = vcs.clone(
        repo_url='https://github.com/audreyr/cookiecutter-pypackage.git',
        checkout=None,
        clone_to_dir='tests/custom_dir1/custom_dir2/')
    with utils.work_in('tests/custom_dir1/custom_dir2/'):
        test_dir = 'tests/custom_dir1/custom_dir2/cookiecutter-pypackage'
        assert repo_dir == test_dir.replace('/', os.sep)
        assert os.path.isfile('cookiecutter-pypackage/README.rst')
        if os.path.isdir('cookiecutter-pypackage'):
            utils.rmtree('cookiecutter-pypackage')
    if os.path.isdir('tests/custom_dir1'):
        utils.rmtree('tests/custom_dir1')
예제 #28
0
def clean_cookiecutter_dirs(request):
    if os.path.isdir('cookiecutter-pypackage'):
        utils.rmtree('cookiecutter-pypackage')
    os.mkdir('cookiecutter-pypackage/')
    if os.path.isdir('cookiecutter-trytonmodule'):
        utils.rmtree('cookiecutter-trytonmodule')
    os.mkdir('cookiecutter-trytonmodule/')

    def remove_cookiecutter_dirs():
        if os.path.isdir('cookiecutter-pypackage'):
            utils.rmtree('cookiecutter-pypackage')
        if os.path.isdir('cookiecutter-trytonmodule'):
            utils.rmtree('cookiecutter-trytonmodule')
    request.addfinalizer(remove_cookiecutter_dirs)
예제 #29
0
    def test_make_sure_path_exists(self):
        if sys.platform.startswith('win'):
            existing_directory = os.path.abspath(os.curdir)
            uncreatable_directory = 'a*b'
        else:
            existing_directory = '/usr/'
            uncreatable_directory = '/this-dir-does-not-exist-and-cant-be-created/'

        self.assertTrue(utils.make_sure_path_exists(existing_directory))
        self.assertTrue(utils.make_sure_path_exists('tests/blah'))
        self.assertTrue(utils.make_sure_path_exists('tests/trailingslash/'))
        self.assertFalse(utils.make_sure_path_exists(uncreatable_directory))
        utils.rmtree('tests/blah/')
        utils.rmtree('tests/trailingslash/')
예제 #30
0
def test_make_sure_path_exists():
    if sys.platform.startswith('win'):
        existing_directory = os.path.abspath(os.curdir)
        uncreatable_directory = 'a*b'
    else:
        existing_directory = '/usr/'
        uncreatable_directory = '/this-doesnt-exist-and-cant-be-created/'

    assert utils.make_sure_path_exists(existing_directory)
    assert utils.make_sure_path_exists('tests/blah')
    assert utils.make_sure_path_exists('tests/trailingslash/')
    assert not utils.make_sure_path_exists(uncreatable_directory)
    utils.rmtree('tests/blah/')
    utils.rmtree('tests/trailingslash/')
예제 #31
0
def test_force_delete(mocker, tmp_path):
    """Verify `utils.force_delete` makes files writable."""
    ro_file = Path(tmp_path, 'bar')

    with open(ro_file, "w") as f:
        f.write("Test data")
    make_readonly(ro_file)

    rmtree = mocker.Mock()
    utils.force_delete(rmtree, ro_file, sys.exc_info())

    assert (ro_file.stat().st_mode & stat.S_IWRITE) == stat.S_IWRITE
    rmtree.assert_called_once_with(ro_file)

    utils.rmtree(tmp_path)
예제 #32
0
def clean_cookiecutter_dirs(request):
    if os.path.isdir('cookiecutter-pypackage'):
        utils.rmtree('cookiecutter-pypackage')
    os.mkdir('cookiecutter-pypackage/')
    if os.path.isdir('cookiecutter-trytonmodule'):
        utils.rmtree('cookiecutter-trytonmodule')
    os.mkdir('cookiecutter-trytonmodule/')

    def remove_cookiecutter_dirs():
        if os.path.isdir('cookiecutter-pypackage'):
            utils.rmtree('cookiecutter-pypackage')
        if os.path.isdir('cookiecutter-trytonmodule'):
            utils.rmtree('cookiecutter-trytonmodule')

    request.addfinalizer(remove_cookiecutter_dirs)
예제 #33
0
    def teardown_method(self, method):
        utils.rmtree(self.repo_path)

        if os.path.exists('python_pre.txt'):
            os.remove('python_pre.txt')
        if os.path.exists('shell_post.txt'):
            os.remove('shell_post.txt')
        if os.path.exists('tests/shell_post.txt'):
            os.remove('tests/shell_post.txt')
        if os.path.exists('tests/test-hooks/input{{hooks}}/python_pre.txt'):
            os.remove('tests/test-hooks/input{{hooks}}/python_pre.txt')
        if os.path.exists('tests/test-hooks/input{{hooks}}/shell_post.txt'):
            os.remove('tests/test-hooks/input{{hooks}}/shell_post.txt')
        if os.path.exists('tests/context_post.txt'):
            os.remove('tests/context_post.txt')
예제 #34
0
 def test_git_clone_custom_dir(self):
     os.makedirs("tests/custom_dir1/custom_dir2/")
     repo_dir = vcs.clone(
         repo_url='https://github.com/audreyr/cookiecutter-pypackage.git',
         checkout=None,
         clone_to_dir="tests/custom_dir1/custom_dir2/"
     )
     with utils.work_in("tests/custom_dir1/custom_dir2/"):
         test_dir = 'tests/custom_dir1/custom_dir2/cookiecutter-pypackage'.replace("/", os.sep)
         self.assertEqual(repo_dir, test_dir)
         self.assertTrue(os.path.isfile('cookiecutter-pypackage/README.rst'))
         if os.path.isdir('cookiecutter-pypackage'):
             utils.rmtree('cookiecutter-pypackage')
     if os.path.isdir('tests/custom_dir1'):
         utils.rmtree('tests/custom_dir1')
예제 #35
0
    def teardown_method(self, method):
        utils.rmtree(self.repo_path)

        if os.path.exists("python_pre.txt"):
            os.remove("python_pre.txt")
        if os.path.exists("shell_post.txt"):
            os.remove("shell_post.txt")
        if os.path.exists("tests/shell_post.txt"):
            os.remove("tests/shell_post.txt")
        if os.path.exists("tests/test-hooks/input{{hooks}}/python_pre.txt"):
            os.remove("tests/test-hooks/input{{hooks}}/python_pre.txt")
        if os.path.exists("tests/test-hooks/input{{hooks}}/shell_post.txt"):
            os.remove("tests/test-hooks/input{{hooks}}/shell_post.txt")
        if os.path.exists("tests/context_post.txt"):
            os.remove("tests/context_post.txt")
예제 #36
0
def bake_in_temp_dir(cookies, *args, **kwargs):
    """
    Delete the temporal directory that is created when executing the tests
    :param cookies: pytest_cookies.Cookies,
        cookie to be baked and its temporal files will be removed
    """
    with suppressed_github_and_circleci_creation():
        result = cookies.bake(*args, **kwargs)
        assert result is not None, result
        assert result.exception is None, errmsg(result.exception)
        assert result.exit_code == 0
    try:
        yield result
    finally:
        rmtree(str(result.project_path))
예제 #37
0
def test_git_clone_custom_dir():
    os.makedirs('tests/custom_dir1/custom_dir2/')
    repo_dir = vcs.clone(
        repo_url='https://github.com/audreyr/cookiecutter-pypackage.git',
        checkout=None,
        clone_to_dir='tests/custom_dir1/custom_dir2/'
    )
    with utils.work_in('tests/custom_dir1/custom_dir2/'):
        test_dir = 'tests/custom_dir1/custom_dir2/cookiecutter-pypackage'
        assert repo_dir == test_dir.replace('/', os.sep)
        assert os.path.isfile('cookiecutter-pypackage/README.rst')
        if os.path.isdir('cookiecutter-pypackage'):
            utils.rmtree('cookiecutter-pypackage')
    if os.path.isdir('tests/custom_dir1'):
        utils.rmtree('tests/custom_dir1')
예제 #38
0
def bake_in_temp_dir(cookies, *args, **kwargs):
    """
    Delete the temporal directory that is created when executing the tests
    :param cookies: pytest_cookies.Cookies,
        cookie to be baked and its temporal files will be removed
    """
    result = cookies.bake(*args, **kwargs)

    if result.exception:
      # raise a new exception because the existing one comes with *a lot* of baggage
      raise(result.exception.__class__(**result.exception.__dict__))

    try:
        yield result
    finally:
        rmtree(str(result.project))
예제 #39
0
 def test_git_clone_custom_dir(self):
     os.makedirs("tests/custom_dir1/custom_dir2/")
     repo_dir = vcs.clone(
         repo_url='https://github.com/audreyr/cookiecutter-pypackage.git',
         checkout=None,
         clone_to_dir="tests/custom_dir1/custom_dir2/")
     with utils.work_in("tests/custom_dir1/custom_dir2/"):
         test_dir = 'tests/custom_dir1/custom_dir2/cookiecutter-pypackage'.replace(
             "/", os.sep)
         self.assertEqual(repo_dir, test_dir)
         self.assertTrue(
             os.path.isfile('cookiecutter-pypackage/README.rst'))
         if os.path.isdir('cookiecutter-pypackage'):
             utils.rmtree('cookiecutter-pypackage')
     if os.path.isdir('tests/custom_dir1'):
         utils.rmtree('tests/custom_dir1')
예제 #40
0
def bake_in_temp_dir(cookies: Cookies, *args: Any, **kwargs: Any) -> Result:
    """Delete the temporal directory that is created when executing the tests.

    Args:
        cookies: A cookie to be baked and its temporal files will be removed.
        *args: Variable length argument list to be passed to the bake command.
        **kwargs: Arbitrary keyword arguments to be passed to the bake command.

    Yields:
        The baked cookie.
    """
    result = cookies.bake(*args, **kwargs)
    try:
        yield result
    finally:
        rmtree(str(result.project_path))
예제 #41
0
    def teardown_method(self, method):
        """External hooks related tests teardown fixture."""
        utils.rmtree(self.repo_path)

        if os.path.exists('python_pre.txt'):
            os.remove('python_pre.txt')
        if os.path.exists('shell_post.txt'):
            os.remove('shell_post.txt')
        if os.path.exists('tests/shell_post.txt'):
            os.remove('tests/shell_post.txt')
        if os.path.exists('tests/test-hooks/input{{hooks}}/python_pre.txt'):
            os.remove('tests/test-hooks/input{{hooks}}/python_pre.txt')
        if os.path.exists('tests/test-hooks/input{{hooks}}/shell_post.txt'):
            os.remove('tests/test-hooks/input{{hooks}}/shell_post.txt')
        if os.path.exists('tests/context_post.txt'):
            os.remove('tests/context_post.txt')
 def fin_remove_additional_folders():
     if os.path.isdir("cookiecutter-pypackage"):
         utils.rmtree("cookiecutter-pypackage")
     if os.path.isdir("python_boilerplate"):
         utils.rmtree("python_boilerplate")
     if os.path.isdir("cookiecutter-trytonmodule"):
         utils.rmtree("cookiecutter-trytonmodule")
     if os.path.isdir("module_name"):
         utils.rmtree("module_name")
 def fin_remove_additional_folders():
     if os.path.isdir('cookiecutter-pypackage'):
         utils.rmtree('cookiecutter-pypackage')
     if os.path.isdir('boilerplate'):
         utils.rmtree('boilerplate')
     if os.path.isdir('cookiecutter-trytonmodule'):
         utils.rmtree('cookiecutter-trytonmodule')
     if os.path.isdir('module_name'):
         utils.rmtree('module_name')
 def fin_remove_additional_folders():
     if os.path.isdir('cookiecutter-pypackage'):
         utils.rmtree('cookiecutter-pypackage')
     if os.path.isdir('python_boilerplate'):
         utils.rmtree('python_boilerplate')
     if os.path.isdir('cookiecutter-trytonmodule'):
         utils.rmtree('cookiecutter-trytonmodule')
     if os.path.isdir('module_name'):
         utils.rmtree('module_name')
def bake_in_temp_dir(cookies, *args, **kwargs):
    """
    Delete the temporal directory that is created when executing the tests.

    https://github.com/audreyr/cookiecutter-pypackage/blob/master/tests/test_bake_project.py#L33

    :param cookies: pytest_cookies.Cookies, cookie to be baked and its temporal files will be removed
    """
    with git_disable_gpgsign():
        extra_context = kwargs.pop("extra_context", {})
        extra_context["_testing"] = True
        result = cookies.bake(*args, extra_context=extra_context, **kwargs)
        try:
            yield result
        finally:
            if result.project:
                rmtree(str(result.project))
예제 #46
0
def test_git_clone_checkout():
    repo_dir = vcs.clone(
        'https://github.com/audreyr/cookiecutter-pypackage.git',
        'console-script')
    git_dir = 'cookiecutter-pypackage'
    assert repo_dir == git_dir
    assert os.path.isfile(os.path.join('cookiecutter-pypackage', 'README.rst'))

    proc = subprocess.Popen(['git', 'symbolic-ref', 'HEAD'],
                            cwd=git_dir,
                            stdout=subprocess.PIPE)
    symbolic_ref = proc.communicate()[0]
    branch = symbolic_ref.decode(ENCODING).strip().split('/')[-1]
    assert 'console-script' == branch

    if os.path.isdir(git_dir):
        utils.rmtree(git_dir)
예제 #47
0
 def tearDown(self):
     if os.path.isdir('cookiecutter-pypackage'):
         utils.rmtree('cookiecutter-pypackage')
     if os.path.isdir('boilerplate'):
         utils.rmtree('boilerplate')
     if os.path.isdir('cookiecutter-trytonmodule'):
         utils.rmtree('cookiecutter-trytonmodule')
     if os.path.isdir('module_name'):
         utils.rmtree('module_name')
     super(TestCookiecutterRepoArg, self).tearDown()
예제 #48
0
 def tearDown(self):
     if os.path.isdir('cookiecutter-pypackage'):
         utils.rmtree('cookiecutter-pypackage')
     if os.path.isdir('boilerplate'):
         utils.rmtree('boilerplate')
     if os.path.isdir('cookiecutter-trytonmodule'):
         utils.rmtree('cookiecutter-trytonmodule')
     if os.path.isdir('module_name'):
         utils.rmtree('module_name')
     super(TestCookiecutterRepoArg, self).tearDown()
예제 #49
0
def test_make_sure_path_exists():
    """Verify correct True/False response from `utils.make_sure_path_exists`.

    Should return True if directory exist or created.
    Should return False if impossible to create directory (for example protected)
    """
    if sys.platform.startswith('win'):
        existing_directory = os.path.abspath(os.curdir)
        uncreatable_directory = 'a*b'
    else:
        existing_directory = '/usr/'
        uncreatable_directory = '/this-doesnt-exist-and-cant-be-created/'

    assert utils.make_sure_path_exists(existing_directory)
    assert utils.make_sure_path_exists('tests/blah')
    assert utils.make_sure_path_exists('tests/trailingslash/')
    assert not utils.make_sure_path_exists(uncreatable_directory)
    utils.rmtree('tests/blah/')
    utils.rmtree('tests/trailingslash/')
예제 #50
0
    def test_git_clone_checkout(self):
        repo_dir = vcs.clone(
            'https://github.com/audreyr/cookiecutter-pypackage.git',
            'console-script')
        git_dir = 'cookiecutter-pypackage'
        self.assertEqual(repo_dir, git_dir)
        self.assertTrue(
            os.path.isfile(os.path.join('cookiecutter-pypackage',
                                        'README.rst')))

        proc = subprocess.Popen(['git', 'symbolic-ref', 'HEAD'],
                                cwd=git_dir,
                                stdout=subprocess.PIPE)
        symbolic_ref = proc.communicate()[0]
        branch = symbolic_ref.decode(encoding).strip().split('/')[-1]
        self.assertEqual('console-script', branch)

        if os.path.isdir(git_dir):
            utils.rmtree(git_dir)
예제 #51
0
def cookiecutter(template, no_input=False, output_dir='.'):  # pragma: no cover
    """A clone of cookiecutter's main entry point.

    This does alot less than cookiecutter's main entry point but flavors it for ``angreal`` .

    :param template: The path to the template to use.
    :type template: str
    :param no_input: Don't use the defaults, defaults to False
    :type no_input: bool, optional
    """

    config_dict = get_user_config(config_file=None, default_config=False)

    repo_dir, cleanup = determine_repo_dir(
        template=template,
        abbreviations=config_dict['abbreviations'],
        clone_to_dir=config_dict['cookiecutters_dir'],
        checkout=None,
        no_input=no_input,
        password=None)

    template_name = os.path.basename(os.path.abspath(repo_dir))

    context_file = os.path.join(repo_dir, 'angreal.json')

    context = generate_context(context_file=context_file,
                               default_context=config_dict['default_context'],
                               extra_context=None)

    context['angreal'] = prompt_for_config(context, no_input)
    context['angreal']['_template'] = template

    dump(config_dict['replay_dir'], template_name, context)

    result = generate_files(repo_dir=repo_dir,
                            context=context,
                            overwrite_if_exists=False,
                            output_dir=output_dir)

    if cleanup:
        rmtree(cleanup)

    return result
예제 #52
0
def test_git_clone_checkout():
    repo_dir = vcs.clone(
        'https://github.com/audreyr/cookiecutter-pypackage.git',
        'console-script'
    )
    git_dir = 'cookiecutter-pypackage'
    assert repo_dir == git_dir
    assert os.path.isfile(os.path.join('cookiecutter-pypackage', 'README.rst'))

    proc = subprocess.Popen(
        ['git', 'symbolic-ref', 'HEAD'],
        cwd=git_dir,
        stdout=subprocess.PIPE
    )
    symbolic_ref = proc.communicate()[0]
    branch = symbolic_ref.decode(ENCODING).strip().split('/')[-1]
    assert 'console-script' == branch

    if os.path.isdir(git_dir):
        utils.rmtree(git_dir)
예제 #53
0
    def test_git_clone_checkout(self):
        repo_dir = vcs.clone(
            'https://github.com/audreyr/cookiecutter-pypackage.git',
            'console-script'
        )
        git_dir = 'cookiecutter-pypackage'
        self.assertEqual(repo_dir, git_dir)
        self.assertTrue(os.path.isfile(os.path.join('cookiecutter-pypackage', 'README.rst')))

        proc = subprocess.Popen(
            ['git', 'symbolic-ref', 'HEAD'],
            cwd=git_dir,
            stdout=subprocess.PIPE
        )
        symbolic_ref = proc.communicate()[0]
        branch = symbolic_ref.decode(encoding).strip().split('/')[-1]
        self.assertEqual('console-script', branch)

        if os.path.isdir(git_dir):
            utils.rmtree(git_dir)
예제 #54
0
def _run_hook_from_repo_dir(repo_dir, hook_name, project_dir, context,
                            delete_project_on_failure):
    """Run hook from repo directory, clean project directory if hook fails.

    :param repo_dir: Project template input directory.
    :param hook_name: The hook to execute.
    :param project_dir: The directory to execute the script from.
    :param context: Cookiecutter project context.
    :param delete_project_on_failure: Delete the project directory on hook
        failure?
    """
    with work_in(repo_dir):
        try:
            run_hook(hook_name, project_dir, context)
        except FailedHookException:
            if delete_project_on_failure:
                rmtree(project_dir)
            logger.error("Stopping generation because {} hook "
                         "script didn't exit successfully".format(hook_name))
            raise
예제 #55
0
 def tearDown(self):
     if os.path.isdir('fake-project'):
         utils.rmtree('fake-project')
     if os.path.isdir('fake-project-extra'):
         utils.rmtree('fake-project-extra')
     if os.path.isdir('fake-project-templated'):
         utils.rmtree('fake-project-templated')
예제 #56
0
    def restore_backup():
        # If it existed, restore ~/.cookiecutterrc
        # We never write to ~/.cookiecutterrc, so this logic is simpler.
        if user_config_found and os.path.exists(user_config_path_backup):
            shutil.copy(user_config_path_backup, user_config_path)
            os.remove(user_config_path_backup)

        # Carefully delete the created ~/.cookiecutters dir only in certain
        # conditions.
        cookie_dir_is_dir = os.path.isdir(cookiecutters_dir)
        if cookiecutters_dir_found:
            # Delete the created ~/.cookiecutters dir as long as a backup
            # exists
            if cookie_dir_is_dir and os.path.isdir(cookiecutters_dir_backup):
                utils.rmtree(cookiecutters_dir)
        else:
            # Delete the created ~/.cookiecutters dir.
            # There's no backup because it never existed
            if cookie_dir_is_dir:
                utils.rmtree(cookiecutters_dir)

        # Restore the user's default cookiecutters_dir contents
        if os.path.isdir(cookiecutters_dir_backup):
            shutil.copytree(cookiecutters_dir_backup, cookiecutters_dir)
        if os.path.isdir(cookiecutters_dir):
            utils.rmtree(cookiecutters_dir_backup)
 def fin_remove_additional_dirs():
     if os.path.isdir("fake-project"):
         utils.rmtree("fake-project")
     if os.path.isdir("fake-project-extra"):
         utils.rmtree("fake-project-extra")
     if os.path.isdir("fake-project-templated"):
         utils.rmtree("fake-project-templated")
예제 #58
0
 def fin_remove_additional_folders():
     if os.path.exists('tests/test-pyhooks/inputpyhooks'):
         utils.rmtree('tests/test-pyhooks/inputpyhooks')
     if os.path.exists('inputpyhooks'):
         utils.rmtree('inputpyhooks')
     if os.path.exists('tests/test-shellhooks'):
         utils.rmtree('tests/test-shellhooks')
예제 #59
0
 def fin_remove_additional_dirs():
     if os.path.isdir('cookiecutter-pypackage'):
         utils.rmtree('cookiecutter-pypackage')
     if os.path.isdir('cookiecutter-jquery'):
         utils.rmtree('cookiecutter-jquery')
     if os.path.isdir('boilerplate'):
         utils.rmtree('boilerplate')
예제 #60
0
 def fin_remove_additional_folders():
     if os.path.exists('tests/test-pyhooks/inputpyhooks'):
         utils.rmtree('tests/test-pyhooks/inputpyhooks')
     if os.path.exists('inputpyhooks'):
         utils.rmtree('inputpyhooks')
     if os.path.exists('tests/test-shellhooks'):
         utils.rmtree('tests/test-shellhooks')