diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 1d930b5..d6d4758 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.12.0 +current_version = 1.12.1 commit = true tag = false diff --git a/configmanager/__init__.py b/configmanager/__init__.py index a120280..7d9d5fc 100644 --- a/configmanager/__init__.py +++ b/configmanager/__init__.py @@ -1,4 +1,4 @@ -__version__ = '1.12.0' +__version__ = '1.12.1' from .managers import Config from .items import Item diff --git a/configmanager/managers.py b/configmanager/managers.py index 9fcf853..b596680 100644 --- a/configmanager/managers.py +++ b/configmanager/managers.py @@ -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): diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 05563a0..55d7301 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -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' diff --git a/tests/test_iterators.py b/tests/test_iterators.py index fbda681..d6e11e9 100644 --- a/tests/test_iterators.py +++ b/tests/test_iterators.py @@ -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