Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix datalad_next.utils.ParamDictator #610

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion datalad_next/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@

def __getattr__(self, attr: str):
if attr.startswith('__'):
return super().__getattr__(attr)
return super().__getattribute__(attr)

Check warning on line 219 in datalad_next/utils/__init__.py

View check run for this annotation

Codecov / codecov/patch

datalad_next/utils/__init__.py#L219

Added line #L219 was not covered by tests
return self.__params[attr]

def __setattr__(self, attr: str, value: Any):
Expand Down
25 changes: 13 additions & 12 deletions datalad_next/utils/tests/test_deprecated.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from datalad_next.utils.deprecate import deprecated

import pytest
Expand Down Expand Up @@ -111,17 +112,17 @@ def test_deprecated():
for func in [deprecated_function_param_value,
RandomClassParamValue().deprecated_method,
]:
with pytest.warns(None) as record:
with warnings.catch_warnings(record=True) as record:
res = func(inputmode='not-deprecated')
assert res == 'not-deprecated'
assert len(record) == 0
assert res == 'not-deprecated'
assert len(record) == 0

for func in [deprecated_function_param,
RandomClassParam().deprecated_method]:
with pytest.warns(None) as record:
with warnings.catch_warnings(record=True) as record:
res = func(other_param='something!')
assert res == inputmode
assert len(record) == 0
assert res == inputmode
assert len(record) == 0

# make sure it catches the parameter even if its a list
for func in [deprecated_function_param_value,
Expand All @@ -132,10 +133,10 @@ def test_deprecated():
match="Use of values {'default'} for argument 'inputmode'"):
res = func(inputmode=[inputmode])
assert res == [inputmode]
with pytest.warns(None) as record:
with warnings.catch_warnings(record=True) as record:
res = func(inputmode=['not-deprecated'])
assert res == ['not-deprecated']
assert len(record) == 0
assert res == ['not-deprecated']
assert len(record) == 0

# two decorators work as expected
with pytest.warns(DeprecationWarning) as record:
Expand All @@ -153,7 +154,7 @@ def test_deprecated():
# shouldn't matter if the parameter value is a list
res = two_deprecated_values(mode=['1'])
assert res == ['1']
with pytest.warns(None) as record:
with warnings.catch_warnings(record=True) as record:
res = two_deprecated_values(mode='safe')
assert res == 'safe'
assert len(record) == 0
assert res == 'safe'
assert len(record) == 0
12 changes: 12 additions & 0 deletions datalad_next/utils/tests/test_paramdictator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest

from .. import ParamDictator


def test_paramdictator():
d = {'a': 1, 'b': 2}
pd = ParamDictator(d)
assert pd.a == 1
assert pd.b == 2
with pytest.raises(AssertionError):
assert pd.__dir__ is None
Loading