-
Notifications
You must be signed in to change notification settings - Fork 77
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
Use pytest/bare asserts in tests #49
base: master
Are you sure you want to change the base?
Conversation
nose has been unmaintained upstream for years now, and so this project should move with the times. To that end, switch to either using bare assert statements, or where that isn't suitable, using pytest's raises context manager.
with raises(NotImplementedError): | ||
d.fromkeys() | ||
d.viewitems() | ||
d.viewkeys() | ||
d.viewvalues() |
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.
with raises(NotImplementedError): | |
d.fromkeys() | |
d.viewitems() | |
d.viewkeys() | |
d.viewvalues() | |
with raises(NotImplementedError): | |
d.fromkeys() | |
with raises(NotImplementedError): | |
d.viewitems() | |
with raises(NotImplementedError): | |
d.viewkeys() | |
with raises(NotImplementedError): | |
d.viewvalues() |
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.
Even with this change the test fails for me with
============================= test session starts ==============================
platform linux -- Python 3.12.4, pytest-8.2.2, pluggy-1.5.0
rootdir: /build/source
collected 14 items
tests/expiringdict_extended_test.py .... [ 28%]
tests/expiringdict_test.py ...F...... [100%]
=================================== FAILURES ===================================
__________________________________ test_repr ___________________________________
def test_repr():
d = ExpiringDict(max_len=2, max_age_seconds=0.01)
d['a'] = 'x'
assert str(d) == "ExpiringDict({'a': 'x'})"
sleep(0.01)
> assert str(d) == "ExpiringDict([])"
tests/expiringdict_test.py:70:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = ExpiringDict(), key = 'a', with_age = False
def __getitem__(self, key, with_age=False):
""" Return the item of the dict.
Raises a KeyError if key is not in the map.
"""
with self.lock:
item = OrderedDict.__getitem__(self, key)
item_age = time.time() - item[1]
if item_age < self.max_age:
if with_age:
return item[0], item_age
else:
return item[0]
else:
del self[key]
> raise KeyError(key)
E KeyError: 'a'
expiringdict/__init__.py:86: KeyError
=========================== short test summary info ============================
FAILED tests/expiringdict_test.py::test_repr - KeyError: 'a'
========================= 1 failed, 13 passed in 0.22s =========================
|
||
|
||
def test_repr(): | ||
d = ExpiringDict(max_len=2, max_age_seconds=0.01) | ||
d['a'] = 'x' | ||
eq_(str(d), "ExpiringDict([('a', 'x')])") | ||
assert str(d) == "ExpiringDict([('a', 'x')])" |
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.
The format changes starting with Python 3.12:
assert str(d) == "ExpiringDict([('a', 'x')])" | |
assert str(d) == "ExpiringDict({'a': 'x')}" |
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.
The empty representation has changed too:
- assert str(d) == "ExpiringDict([])"
+ assert str(d) == "ExpiringDict()"
But stepping back, the module itself isn’t compatible with Python 3.12 so I don’t think it’s appropriate to update the tests for that yet.
Addresses NixOS#326513 by applying mailgun/expiringdict#49
Addresses NixOS#326513 by applying mailgun/expiringdict#49
Addresses NixOS#326513 by applying mailgun/expiringdict#49
nose has been unmaintained upstream for years now, and so this project
should move with the times. To that end, switch to either using bare
assert statements, or where that isn't suitable, using pytest's raises
context manager.