Skip to content

Commit

Permalink
Fixes #57 (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
loganasherjones committed May 27, 2018
1 parent 0fadd06 commit 50be2b6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
12 changes: 12 additions & 0 deletions tests/spec_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ def test_load_config_multi_part_dictionary(spec_with_dicts):
'port': 1234}


@patch('os.path.isfile', Mock(return_value=True))
def test_migrate_config_file():
spec = YapconfSpec({'foo': {'bootstrap': True}})
with patch('yapconf.open', mock_open(read_data='{}')):
config = spec.migrate_config_file(
'/path/to/file',
create=False,
include_bootstrap=False
)
assert config == {}


@patch('os.path.isfile', Mock(return_value=True))
def test_migrate_config_file_no_changes(basic_spec):
open_path = 'yapconf.open'
Expand Down
12 changes: 11 additions & 1 deletion yapconf/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ def migrate_config_file(
create=True,
update_defaults=True,
dump_kwargs=None,
include_bootstrap=True,
):
"""Migrates a configuration file.
Expand Down Expand Up @@ -303,6 +304,7 @@ def migrate_config_file(
update_defaults (bool): Update values that have a value set to
something listed in the previous_defaults
dump_kwargs (dict): A key-value pair that will be passed to dump
include_bootstrap (bool): Include bootstrap items in the output
Returns:
box.Box: The newly migrated configuration.
Expand All @@ -317,7 +319,15 @@ def migrate_config_file(
current_file_type)

migrated_config = {}
for item in self._yapconf_items.values():

if include_bootstrap:
items = self._yapconf_items.values()
else:
items = [
item for item in self._yapconf_items.values()
if not item.bootstrap
]
for item in items:
item.migrate_config(current_config, migrated_config,
always_update, update_defaults)

Expand Down

0 comments on commit 50be2b6

Please sign in to comment.