def test_expiration(self): rc = RollingCounter(ttl_secs=0.5) for _ in range(10): rc.add('foo') for _ in range(5): rc.add('bar') assert len(rc.keys()) == 2 assert rc.count('foo') == 10 time.sleep(1) assert len(rc.keys()) == 0 assert rc.max() is None assert rc.min() is None assert not rc.ranked() assert rc.count('foo') == 0
def test_rank(self): rc = RollingCounter() for _ in range(100): rc.add('foo') for _ in range(10): rc.add('bar') for _ in range(40): rc.add('baz') for _ in range(60): rc.add('quux') assert rc.max() == 'foo' assert rc.min() == 'bar' assert [x[0] for x in rc.ranked()] == ['bar', 'baz', 'quux', 'foo']