mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-22 17:47:08 +03:00
Integrate additional checks of base.py with slight improvements
This commit is contained in:
parent
6c339a1417
commit
646e376a8e
|
@ -1,6 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
import pytest
|
||||
from binaryornot.check import is_binary
|
||||
|
||||
PATTERN = "{{(\s?cookiecutter)[.](.*?)}}"
|
||||
RE_OBJ = re.compile(PATTERN)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def context():
|
||||
|
@ -18,6 +26,36 @@ def context():
|
|||
}
|
||||
|
||||
|
||||
def build_files_list(root_dir):
|
||||
"""Build a list containing absolute paths to the generated files."""
|
||||
return [
|
||||
os.path.join(dirpath, file_path)
|
||||
for dirpath, subdirs, files in os.walk(root_dir)
|
||||
for file_path in files
|
||||
]
|
||||
|
||||
|
||||
def check_paths(paths):
|
||||
"""Method to check all paths have correct substitutions,
|
||||
used by other tests cases
|
||||
"""
|
||||
# Assert that no match is found in any of the files
|
||||
for path in paths:
|
||||
if is_binary(path):
|
||||
continue
|
||||
for line in open(path, 'r'):
|
||||
match = RE_OBJ.search(line)
|
||||
msg = "cookiecutter variable not replaced in {}"
|
||||
assert match is None, msg.format(path)
|
||||
|
||||
|
||||
def test_default_configuration(cookies, context):
|
||||
result = cookies.bake(extra_context=context)
|
||||
assert result.exit_code == 0
|
||||
assert result.exception is None
|
||||
assert result.project.basename == context['repo_name']
|
||||
assert result.project.isdir()
|
||||
|
||||
paths = build_files_list(str(result.project))
|
||||
assert paths
|
||||
check_paths(paths)
|
||||
|
|
Loading…
Reference in New Issue
Block a user