Skip to content

Commit

Permalink
improved deprecation on CustomAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Saskia Kohn committed Oct 5, 2023
1 parent dd3e1ac commit 7b8009d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
22 changes: 10 additions & 12 deletions test/unisens_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,23 +856,21 @@ def test_write_signal_entry(self):
def test_deprecation(self):
# CustomAttribute
from unisens import CustomAttribute
#warnings.filterwarnings('error')
ca = CustomAttributes()
# expected usage
#with pytest.raises(DeprecationWarning) as dep:
with pytest.warns(DeprecationWarning) as dep:
att = CustomAttribute(key='height2', value='2,05m') # doesn't work with 'self' in args
att = CustomAttribute(height2='2,05m')
assert att.height2 == '2,05m'
#ca.add_entry(att) # doesn't work, needs att.key='height' etc.
#assert ca.height2 == '2,05m'

# faulty useage
"""with pytest.warns(DeprecationWarning) as dep:
att2 = CustomAttribute(name='height', value='2,05m') # got multiple values for argument 'name'
assert not hasattr(att2, 'height')
assert att2.value == '2,05m'
assert att2._name == 'height'"""
with pytest.raises(AttributeError):
ca.add_entry(att)
assert not hasattr(ca, 'height2')

with pytest.warns(DeprecationWarning) as dep:
att1 = CustomAttribute()
att1.set_attrib('key', 'height2')
att1.set_attrib('value', '2,05m')
ca.add_entry(att1)
assert ca.height2 == '2,05m'
# desired usage
ca.set_attrib(name='height1', value='1,73m')
assert ca.height1 == '1,73m'
Expand Down
2 changes: 1 addition & 1 deletion unisens/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,4 +928,4 @@ def __new__(*args, **kwargs):
warnings.warn("CustomAttribute will be removed in the next release. "
"Use CustomAttributes.set_attrib('key', 'value') instead.",
category=DeprecationWarning, stacklevel=2)
return MiscEntry('customAttribute', *args[1:], **kwargs)
return MiscEntry('customAttribute', *args, **kwargs)

0 comments on commit 7b8009d

Please sign in to comment.