Skip to content

Commit

Permalink
config: set default on missing default_context key
Browse files Browse the repository at this point in the history
Closes: #1514
Closes: #1513
  • Loading branch information
simobasso committed Apr 11, 2021
1 parent 52dd185 commit 4609471
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cookiecutter/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def merge_configs(default, overwrite):
# Make sure to preserve existing items in
# nested dicts, for example `abbreviations`
if isinstance(v, dict):
new_config[k] = merge_configs(default[k], v)
new_config[k] = merge_configs(default.get(k, {}), v)
else:
new_config[k] = v

Expand Down
6 changes: 6 additions & 0 deletions tests/test-config/valid-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ default_context:
full_name: "Firstname Lastname"
email: "firstname.lastname@gmail.com"
github_username: "example"
project:
description: "description"
tags:
- "first"
- "second"
- "third"
cookiecutters_dir: "/home/example/some-path-to-templates"
replay_dir: "/home/example/some-path-to-replay-files"
abbreviations:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_get_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def test_get_config():
'full_name': 'Firstname Lastname',
'email': 'firstname.lastname@gmail.com',
'github_username': 'example',
'project': {
'description': 'description',
'tags': ['first', 'second', 'third',],
},
},
'abbreviations': {
'gh': 'https://github.com/{0}.git',
Expand Down
4 changes: 4 additions & 0 deletions tests/test_get_user_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def custom_config():
'full_name': 'Firstname Lastname',
'email': 'firstname.lastname@gmail.com',
'github_username': 'example',
'project': {
'description': 'description',
'tags': ['first', 'second', 'third',],
},
},
'cookiecutters_dir': '/home/example/some-path-to-templates',
'replay_dir': '/home/example/some-path-to-replay-files',
Expand Down

0 comments on commit 4609471

Please sign in to comment.