Skip to content

Commit

Permalink
fix: restore the ability to have more than two option levels (#3151)
Browse files Browse the repository at this point in the history
* Restore the ability to have more than two option levels

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
gerrymanoim and pre-commit-ci[bot] authored Dec 9, 2021
1 parent 6309432 commit fb4a944
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
12 changes: 4 additions & 8 deletions ibis/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,14 +570,10 @@ def _get_root(
tuple
"""
path = key.split('.')
if len(path) == 1:
return _global_config, path[0]
elif len(path) == 2:
return _global_config[path[0]], path[1]
else:
raise AssertionError(
f'Option keys cannot have more than 2 levels, found: {key}'
)
cursor = _global_config
for p in path[:-1]:
cursor = cursor[p]
return (cursor, path[-1])


def _is_deprecated(key: str) -> bool:
Expand Down
10 changes: 10 additions & 0 deletions ibis/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,13 @@ def test_multiple_backends(mocker):
msg = "3 packages found for backend 'foo'"
with pytest.raises(RuntimeError, match=msg):
ibis.foo


@pytest.mark.parametrize(
('key', 'value'), [("two.levels", True), ("gt.two.levels", 55)]
)
def test_getting_setting_config_options(key, value):
ibis.config.register_option(key, "DEFAULT")
assert ibis.config.get_option(key) == "DEFAULT"
ibis.config.set_option(key, value)
assert ibis.config.get_option(key) == value

0 comments on commit fb4a944

Please sign in to comment.