Skip to content

Commit

Permalink
Merge pull request #32 from ronsinai/master
Browse files Browse the repository at this point in the history
Fix order of hierarchies, fixes #31
  • Loading branch information
andrasmaroy authored Dec 8, 2020
2 parents fa6203d + 3f9054c commit 304d043
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
3 changes: 1 addition & 2 deletions pconf/pconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ def get(cls):
"""
results = {}

hierarchy = cls.__hierarchy
hierarchy.reverse()
hierarchy = cls.__hierarchy[::-1]

for storeMethod in hierarchy:
cls.merger.merge(results, storeMethod.get())
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def read(fname):

setup(
name="pconf",
version="1.7.1",
version="1.7.2",
author="Andras Maroy",
author_email="[email protected]",
description=("Hierarchical python configuration with files, environment variables, command-line arguments."),
Expand Down
50 changes: 50 additions & 0 deletions tests/test_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,31 @@ def test_forward(self, mock_file, mock_env):

self.assertEqual(expected, results)

@patch("pconf.store.env.Env")
@patch("pconf.store.file.File")
def test_double_forward(self, mock_file, mock_env):
mocked_env = MagicMock()
mocked_env.get.return_value = self.TEST_ENV_RESULT
mock_env.return_value = mocked_env

mocked_file = MagicMock()
mocked_file.get.return_value = self.TEST_FILE_RESULT
mock_file.return_value = mocked_file

Pconf.env()
Pconf.file(self.TEST_FILE_PATH)
Pconf.get()
results = Pconf.get()

expected = {
"file": "result",
"env": "result",
"overlapping": "env",
"deep": {"stillhere": "stillhere", "overlapping": "env"},
}

self.assertEqual(expected, results)

@patch("pconf.store.env.Env")
@patch("pconf.store.file.File")
def test_backward(self, mock_file, mock_env):
Expand All @@ -65,3 +90,28 @@ def test_backward(self, mock_file, mock_env):
}

self.assertEqual(expected, results)

@patch("pconf.store.env.Env")
@patch("pconf.store.file.File")
def test_double_backward(self, mock_file, mock_env):
mocked_env = MagicMock()
mocked_env.get.return_value = self.TEST_ENV_RESULT
mock_env.return_value = mocked_env

mocked_file = MagicMock()
mocked_file.get.return_value = self.TEST_FILE_RESULT
mock_file.return_value = mocked_file

Pconf.file(self.TEST_FILE_PATH)
Pconf.env()
Pconf.get()
results = Pconf.get()

expected = {
"file": "result",
"env": "result",
"overlapping": "file",
"deep": {"stillhere": "stillhere", "overlapping": "file"},
}

self.assertEqual(expected, results)

0 comments on commit 304d043

Please sign in to comment.