How to use the cookiecutter.generate function in cookiecutter

To help you get started, we’ve selected a few cookiecutter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cookiecutter / cookiecutter / tests / test_output_folder.py View on Github external
def test_output_folder():
    context = generate.generate_context(
        context_file='tests/test-output-folder/cookiecutter.json'
    )
    generate.generate_files(
        context=context,
        repo_dir='tests/test-output-folder'
    )

    something = """Hi!
My name is Audrey Greenfeld.
It is 2014."""
    something2 = open('output_folder/something.txt').read()
    assert something == something2

    in_folder = "The color is green and the letter is D."
    in_folder2 = open('output_folder/folder/in_folder.txt').read()
    assert in_folder == in_folder2
github cookiecutter / cookiecutter / tests / test_output_folder.py View on Github external
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'
        )
github cookiecutter / cookiecutter / tests / test_generate_hooks.py View on Github external
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')
github cookiecutter / cookiecutter / tests / test_generate_file.py View on Github external
def test_generate_file_with_false_condition(env):
    infile = 'tests/files/{% if generate_file == \'y\' %}cheese.txt{% endif %}'
    generate.generate_file(
        project_dir=".",
        infile=infile,
        context={'generate_file': 'n'},
        env=env
    )
    assert not os.path.exists('tests/files/cheese.txt')
github cookiecutter / cookiecutter / tests / test_generate_copy_without_render.py View on Github external
def test_generate_copy_without_render_extensions():
    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',
                ]}
        },
        repo_dir='tests/test-generate-copy-without-render'
    )

    dir_contents = os.listdir('test_copy_without_render')

    assert '{{cookiecutter.repo_name}}-not-rendered' in dir_contents
github cookiecutter / cookiecutter / tests / test_generate_hooks.py View on Github external
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')
github cookiecutter / cookiecutter / tests / test_generate_files.py View on Github external
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')
github cookiecutter / cookiecutter / tests / test_generate.py View on Github external
def test_generate_file(self):
        env = Environment()
        env.loader = FileSystemLoader('.')
        infile = 'tests/files/{{generate_file}}.txt'
        generate.generate_file(
            project_dir=".",
            infile=infile,
            context={'generate_file': 'cheese'},
            env=env
        )
        self.assertTrue(os.path.isfile('tests/files/cheese.txt'))
        with open('tests/files/cheese.txt', 'rt') as f:
            generated_text = f.read()
            self.assertEqual(generated_text, 'Testing cheese')
github cookiecutter / cookiecutter / tests / test_generate_files.py View on Github external
def test_ensure_dir_is_templated_raises(invalid_dirname):
    with pytest.raises(exceptions.NonTemplatedInputDirException):
        generate.ensure_dir_is_templated(invalid_dirname)
github cookiecutter / cookiecutter / tests / test_generate_file.py View on Github external
def test_generate_file(env):
    infile = 'tests/files/{{generate_file}}.txt'
    generate.generate_file(
        project_dir=".",
        infile=infile,
        context={'generate_file': 'cheese'},
        env=env
    )
    assert os.path.isfile('tests/files/cheese.txt')
    with open('tests/files/cheese.txt', 'rt') as f:
        generated_text = f.read()
        assert generated_text == 'Testing cheese'