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