forked from cookiecutter/cookiecutter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_get_config.py
81 lines (68 loc) · 2.34 KB
/
test_get_config.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
test_get_config
---------------
Tests formerly known from a unittest residing in test_config.py named
TestGetConfig.test_get_config
TestGetConfig.test_get_config_does_not_exist
TestGetConfig.test_invalid_config
TestGetConfigWithDefaults.test_get_config_with_defaults
"""
import os
import pytest
from cookiecutter import config
from cookiecutter.exceptions import (
ConfigDoesNotExistException, InvalidConfiguration
)
def test_get_config():
"""
Opening and reading config file
"""
conf = config.get_config('tests/test-config/valid-config.yaml')
expected_conf = {
'cookiecutters_dir': '/home/example/some-path-to-templates',
'replay_dir': '/home/example/some-path-to-replay-files',
'default_context': {
'full_name': 'Firstname Lastname',
'email': '[email protected]',
'github_username': 'example'
}
}
assert conf == expected_conf
def test_get_config_does_not_exist():
"""
Check that `exceptions.ConfigDoesNotExistException` is raised when
attempting to get a non-existent config file.
"""
with pytest.raises(ConfigDoesNotExistException):
config.get_config('tests/test-config/this-does-not-exist.yaml')
def test_invalid_config():
"""
An invalid config file should raise an `InvalidConfiguration` exception.
"""
with pytest.raises(InvalidConfiguration) as excinfo:
config.get_config('tests/test-config/invalid-config.yaml')
expected_error_msg = (
'Unable to parse YAML file '
'tests/test-config/invalid-config.yaml. '
'Error: '
)
assert expected_error_msg in str(excinfo.value)
def test_get_config_with_defaults():
"""
A config file that overrides 1 of 3 defaults
"""
conf = config.get_config('tests/test-config/valid-partial-config.yaml')
default_cookiecutters_dir = os.path.expanduser('~/.cookiecutters/')
default_replay_dir = os.path.expanduser('~/.cookiecutter_replay/')
expected_conf = {
'cookiecutters_dir': default_cookiecutters_dir,
'replay_dir': default_replay_dir,
'default_context': {
'full_name': 'Firstname Lastname',
'email': '[email protected]',
'github_username': 'example'
}
}
assert conf == expected_conf