Fixed Deadline comparison methods, improved tests
This commit is contained in:
parent
734d2b94f3
commit
f74f4a925a
|
@ -43,10 +43,16 @@ class Deadline:
|
|||
self._timestamp = _timestamp
|
||||
|
||||
def __lt__(self, other):
|
||||
return self._timestamp < other.timestamp
|
||||
if not isinstance(other, Deadline):
|
||||
raise TypeError('comparison is not supported between '
|
||||
'instances of \'{}\' and \'{}\''
|
||||
.format(type(self).__name__, type(other).__name__))
|
||||
return self._timestamp < other._timestamp
|
||||
|
||||
def __eq__(self, other):
|
||||
return self._timestamp == other.timestamp
|
||||
if not isinstance(other, Deadline):
|
||||
return False
|
||||
return self._timestamp == other._timestamp
|
||||
|
||||
@classmethod
|
||||
def from_metadata(cls, metadata):
|
||||
|
|
|
@ -33,7 +33,16 @@ def test_decode_timeout(value, expected):
|
|||
|
||||
|
||||
def test_deadline():
|
||||
assert min(Deadline(1), Deadline(2)) == Deadline(1)
|
||||
assert Deadline.from_timeout(1) < Deadline.from_timeout(2)
|
||||
|
||||
with pytest.raises(TypeError) as err:
|
||||
Deadline.from_timeout(1) < 'invalid'
|
||||
err.match('comparison is not supported between instances '
|
||||
'of \'Deadline\' and \'str\'')
|
||||
|
||||
assert Deadline(_timestamp=1) == Deadline(_timestamp=1)
|
||||
|
||||
assert Deadline.from_timeout(1) != 'invalid'
|
||||
|
||||
|
||||
def test_headers_with_deadline():
|
||||
|
|
Loading…
Reference in New Issue