| 1 |
[case testTimeBasic_librt] |
| 2 |
import time as stdlib_time |
| 3 |
from librt.time import time |
| 4 |
|
| 5 |
def test_time_returns_float() -> None: |
| 6 |
result = time() |
| 7 |
assert isinstance(result, float) |
| 8 |
|
| 9 |
def test_time_is_reasonable() -> None: |
| 10 |
# Should return a Unix timestamp, which should be a large positive number |
| 11 |
result = time() |
| 12 |
# Check it's after year 2020 (timestamp > 1577836800) |
| 13 |
assert result > 1577836800.0 |
| 14 |
# Check it's before year 2100 (timestamp < 4102444800) |
| 15 |
assert result < 4102444800.0 |
| 16 |
|
| 17 |
def test_time_increments() -> None: |
| 18 |
t1 = time() |
| 19 |
t2 = time() |
| 20 |
# Time should not go backwards (allowing for same value due to precision) |
| 21 |
assert t2 >= t1 |
| 22 |
|
| 23 |
def test_time_comparable_to_stdlib() -> None: |
| 24 |
# Our time() should return similar values to stdlib time.time() |
| 25 |
our_time = time() |
| 26 |
std_time = stdlib_time.time() |
| 27 |
# Should be within 0.25 seconds of each other (usually should be much less, |
| 28 |
# but keep it relatively high to avoid test flakiness in CI) |
| 29 |
assert abs(our_time - std_time) < 0.25 |
| 30 |
|
| 31 |
[case testTimeUsedAtTopLevelOnly_librt] |
| 32 |
from librt.time import time |
| 33 |
|
| 34 |
# The only reference to time() is at module top level |
| 35 |
current_time = time() |
| 36 |
|
| 37 |
def test_top_level_only_time() -> None: |
| 38 |
assert isinstance(current_time, float) |
| 39 |
assert current_time > 0.0 |