1
|
|
|
"""Verify Jinja2 filters/extensions are available from pre-gen/post-gen hooks.""" |
2
|
|
|
import os |
3
|
|
|
|
4
|
|
|
import freezegun |
5
|
|
|
import pytest |
6
|
|
|
import uuid |
7
|
|
|
|
8
|
|
|
from cookiecutter.main import cookiecutter |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
@pytest.fixture(autouse=True) |
12
|
|
|
def freeze(): |
13
|
|
|
"""Fixture. Make time stating during all tests in this file.""" |
14
|
|
|
freezer = freezegun.freeze_time("2015-12-09 23:33:01") |
15
|
|
|
freezer.start() |
16
|
|
|
yield |
17
|
|
|
freezer.stop() |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
def test_jinja2_time_extension(tmpdir): |
21
|
|
|
"""Verify Jinja2 time extension work correctly.""" |
22
|
|
|
project_dir = cookiecutter( |
23
|
|
|
'tests/test-extensions/default/', no_input=True, output_dir=str(tmpdir) |
24
|
|
|
) |
25
|
|
|
changelog_file = os.path.join(project_dir, 'HISTORY.rst') |
26
|
|
|
assert os.path.isfile(changelog_file) |
27
|
|
|
|
28
|
|
|
with open(changelog_file, 'r', encoding='utf-8') as f: |
29
|
|
|
changelog_lines = f.readlines() |
30
|
|
|
|
31
|
|
|
expected_lines = [ |
32
|
|
|
'History\n', |
33
|
|
|
'-------\n', |
34
|
|
|
'\n', |
35
|
|
|
'0.1.0 (2015-12-09)\n', |
36
|
|
|
'------------------\n', |
37
|
|
|
'\n', |
38
|
|
|
'First release on PyPI.\n', |
39
|
|
|
] |
40
|
|
|
assert expected_lines == changelog_lines |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
def test_jinja2_slugify_extension(tmpdir): |
44
|
|
|
"""Verify Jinja2 slugify extension work correctly.""" |
45
|
|
|
project_dir = cookiecutter( |
46
|
|
|
'tests/test-extensions/default/', no_input=True, output_dir=str(tmpdir) |
47
|
|
|
) |
48
|
|
|
|
49
|
|
|
assert os.path.basename(project_dir) == "it-s-slugified-foobar" |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
def test_jinja2_uuid_extension(tmpdir): |
53
|
|
|
"""Verify Jinja2 uuid extension work correctly.""" |
54
|
|
|
project_dir = cookiecutter( |
55
|
|
|
'tests/test-extensions/default/', no_input=True, output_dir=str(tmpdir) |
56
|
|
|
) |
57
|
|
|
changelog_file = os.path.join(project_dir, 'id') |
58
|
|
|
assert os.path.isfile(changelog_file) |
59
|
|
|
|
60
|
|
|
with open(changelog_file, 'r', encoding='utf-8') as f: |
61
|
|
|
changelog_lines = f.readlines() |
62
|
|
|
|
63
|
|
|
uuid.UUID(changelog_lines[0], version=4) |
64
|
|
|
assert True |
65
|
|
|
|