Ejemplo n.º 1
0
def test_run_failing_hook_preserves_existing_output_directory():
    repo_path = os.path.abspath('tests/test-hooks/')
    hooks_path = os.path.abspath('tests/test-hooks/hooks')

    hook_dir = os.path.join(repo_path, 'hooks')
    template = os.path.join(repo_path, 'input{{cookiecutter.hooks}}')
    os.mkdir(repo_path)
    os.mkdir(hook_dir)
    os.mkdir(template)

    hook_path = os.path.join(hooks_path, 'pre_gen_project.py')

    with open(hook_path, 'w') as f:
        f.write("#!/usr/bin/env python\n")
        f.write("import sys; sys.exit(1)\n")

    os.mkdir('inputhooks')
    with pytest.raises(FailedHookException) as excinfo:
        generate.generate_files(
            context={
                'cookiecutter': {'hooks': 'hooks'}
            },
            repo_dir='tests/test-hooks/',
            overwrite_if_exists=True
        )

    assert 'Hook script failed' in str(excinfo.value)
    assert os.path.exists('inputhooks')
Ejemplo n.º 2
0
 def test_generate_files_binaries(self):
     generate.generate_files(
         context={
             'cookiecutter': {'binary_test': 'binary_files'}
         },
         repo_dir='tests/test-generate-binaries'
     )
     self.assertTrue(os.path.isfile('inputbinary_files/logo.png'))
     self.assertTrue(os.path.isfile('inputbinary_files/.DS_Store'))
     self.assertTrue(os.path.isfile('inputbinary_files/readme.txt'))
     self.assertTrue(
         os.path.isfile('inputbinary_files/some_font.otf')
     )
     self.assertTrue(
         os.path.isfile('inputbinary_files/binary_files/logo.png')
     )
     self.assertTrue(
         os.path.isfile('inputbinary_files/binary_files/.DS_Store')
     )
     self.assertTrue(
         os.path.isfile('inputbinary_files/binary_files/readme.txt')
     )
     self.assertTrue(
         os.path.isfile('inputbinary_files/binary_files/some_font.otf')
     )
     self.assertTrue(
         os.path.isfile('inputbinary_files/binary_files/binary_files/logo.png')
     )
Ejemplo n.º 3
0
    def test_generate_files_permissions(self):
        """
        simple.txt and script.sh should retain their respective 0o644 and
        0o755 permissions
        """
        generate.generate_files(
            context={
                'cookiecutter': {'permissions': 'permissions'}
            },
            repo_dir='tests/test-generate-files-permissions'
        )

        self.assertTrue(os.path.isfile('inputpermissions/simple.txt'))

        # simple.txt should still be 0o644
        self.assertEquals(
            os.stat('tests/test-generate-files-permissions/input{{cookiecutter.permissions}}/simple.txt').st_mode & 0o777,
            os.stat('inputpermissions/simple.txt').st_mode & 0o777
        )

        self.assertTrue(os.path.isfile('inputpermissions/script.sh'))

        # script.sh should still be 0o755
        self.assertEquals(
            os.stat('tests/test-generate-files-permissions/input{{cookiecutter.permissions}}/script.sh').st_mode & 0o777,
            os.stat('inputpermissions/script.sh').st_mode & 0o777
        )
Ejemplo n.º 4
0
 def test_run_shell_hooks(self):
     generate.generate_files(
         context={'shellhooks': 'shellhooks'},
         template_dir='tests/test-shellhooks/input{{shellhooks}}'
     )
     self.assertTrue(os.path.exists('tests/test-shellhooks/inputshellhooks/shell_pre.txt'))
     self.assertTrue(os.path.exists('tests/test-shellhooks/inputshellhooks/shell_post.txt'))
Ejemplo n.º 5
0
 def test_run_python_hooks(self):
     generate.generate_files(
         context={'pyhooks': 'pyhooks'},
         template_dir='tests/test-pyhooks/input{{pyhooks}}'
     )
     self.assertTrue(os.path.exists('tests/test-pyhooks/inputpyhooks/python_pre.txt'))
     self.assertTrue(os.path.exists('tests/test-pyhooks/inputpyhooks/python_post.txt'))
Ejemplo n.º 6
0
 def test_ignore_hooks_dirs(self):
     generate.generate_files(
         context={"cookiecutter": {"pyhooks": "pyhooks"}},
         repo_dir="tests/test-pyhooks/",
         output_dir="tests/test-pyhooks/",
     )
     self.assertFalse(os.path.exists("tests/test-pyhooks/inputpyhooks/hooks"))
Ejemplo n.º 7
0
    def test_generate_files_permissions(self):
        """
        simple.txt and script.sh should retain their respective 0o644 and
        0o755 permissions
        """
        generate.generate_files(
            context={"cookiecutter": {"permissions": "permissions"}}, repo_dir="tests/test-generate-files-permissions"
        )

        self.assertTrue(os.path.isfile("inputpermissions/simple.txt"))

        # simple.txt should still be 0o644
        self.assertEquals(
            os.stat("tests/test-generate-files-permissions/input{{cookiecutter.permissions}}/simple.txt").st_mode
            & 0o777,
            os.stat("inputpermissions/simple.txt").st_mode & 0o777,
        )

        self.assertTrue(os.path.isfile("inputpermissions/script.sh"))

        # script.sh should still be 0o755
        self.assertEquals(
            os.stat("tests/test-generate-files-permissions/input{{cookiecutter.permissions}}/script.sh").st_mode
            & 0o777,
            os.stat("inputpermissions/script.sh").st_mode & 0o777,
        )
Ejemplo n.º 8
0
def api():
    scaffold = get_scaffold('api')
    context = create_context('api')
    context['cookiecutter']['project_name'] = config.get_project_name()
    generate_files(repo_dir=scaffold, context=context)
    print(u"Created api addon")
    factory_api()
    config.addons(new_addon='api')
Ejemplo n.º 9
0
def test_generate_files_absolute_path():
    generate.generate_files(
        context={
            'cookiecutter': {'food': 'pizzä'}
        },
        repo_dir=os.path.abspath('tests/test-generate-files')
    )
    assert os.path.isfile('inputpizzä/simple.txt')
Ejemplo n.º 10
0
 def test_run_python_hooks_cwd(self):
     generate.generate_files(
         context={'cookiecutter': {
             'pyhooks': 'pyhooks'
         }},
         repo_dir='tests/test-pyhooks/')
     self.assertTrue(os.path.exists('inputpyhooks/python_pre.txt'))
     self.assertTrue(os.path.exists('inputpyhooks/python_post.txt'))
Ejemplo n.º 11
0
 def test_generate_files(self):
     generate.generate_files(context={"cookiecutter": {"food": "pizzä"}}, repo_dir="tests/test-generate-files")
     self.assertTrue(os.path.isfile("inputpizzä/simple.txt"))
     simple_text = open("inputpizzä/simple.txt", "rt").read()
     if PY3:
         self.assertEqual(simple_text, "I eat pizzä")
     else:
         self.assertEqual(simple_text, "I eat pizzä".encode("utf-8"))
Ejemplo n.º 12
0
 def test_run_shell_hooks(self):
     generate.generate_files(
         context={"cookiecutter": {"shellhooks": "shellhooks"}},
         repo_dir="tests/test-shellhooks/",
         output_dir="tests/test-shellhooks/",
     )
     self.assertTrue(os.path.exists("tests/test-shellhooks/inputshellhooks/shell_pre.txt"))
     self.assertTrue(os.path.exists("tests/test-shellhooks/inputshellhooks/shell_post.txt"))
Ejemplo n.º 13
0
 def test_run_python_hooks(self):
     generate.generate_files(
         context={"cookiecutter": {"pyhooks": "pyhooks"}},
         repo_dir="tests/test-pyhooks/".replace("/", os.sep),
         output_dir="tests/test-pyhooks/".replace("/", os.sep),
     )
     self.assertTrue(os.path.exists("tests/test-pyhooks/inputpyhooks/python_pre.txt"))
     self.assertTrue(os.path.exists("tests/test-pyhooks/inputpyhooks/python_post.txt"))
Ejemplo n.º 14
0
 def test_generate_files_absolute_path(self):
     generate.generate_files(
         context={
             'cookiecutter': {'food': 'pizzä'}
         },
         repo_dir=os.path.abspath('tests/test-generate-files')
     )
     self.assertTrue(os.path.isfile('inputpizzä/simple.txt'))
Ejemplo n.º 15
0
def test_generate_files_absolute_path(tmp_path):
    """Verify usage of absolute path does not change files generation behaviour."""
    generate.generate_files(
        context={'cookiecutter': {'food': 'pizzä'}},
        repo_dir=Path('tests/test-generate-files').absolute(),
        output_dir=tmp_path,
    )
    assert Path(tmp_path, 'inputpizzä/simple.txt').is_file()
Ejemplo n.º 16
0
def test_generate_files_nontemplated_exception():
    with pytest.raises(exceptions.NonTemplatedInputDirException):
        generate.generate_files(
            context={
                'cookiecutter': {'food': 'pizza'}
            },
            repo_dir='tests/test-generate-files-nontemplated'
        )
Ejemplo n.º 17
0
 def test_generate_files_output_dir(self):
     os.mkdir("tests/custom_output_dir")
     generate.generate_files(
         context={"cookiecutter": {"food": "pizzä"}},
         repo_dir=os.path.abspath("tests/test-generate-files"),
         output_dir="tests/custom_output_dir",
     )
     self.assertTrue(os.path.isfile("tests/custom_output_dir/inputpizzä/simple.txt"))
Ejemplo n.º 18
0
 def test_generate_files(self):
     generate.generate_files(
         context={'food': 'pizza'},
         template_dir='tests/input{{food}}'
     )
     self.assertTrue(os.path.isfile('tests/inputpizza/simple.txt'))
     simple_text = open('tests/inputpizza/simple.txt', 'rt').read()
     self.assertEqual(simple_text, 'I eat pizza')
def test_generate_files_absolute_path(monkeypatch, tmp_path):
    """Verify usage of absolute path does not change files generation behaviour."""
    monkeypatch.chdir(os.path.join(os.path.abspath(os.path.dirname(__file__))))
    generate.generate_files(
        context={'cookiecutter': {'food': 'pizzä'}},
        repo_dir=Path('test-generate-files').absolute(),
        output_dir=tmp_path,
    )
    assert Path(tmp_path, u'inputpizzä/simple.txt').is_file()
Ejemplo n.º 20
0
def test_generate_files_absolute_path():
    """Verify usage of `abspath` does not change files generation behaviour."""
    generate.generate_files(
        context={'cookiecutter': {
            'food': 'pizzä'
        }},
        repo_dir=os.path.abspath('tests/test-generate-files'),
    )
    assert os.path.isfile('inputpizzä/simple.txt')
Ejemplo n.º 21
0
 def test_generate_files(self):
     generate.generate_files(context={'cookiecutter': {
         'food': 'pizzä'
     }},
                             repo_dir='tests/test-generate-files')
     self.assertTrue(os.path.isfile('inputpizzä/simple.txt'))
     simple_text = io.open('inputpizzä/simple.txt', 'rt',
                           encoding='utf-8').read()
     self.assertEqual(simple_text, u'I eat pizzä')
Ejemplo n.º 22
0
def test_ignore_hooks_dirs():
    generate.generate_files(
        context={"cookiecutter": {
            "pyhooks": "pyhooks"
        }},
        repo_dir="tests/test-pyhooks/",
        output_dir="tests/test-pyhooks/",
    )
    assert not os.path.exists("tests/test-pyhooks/inputpyhooks/hooks")
Ejemplo n.º 23
0
 def test_ignore_hooks_dirs(self):
     generate.generate_files(
         context={'cookiecutter': {
             'pyhooks': 'pyhooks'
         }},
         repo_dir='tests/test-pyhooks/',
         output_dir='tests/test-pyhooks/')
     self.assertFalse(
         os.path.exists('tests/test-pyhooks/inputpyhooks/hooks'))
Ejemplo n.º 24
0
 def test_generate_files(self):
     generate.generate_files(context={'food': 'pizzä'},
                             template_dir='tests/input{{food}}')
     self.assertTrue(os.path.isfile('tests/inputpizzä/simple.txt'))
     simple_text = open('tests/inputpizzä/simple.txt', 'rt').read()
     if PY3:
         self.assertEqual(simple_text, 'I eat pizzä')
     else:
         self.assertEqual(simple_text, 'I eat pizzä'.encode('utf-8'))
Ejemplo n.º 25
0
 def test_ignore_hooks_dirs(self):
     generate.generate_files(
         context={
             'cookiecutter' : {'pyhooks': 'pyhooks'}
         },
         repo_dir='tests/test-pyhooks/',
         output_dir='tests/test-pyhooks/'
     )
     self.assertFalse(os.path.exists('tests/test-pyhooks/inputpyhooks/hooks'))
Ejemplo n.º 26
0
def test_generate_copy_without_render_extensions():
    """Verify correct work of `_copy_without_render` context option.

    Some files/directories should be rendered during invocation,
    some just copied, without any modification.
    """
    generate.generate_files(
        context={
            'cookiecutter': {
                'repo_name': 'test_copy_without_render',
                'render_test': 'I have been rendered!',
                '_copy_without_render': [
                    '*not-rendered',
                    'rendered/not_rendered.yml',
                    '*.txt',
                    '{{cookiecutter.repo_name}}-rendered/README.md',
                ],
            }
        },
        repo_dir='tests/generate/test-generate-copy-without-render',
    )

    dir_contents = os.listdir('test_copy_without_render')

    assert 'test_copy_without_render-not-rendered' in dir_contents
    assert 'test_copy_without_render-rendered' in dir_contents

    with open('test_copy_without_render/README.txt') as f:
        assert '{{cookiecutter.render_test}}' in f.read()

    with open('test_copy_without_render/README.rst') as f:
        assert 'I have been rendered!' in f.read()

    with open(
        'test_copy_without_render/test_copy_without_render-rendered/README.txt'
    ) as f:
        assert '{{cookiecutter.render_test}}' in f.read()

    with open(
        'test_copy_without_render/test_copy_without_render-rendered/README.rst'
    ) as f:
        assert 'I have been rendered' in f.read()

    with open(
        'test_copy_without_render/'
        'test_copy_without_render-not-rendered/'
        'README.rst'
    ) as f:
        assert '{{cookiecutter.render_test}}' in f.read()

    with open('test_copy_without_render/rendered/not_rendered.yml') as f:
        assert '{{cookiecutter.render_test}}' in f.read()

    with open(
        'test_copy_without_render/' 'test_copy_without_render-rendered/' 'README.md'
    ) as f:
        assert '{{cookiecutter.render_test}}' in f.read()
Ejemplo n.º 27
0
def test_generate_files_output_dir():
    os.mkdir('tests/custom_output_dir')
    generate.generate_files(
        context={'cookiecutter': {
            'food': 'pizzä'
        }},
        repo_dir=os.path.abspath('tests/test-generate-files'),
        output_dir='tests/custom_output_dir')
    assert os.path.isfile('tests/custom_output_dir/inputpizzä/simple.txt')
Ejemplo n.º 28
0
 def test_run_python_hooks_cwd(self):
     generate.generate_files(
         context={
             'cookiecutter' : {'pyhooks': 'pyhooks'}
         },
         repo_dir='tests/test-pyhooks/'
     )
     self.assertTrue(os.path.exists('inputpyhooks/python_pre.txt'))
     self.assertTrue(os.path.exists('inputpyhooks/python_post.txt'))
Ejemplo n.º 29
0
def test_run_python_hooks():
    generate.generate_files(
        context={'cookiecutter': {
            'pyhooks': 'pyhooks'
        }},
        repo_dir='tests/test-pyhooks/'.replace("/", os.sep),
        output_dir='tests/test-pyhooks/'.replace("/", os.sep))
    assert os.path.exists('tests/test-pyhooks/inputpyhooks/python_pre.txt')
    assert os.path.exists('tests/test-pyhooks/inputpyhooks/python_post.txt')
Ejemplo n.º 30
0
def test_run_python_hooks_cwd():
    generate.generate_files(
        context={"cookiecutter": {
            "pyhooks": "pyhooks"
        }},
        repo_dir="tests/test-pyhooks/",
    )
    assert os.path.exists("inputpyhooks/python_pre.txt")
    assert os.path.exists("inputpyhooks/python_post.txt")
Ejemplo n.º 31
0
def users():
    scaffold = get_scaffold('users')
    context = create_context('users')
    context['cookiecutter']['project_name'] = config.get_project_name()
    generate_files(repo_dir=scaffold, context=context)
    print(u"Created user addon")
    factory_users()
    manage_users()
    requirements(u'flask-login', u'flask-principal')
    config.addons(new_addon='users')
Ejemplo n.º 32
0
 def test_generate_files(self):
     generate.generate_files(
         context={
             'cookiecutter': {'food': 'pizzä'}
         },
         repo_dir='tests/test-generate-files'
     )
     self.assertTrue(os.path.isfile('inputpizzä/simple.txt'))
     simple_text = io.open('inputpizzä/simple.txt', 'rt', encoding='utf-8').read()
     self.assertEqual(simple_text, u'I eat pizzä')
Ejemplo n.º 33
0
def test_exception_when_output_folder_exists():
    context = generate.generate_context(
        context_file='tests/test-output-folder/cookiecutter.json')
    output_folder = context['cookiecutter']['test_name']

    if not os.path.exists(output_folder):
        os.makedirs(output_folder)
    with pytest.raises(exceptions.OutputDirExistsException):
        generate.generate_files(context=context,
                                repo_dir='tests/test-output-folder')
Ejemplo n.º 34
0
 def test_run_python_hooks(self):
     generate.generate_files(
         context={
             'cookiecutter' : {'pyhooks': 'pyhooks'}
         },
         repo_dir='tests/test-pyhooks/'.replace("/", os.sep),
         output_dir='tests/test-pyhooks/'.replace("/", os.sep)
     )
     self.assertTrue(os.path.exists('tests/test-pyhooks/inputpyhooks/python_pre.txt'))
     self.assertTrue(os.path.exists('tests/test-pyhooks/inputpyhooks/python_post.txt'))
Ejemplo n.º 35
0
def test_ignore_hooks_dirs():
    """Verify hooks directory not created in target location on files generation."""
    generate.generate_files(
        context={'cookiecutter': {
            'pyhooks': 'pyhooks'
        }},
        repo_dir='tests/test-pyhooks/',
        output_dir='tests/test-pyhooks/',
    )
    assert not os.path.exists('tests/test-pyhooks/inputpyhooks/hooks')
Ejemplo n.º 36
0
 def test_generate_binary_files_in_nested_jinja_path(self):
     generate.generate_files(
         context={'binary_test': 'binary_files'},
         template_dir='tests/input{{binary_test}}'
     )
     expected = ['tests/inputbinary_files/binary_files/logo.png',
                 "tests/inputbinary_files/binary_files/.DS_Store",
                 "tests/inputbinary_files/binary_files/readme.txt"]
     for each in expected:
         self.assertTrue(os.path.isfile(each))
Ejemplo n.º 37
0
 def test_generate_binary_files_in_nested_jinja_path(self):
     generate.generate_files(
         context={'binary_test': 'binary_files'},
         template_dir='tests/input{{binary_test}}'
     )
     expected = ['tests/inputbinary_files/binary_files/logo.png',
                 "tests/inputbinary_files/binary_files/.DS_Store",
                 "tests/inputbinary_files/binary_files/readme.txt"]
     for each in expected:
         self.assertTrue(os.path.isfile(each))
Ejemplo n.º 38
0
def test_run_python_hooks():
    generate.generate_files(
        context={"cookiecutter": {
            "pyhooks": "pyhooks"
        }},
        repo_dir="tests/test-pyhooks/".replace("/", os.sep),
        output_dir="tests/test-pyhooks/".replace("/", os.sep),
    )
    assert os.path.exists("tests/test-pyhooks/inputpyhooks/python_pre.txt")
    assert os.path.exists("tests/test-pyhooks/inputpyhooks/python_post.txt")
Ejemplo n.º 39
0
 def test_generate_files_output_dir(self):
     os.mkdir('tests/custom_output_dir')
     generate.generate_files(
         context={
             'cookiecutter': {'food': 'pizzä'}
         },
         repo_dir=os.path.abspath('tests/test-generate-files'),
         output_dir='tests/custom_output_dir'
     )
     self.assertTrue(os.path.isfile('tests/custom_output_dir/inputpizzä/simple.txt'))
Ejemplo n.º 40
0
 def test_generate_files_binaries(self):
     generate.generate_files(
         context={'binary_test': 'binary_files'},
         template_dir='tests/input{{binary_test}}'
     )
     self.assertTrue(os.path.isfile('tests/inputbinary_files/logo.png'))
     self.assertTrue(os.path.isfile('tests/inputbinary_files/readme.txt'))
     self.assertTrue(
         os.path.isfile('tests/inputbinary_files/some_font.otf')
     )
Ejemplo n.º 41
0
 def test_run_shell_hooks(self):
     generate.generate_files(
         context={
             'cookiecutter' : {'shellhooks': 'shellhooks'}
         },
         repo_dir='tests/test-shellhooks/',
         output_dir='tests/test-shellhooks/'
     )
     self.assertTrue(os.path.exists('tests/test-shellhooks/inputshellhooks/shell_pre.txt'))
     self.assertTrue(os.path.exists('tests/test-shellhooks/inputshellhooks/shell_post.txt'))
Ejemplo n.º 42
0
 def test_run_shell_hooks(self):
     generate.generate_files(
         context={
             'cookiecutter' : {'shellhooks': 'shellhooks'}
         },
         repo_dir='tests/test-shellhooks/',
         output_dir='tests/test-shellhooks/'
     )
     self.assertTrue(os.path.exists('tests/test-shellhooks/inputshellhooks/shell_pre.txt'))
     self.assertTrue(os.path.exists('tests/test-shellhooks/inputshellhooks/shell_post.txt'))
Ejemplo n.º 43
0
def render_template(output_directory, config_filename, force=False):
    import qhub

    input_directory = pathlib.Path(qhub.__file__).parent / "template"

    # would be nice to remove assumption that input directory
    # is in local filesystem
    input_directory = pathlib.Path(input_directory)
    if not input_directory.is_dir():
        raise ValueError(f"input directory={input_directory} is not a directory")

    output_directory = pathlib.Path(output_directory).resolve()
    # due to cookiecutter requiring a template directory folder
    # we take the output directory and split into two components
    repo_directory = output_directory.name
    output_directory = output_directory.parent

    # mkdir all the way down to repo dir so we can copy .gitignore into it in remove_existing_renders
    (output_directory / repo_directory).mkdir(exist_ok=True, parents=True)

    filename = pathlib.Path(config_filename)

    if not filename.is_file():
        raise ValueError(f"cookiecutter configuration={filename} is not filename")

    config = load_yaml(filename)

    # For any config values that start with
    # QHUB_SECRET_, set the values using the
    # corresponding env var.
    set_env_vars_in_config(config)

    config["repo_directory"] = repo_directory
    patch_dask_gateway_extra_config(config)

    with (input_directory / "cookiecutter.json").open() as f:
        config = collections.ChainMap(config, json.load(f))

    patch_versioning_extra_config(config)

    patch_terraform_extensions(config)

    config["qhub_config_yaml_path"] = str(filename.absolute())

    remove_existing_renders(
        dest_repo_dir=output_directory / repo_directory,
        verbosity=0,
    )

    generate_files(
        repo_dir=str(input_directory),
        context={"cookiecutter": config},
        output_dir=str(output_directory),
        overwrite_if_exists=force,
    )
def test_generate_files():
    generate.generate_files(
        context={"cookiecutter": {"food": "pizzä"}},
        repo_dir="tests/test-generate-files",
    )

    simple_file = "inputpizzä/simple.txt"
    assert os.path.isfile(simple_file)

    simple_text = io.open(simple_file, "rt", encoding="utf-8").read()
    assert simple_text == "I eat pizzä"
Ejemplo n.º 45
0
 def test_generate_files(self):
     generate.generate_files(
         context={'food': 'pizzä'},
         template_dir='tests/input{{food}}'
     )
     self.assertTrue(os.path.isfile('tests/inputpizzä/simple.txt'))
     simple_text = open('tests/inputpizzä/simple.txt', 'rt').read()
     if PY3:
         self.assertEqual(simple_text, 'I eat pizzä')
     else:
         self.assertEqual(simple_text, 'I eat pizzä'.encode('utf-8'))
Ejemplo n.º 46
0
def test_generate_files_nontemplated_exception():
    """
    Verify `generate_files` raises when no directories to render exist.

    Note: Check `tests/test-generate-files-nontemplated` location to understand.
    """
    with pytest.raises(exceptions.NonTemplatedInputDirException):
        generate.generate_files(
            context={'cookiecutter': {'food': 'pizza'}},
            repo_dir='tests/test-generate-files-nontemplated',
        )
Ejemplo n.º 47
0
 def test_generate_files_with_trailing_newline(self):
     generate.generate_files(
         context={
             'cookiecutter': {'food': 'pizzä'}
         },
         repo_dir='tests/test-generate-files'
     )
     self.assertTrue(os.path.isfile('inputpizzä/simple-with-newline.txt'))
     with io.open('inputpizzä/simple-with-newline.txt', 'r', encoding='utf-8') as f:
         simple_text = f.read()
     self.assertEqual(simple_text, u'I eat pizzä\n')
Ejemplo n.º 48
0
 def test_generate_files_binaries(self):
     generate.generate_files(
         context={'binary_test': 'binary_files'},
         template_dir='tests/input{{binary_test}}'
     )
     self.assertTrue(os.path.isfile('tests/inputbinary_files/logo.png'))
     self.assertTrue(os.path.isfile('tests/inputbinary_files/.DS_Store'))
     self.assertTrue(os.path.isfile('tests/inputbinary_files/readme.txt'))
     self.assertTrue(
         os.path.isfile('tests/inputbinary_files/some_font.otf')
     )
Ejemplo n.º 49
0
def test_empty_hooks():
    # OSError.errno=8 is not thrown on Windows when the script is empty
    # because it always runs through shell instead of needing a shebang.
    with pytest.raises(FailedHookException) as excinfo:
        generate.generate_files(
            context={'cookiecutter': {
                'shellhooks': 'shellhooks'
            }},
            repo_dir='tests/test-shellhooks-empty/',
            overwrite_if_exists=True)
    assert 'shebang' in str(excinfo.value)
Ejemplo n.º 50
0
def test_generate_files():
    generate.generate_files(context={'cookiecutter': {
        'food': 'pizzä'
    }},
                            repo_dir='tests/test-generate-files')

    simple_file = 'inputpizzä/simple.txt'
    assert os.path.isfile(simple_file)

    simple_text = io.open(simple_file, 'rt', encoding='utf-8').read()
    assert simple_text == u'I eat pizzä'
Ejemplo n.º 51
0
def frontend():
    user_dir = get_user_directory()
    if not path.exists(user_dir):
        setup_user_directory()
    scaffold = get_scaffold('frontend')
    context = create_context('frontend')
    context['cookiecutter']['project_name'] = config.get_project_name()
    context['cookiecutter']['directory_name'] = 'frontend'
    generate_files(repo_dir=scaffold, context=context)
    setup_frontend_symlink()
    config.addons(new_addon='frontend')
    print(u"Created frontend workflow")
Ejemplo n.º 52
0
def test_generate_files():
    """Verify directory name correctly rendered with unicode containing context."""
    generate.generate_files(
        context={'cookiecutter': {'food': 'pizzä'}},
        repo_dir='tests/test-generate-files',
    )

    simple_file = 'inputpizzä/simple.txt'
    assert os.path.isfile(simple_file)

    simple_text = io.open(simple_file, 'rt', encoding='utf-8').read()
    assert simple_text == 'I eat pizzä'
Ejemplo n.º 53
0
def create_project(name, directory=None):
    if not is_name_valid(name):
        raise StandardError("Name given is invalid")
    project_path = directory if directory else name
    if path.exists(project_path):
        raise OSError("Directory already exists")
    context = create_context('base')
    context['cookiecutter']['directory_name'] = project_path
    context['cookiecutter']['project_name'] = name
    context['cookiecutter']['root_project_name'] = name.lower()
    generate_files(repo_dir=get_scaffold('base'), context=context)
    config.create(name, project_path)
Ejemplo n.º 54
0
def test_exception_when_output_folder_exists(monkeypatch):
    """Tests should raise error as output folder created before `generate_files`."""
    monkeypatch.chdir(os.path.join(os.path.abspath(os.path.dirname(__file__))))

    context = generate.generate_context(
        context_file='test-output-folder/cookiecutter.json')
    output_folder = context['cookiecutter']['test_name']

    if not os.path.exists(output_folder):
        os.makedirs(output_folder)
    with pytest.raises(exceptions.OutputDirExistsException):
        generate.generate_files(context=context, repo_dir='test-output-folder')
Ejemplo n.º 55
0
def test_empty_hooks():
    # OSError.errno=8 is not thrown on Windows when the script is empty
    # because it always runs through shell instead of needing a shebang.
    with pytest.raises(FailedHookException) as excinfo:
        generate.generate_files(
            context={
                'cookiecutter': {'shellhooks': 'shellhooks'}
            },
            repo_dir='tests/test-shellhooks-empty/',
            overwrite_if_exists=True
        )
    assert 'shebang' in str(excinfo.value)
def test_generate_files_with_trailing_newline():
    generate.generate_files(
        context={"cookiecutter": {"food": "pizzä"}},
        repo_dir="tests/test-generate-files",
    )

    newline_file = "inputpizzä/simple-with-newline.txt"
    assert os.path.isfile(newline_file)

    with io.open(newline_file, "r", encoding="utf-8") as f:
        simple_text = f.read()
    assert simple_text == "I eat pizzä\n"
Ejemplo n.º 57
0
def test_run_shell_hooks():
    make_test_repo('tests/test-shellhooks')
    generate.generate_files(
        context={'cookiecutter': {
            'shellhooks': 'shellhooks'
        }},
        repo_dir='tests/test-shellhooks/',
        output_dir='tests/test-shellhooks/')
    shell_pre_file = 'tests/test-shellhooks/inputshellhooks/shell_pre.txt'
    shell_post_file = 'tests/test-shellhooks/inputshellhooks/shell_post.txt'
    assert os.path.exists(shell_pre_file)
    assert os.path.exists(shell_post_file)
Ejemplo n.º 58
0
def test_generate_files_with_trailing_newline():
    generate.generate_files(context={'cookiecutter': {
        'food': 'pizzä'
    }},
                            repo_dir='tests/test-generate-files')

    newline_file = 'inputpizzä/simple-with-newline.txt'
    assert os.path.isfile(newline_file)

    with io.open(newline_file, 'r', encoding='utf-8') as f:
        simple_text = f.read()
    assert simple_text == u'I eat pizzä\n'
Ejemplo n.º 59
0
def test_raise_undefined_variable_file_name(tmpdir, undefined_context):
    output_dir = tmpdir.mkdir('output')

    with pytest.raises(exceptions.UndefinedVariableInTemplate) as err:
        generate.generate_files(repo_dir='tests/undefined-variable/file-name/',
                                output_dir=str(output_dir),
                                context=undefined_context)
    error = err.value
    assert "Unable to create file '{{cookiecutter.foobar}}'" == error.message
    assert error.context == undefined_context

    assert not output_dir.join('testproject').exists()
Ejemplo n.º 60
0
def test_run_shell_hooks():
    make_test_repo('tests/test-shellhooks')
    generate.generate_files(
        context={
            'cookiecutter': {'shellhooks': 'shellhooks'}
        },
        repo_dir='tests/test-shellhooks/',
        output_dir='tests/test-shellhooks/'
    )
    shell_pre_file = 'tests/test-shellhooks/inputshellhooks/shell_pre.txt'
    shell_post_file = 'tests/test-shellhooks/inputshellhooks/shell_post.txt'
    assert os.path.exists(shell_pre_file)
    assert os.path.exists(shell_post_file)