File: test_utils.py

package info (click to toggle)
python-ratelimitqueue 0.2.2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 180 kB
  • sloc: python: 463; makefile: 15
file content (31 lines) | stat: -rw-r--r-- 863 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Tests for ratelimitqueue/utils.py"""
import time

from ratelimitqueue import utils

from .utils import almost


class TestGetTimeRemaining:
    def test_timeout_none(self):
        assert utils.get_time_remaining(0, None) is None

    def test_timeout_positive(self):
        start = time.time()
        remaining = utils.get_time_remaining(start, 5)
        assert almost(remaining, 5)

    def test_timeout_zero(self):
        start = time.time()
        remaining = utils.get_time_remaining(start, 0)
        assert almost(remaining, 0)

    def test_timeout_negative(self):
        start = time.time()
        remaining = utils.get_time_remaining(start, -5)
        assert almost(remaining, -5)

    def test_timeout_passed(self):
        start = time.time() + 10
        remaining = utils.get_time_remaining(start, 5)
        assert almost(remaining, -5)