Ejemplo n.º 1
0
 def testUnExpiredToUnExpiredComparison(self):
     et1 = ExpiryTime(timedelta(milliseconds=15))
     et2 = ExpiryTime(timedelta(milliseconds=10))
     assert et1 != et2
     assert et2 != et1
     sleep(et2.remainingSeconds())
     print(str(et1), str(et2))
     assert et1 != et2
     assert et2 != et1
     sleep(et1.remainingSeconds())
     assert et1 == et2
     assert et2 == et1
Ejemplo n.º 2
0
 def testUnExpiredToUnExpiredComparison(self):
     et1 = ExpiryTime(timedelta(milliseconds=15))
     et2 = ExpiryTime(timedelta(milliseconds=10))
     assert et1 != et2
     assert et2 != et1
     sleep(et2.remainingSeconds())
     print(str(et1), str(et2))
     assert et1 != et2
     assert et2 != et1
     sleep(et1.remainingSeconds())
     assert et1 == et2
     assert et2 == et1
Ejemplo n.º 3
0
 def testNonZeroIsFalse(self):
     et = ExpiryTime(timedelta(milliseconds=10))
     assert not et
     assert not bool(et)
     sleep(et.remainingSeconds())
     assert et
     assert bool(et)
Ejemplo n.º 4
0
 def testNonZeroIsFalse(self):
     et = ExpiryTime(timedelta(milliseconds=10))
     assert not et
     assert not bool(et)
     sleep(et.remainingSeconds())
     assert et
     assert bool(et)
Ejemplo n.º 5
0
 def testNoneToUnExpiredComparison(self):
     et1 = ExpiryTime(None)
     et2 = ExpiryTime(timedelta(milliseconds=10))
     assert et1 != et2
     assert et2 != et1
     sleep(et2.remainingSeconds())
     assert et1 != et2
     assert et2 != et1
Ejemplo n.º 6
0
 def testNoneToUnExpiredComparison(self):
     et1 = ExpiryTime(None)
     et2 = ExpiryTime(timedelta(milliseconds=10))
     assert et1 != et2
     assert et2 != et1
     sleep(et2.remainingSeconds())
     assert et1 != et2
     assert et2 != et1
Ejemplo n.º 7
0
 def testNoneComparedToNonZero(self):
     et1 = ExpiryTime(None)
     et2 = ExpiryTime(timedelta(milliseconds=10))
     # None == forever, so it is greater than anything, although equal to itself
     assert et1 > et2
     assert et2 < et1
     assert et1 > et2
     assert et2 < et1
     sleep(et2.remainingSeconds())
     assert et1 > et2
     assert et2 < et1
     assert et1 > et2
     assert et2 < et1
Ejemplo n.º 8
0
 def testNoneComparedToNonZero(self):
     et1 = ExpiryTime(None)
     et2 = ExpiryTime(timedelta(milliseconds=10))
     # None == forever, so it is greater than anything, although equal to itself
     assert et1 > et2
     assert et2 < et1
     assert et1 > et2
     assert et2 < et1
     sleep(et2.remainingSeconds())
     assert et1 > et2
     assert et2 < et1
     assert et1 > et2
     assert et2 < et1
Ejemplo n.º 9
0
 def testNoneRemainingSecondsExplicitForever(self):
     et = ExpiryTime(None)
     assert 9 == et.remainingSeconds(9)
Ejemplo n.º 10
0
 def testNonZeroRemainingSeconds(self):
     et = ExpiryTime(timedelta(milliseconds=10))
     assert 0.0 < et.remainingSeconds()
     assert 0.0101 > et.remainingSeconds()
     sleep(et.remainingSeconds())
     assert 0.0 == et.remainingSeconds()
Ejemplo n.º 11
0
 def testZeroRemainingSeconds(self):
     et = ExpiryTime(timedelta(microseconds=0))
     assert 0.0 == et.remainingSeconds()
Ejemplo n.º 12
0
 def testNoneRemainingSeconds(self):
     et = ExpiryTime(None)
     assert et.remainingSeconds() is None
Ejemplo n.º 13
0
 def testNonZeroRemaining(self):
     et = ExpiryTime(timedelta(milliseconds=10))
     assert timedelta(days=0) < et.remaining()
     assert timedelta(milliseconds=11) > et.remaining()
     sleep(et.remainingSeconds())
     assert timedelta(days=0) == et.remaining()
Ejemplo n.º 14
0
 def testNonZeroRemaining(self):
     et = ExpiryTime(timedelta(milliseconds=10))
     assert timedelta(days=0) < et.remaining()
     assert timedelta(milliseconds=11) > et.remaining()
     sleep(et.remainingSeconds())
     assert timedelta(days=0) == et.remaining()
Ejemplo n.º 15
0
 def testNoneRemainingSeconds(self):
     et = ExpiryTime(None)
     assert et.remainingSeconds() is None
Ejemplo n.º 16
0
 def testNonZeroStr(self):
     et = ExpiryTime(timedelta(milliseconds=10))
     assert str(et).startswith('Expires_in_0:00:00.0')
     sleep(et.remainingSeconds())
     assert str(et).startswith('Expired_for_0:00:00')
Ejemplo n.º 17
0
 def testZeroRemainingSeconds(self):
     et = ExpiryTime(timedelta(microseconds=0))
     assert 0.0 == et.remainingSeconds()
Ejemplo n.º 18
0
 def testNonZeroStr(self):
     et = ExpiryTime(timedelta(milliseconds=10))
     assert str(et).startswith('Expires_in_0:00:00.0')
     sleep(et.remainingSeconds())
     assert str(et).startswith('Expired_for_0:00:00')
Ejemplo n.º 19
0
 def testNoneRemainingSecondsExplicitForever(self):
     et = ExpiryTime(None)
     assert 9 == et.remainingSeconds(9)
Ejemplo n.º 20
0
 def testNonZeroRemainingSeconds(self):
     et = ExpiryTime(timedelta(milliseconds=10))
     assert 0.0 < et.remainingSeconds()
     assert 0.0101 > et.remainingSeconds()
     sleep(et.remainingSeconds())
     assert 0.0 == et.remainingSeconds()
Ejemplo n.º 21
0
 def testNonZeroExpired(self):
     et = ExpiryTime(timedelta(milliseconds=10))
     assert not et.expired()
     sleep(et.remainingSeconds())
     assert et.expired()
Ejemplo n.º 22
0
 def testNonZeroExpired(self):
     et = ExpiryTime(timedelta(milliseconds=10))
     assert not et.expired()
     sleep(et.remainingSeconds())
     assert et.expired()