Fake timing tools for testing time-dependent functionality
Project description
Are you tired of unpredictable time values messing with your testing? Enter Tyminator, a testing toolkit that terminates uncertainty and boosts the reliability of your tests.
Just like how database fixtures provide predictable data sets, Tyminator brings that same level of predictability to time. Tyminator enables precise control over time-related operations in testing scenarios by seamlessly replacing the built-in Python time functions.
Importance of Predictable Time Test Fixtures
Test fixtures are the guardians of correctness and stability in software applications, setting the stage for tests with data, dependencies, and environment configurations. But when it comes to time-sensitive operations like scheduling events or handling timeouts, relying on the actual passage of time introduces non-deterministic behavior, making it challenging to reproduce and debug issues consistently.
By controlling time, developers can isolate specific scenarios, simulate time-based events, and test edge cases that would otherwise be difficult to replicate reliably. This control allows for comprehensive testing of time-sensitive functionality, including handling time zones, time-based calculations, and scheduling logic.
Key features
The library offers a range of features and methods to manipulate time, schedule events, calculate durations, and track elapsed time, ensuring accurate and repeatable test results.
Patching Time Functions: Tyminator seamlessly replaces the built-in Python time functions with a fake clock implementation. This allows tests to control and manipulate time-related operations without affecting or being affected by the actual system time.
Fine-Grained Time Manipulation: Test fixtures can move time forward in controlled increments, making it possible to simulate various time-based scenarios accurately. This enables comprehensive testing of time-dependent code paths.
Predictable Timestamp Generation: Test fixtures can generate consistent and predictable timestamps, eliminating non-deterministic behavior associated with real-time values. This ensures reliable test results and simplifies debugging.
Time Zone Support: Supports simulating alternate local time zones, allowing tests to ensure that time-dependent code handles regional changes correctly.
Events: Ability to specify specific times when for triggering events, helping to simulate specific sequences of normally unpredictable sequences in asynchronous code paths.
Installation
Tyminator is available as the Python tyminator package.
For example, to install using pip:
$ pip install tyminator
Usage with unittests
import time
import unittest
from datetime import datetime, timezone
from datetime import timedelta
from tyminator.clock import Clock
from tyminator.clock import installed
EPOCH = datetime(2016, 8, 29, 18, 18)
EASTERN_TIME = timedelta(hours=-5)
class MyTimeTest(unittest.TestCase):
def setUp(self):
self.clock = Clock(EPOCH, local_tz=timezone(EASTERN_TIME))
def test_example(self):
with installed(self.clock):
now1 = datetime.fromtimestamp(time.time())
assert now1 == EPOCH
now2 = datetime.fromtimestamp(time.time())
assert now2 == EPOCH + self.clock.step
naive_utc = EPOCH + self.clock.step * 2 - EASTERN_TIME
assert self.clock.current_utc_datetime == naive_utc.replace(tzinfo=timezone.utc)
Links
PyPI Releases: https://pypi.org/project/tyminator/
Source Code: https://github.com/milton-hirsch-institute/tyminator
Issue Tracker: https://github.com/milton-hirsch-institute/tyminator/issues
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file tyminator-1.0.1.tar.gz.
File metadata
- Download URL: tyminator-1.0.1.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
272ab64a1f0c0d6260676e8fd6d68df6bbff52355a688f5863891adbaef433ae
|
|
| MD5 |
ee5a5e6a5ec24b342d9b39daad768958
|
|
| BLAKE2b-256 |
ae1b51a14abd581d7e61a016c4a34d504db4df014af4cfbf2c699875a69c3eb4
|
Provenance
The following attestation bundles were made for tyminator-1.0.1.tar.gz:
Publisher:
release.yml on milton-hirsch-institute/tyminator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tyminator-1.0.1.tar.gz -
Subject digest:
272ab64a1f0c0d6260676e8fd6d68df6bbff52355a688f5863891adbaef433ae - Sigstore transparency entry: 162020229
- Sigstore integration time:
-
Permalink:
milton-hirsch-institute/tyminator@aed5706f8403bb20f45031701bd8da35288ff6e7 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/milton-hirsch-institute
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@aed5706f8403bb20f45031701bd8da35288ff6e7 -
Trigger Event:
push
-
Statement type: