Skip to content
This repository has been archived by the owner on Feb 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #140 from jbasko/meta-config
Browse files Browse the repository at this point in the history
Bug fixes in path handling in iterators
  • Loading branch information
jbasko authored Jun 4, 2017
2 parents fb5a8ec + 4b0420c commit f45e6e3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.12.0
current_version = 1.12.1
commit = true
tag = false

Expand Down
2 changes: 1 addition & 1 deletion configmanager/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '1.12.0'
__version__ = '1.12.1'

from .managers import Config
from .items import Item
Expand Down
13 changes: 9 additions & 4 deletions configmanager/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,16 @@ def _parse_path(self, path=None, separator='.'):
if not path:
return ()

clean_path = tuple(path.split(separator))
if clean_path not in self:
# TODO Use custom exceptions
raise AttributeError(path)
if isinstance(path, six.string_types):
clean_path = tuple(path.split(separator))
else:
clean_path = path

if clean_path not in self:
for i, part in enumerate(clean_path):
if clean_path[:i + 1] not in self:
raise NotFound(part)
assert False # shouldn't reach this line
return clean_path

def _get_recursive_iterator(self, recursive=False):
Expand Down
16 changes: 16 additions & 0 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,19 @@ def test_required_value_missing_includes_item():

assert exc2.value.name == 'greeting'
assert exc2.value.item is item2


def test_not_found_raised_by_iterators_on_first_not_found_name_in_path():
config = Config({'uploads': {'db': {'user': 'root'}}})

with pytest.raises(NotFound) as exc1:
list(config.iter_all(recursive=True, path=('downloads',)))
assert exc1.value.name == 'downloads'

with pytest.raises(NotFound) as exc2:
_ = config['uploads', 'enabled']
assert exc2.value.name == 'enabled'

with pytest.raises(NotFound) as exc3:
_ = config['uploads', 'something', 'deep']
assert exc3.value.name == 'something'
8 changes: 8 additions & 0 deletions tests/test_iterators.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,11 @@ def test_iter_paths_accepts_path_and_separator_and_str_path_as_key(c4):
assert all[2] == 'uploads.db'
assert all[3] == 'uploads.db.host'
assert all[4] == 'uploads.db.user'


def test_iterators_accept_path_tuples(c4):
uploads = list(c4.iter_paths(recursive=True, path=('uploads',)))
assert len(uploads) == 5

db = list(c4.iter_paths(recursive=True, path=('uploads', 'db')))
assert len(db) == 3

0 comments on commit f45e6e3

Please sign in to comment.