-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix handling of throw_on_missing
flag for select()
on ListConfig
#564
Conversation
678fa4e
to
f542d71
Compare
news/563.bugfix
Outdated
@@ -0,0 +1 @@ | |||
Selecting a missing node from a ListConfig with `throw_on_missing` set to True now raises the intended exception. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function name here to be more specific about what you mean by "selecting"
Selecting a missing node from a ListConfig with `throw_on_missing` set to True now raises the intended exception. | |
OmegaConf.select() a missing node from a ListConfig with `throw_on_missing` set to True now raises the intended exception. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in b9a5db6
tests/test_select.py
Outdated
@@ -85,7 +86,7 @@ def test_select_default( | |||
pytest.param({"missing": "???"}, "missing", id="missing"), | |||
], | |||
) | |||
def test_select_default_throw_on_missing( | |||
def test_select_default_throw_on_missing_dict( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
old function name seems better. why rename it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before there was just the test_select_default_throw_on_missing
function;
now there is a test_select_default_throw_on_missing_dict
function and a test_select_default_throw_on_missing_list
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function is testing both dicts and lists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/test_select.py
Outdated
@pytest.mark.parametrize( | ||
"cfg, key", | ||
[ | ||
pytest.param(["???"], "0", id="missing"), | ||
], | ||
) | ||
def test_select_default_throw_on_missing_list( | ||
cfg: Any, | ||
key: Any, | ||
) -> None: | ||
cfg = OmegaConf.create(cfg) | ||
|
||
# throw on missing still throws if default is provided | ||
with pytest.raises(MissingMandatoryValue): | ||
OmegaConf.select(cfg, key, default=0, throw_on_missing=True) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this is covered by the first test you changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this test covers the throw_on_missing=True
case, the other one does not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the list:missing
test I added is a success case when throw_on_missing
is False (it was working before as well, but it wasn't tested, I just added it for better test coverage)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is it a success case if the test body has this?
with pytest.raises(MissingMandatoryValue):
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to clear up the confusion:
- I thought by "first test you changed" you meant
test_select()
: I indeed added a new test here (idlist:missing
) to test the case where we select a missing value withthrow_on_missing
set to False (which worked before, and still works here) - The test with
with pytest.raises(MissingMandatoryValue):
istest_select_default_throw_on_missing
: this tests the case wherethrow_on_missing
is True. The new test I added here would have failed before this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
tests/test_select.py
Outdated
@@ -85,7 +86,7 @@ def test_select_default( | |||
pytest.param({"missing": "???"}, "missing", id="missing"), | |||
], | |||
) | |||
def test_select_default_throw_on_missing( | |||
def test_select_default_throw_on_missing_dict( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function is testing both dicts and lists.
tests/test_select.py
Outdated
@pytest.mark.parametrize( | ||
"cfg, key", | ||
[ | ||
pytest.param(["???"], "0", id="missing"), | ||
], | ||
) | ||
def test_select_default_throw_on_missing_list( | ||
cfg: Any, | ||
key: Any, | ||
) -> None: | ||
cfg = OmegaConf.create(cfg) | ||
|
||
# throw on missing still throws if default is provided | ||
with pytest.raises(MissingMandatoryValue): | ||
OmegaConf.select(cfg, key, default=0, throw_on_missing=True) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is it a success case if the test body has this?
with pytest.raises(MissingMandatoryValue):
...
cef0a23
to
585183c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good.
I think GitHub diff view played some tricks on all of us here.
Fixes #563