{ "info": { "author": "Gonzalo Bulnes Guilpain", "author_email": "gon.bulnes@fastmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "

\"An

\n

Simulated Time

\n\n

A testing (and partial) replacement for Python's time package, for fully-controlled time-dependent tests.

\n

\"PyPI\"

\n\n

\n\nTesting functions that depend on time is always tricky, and can take long. To save time and avoid relying on `time.sleep()`, this package allows to fast-forward time arbitrarily.\n\nIt implements the functions `stime.time()` and `stime.monotonic()`.\n\n
\n\n> **Note**: This package in not meant to replace [`time`][time] in production! Only in testing environments!\n\n [time]: https://docs.python.org/3/library/time.html\n\nUsage\n-----\n\nThe idea is to make your code to use `stime.test()` instead of `time.test()` while it is being tested.\n\nIdeally, the code you want to test is receiving a time source through _dependency injection_, like the `Timer` class in the example below.\n\nIf the code you are testing is not using dependency injection, it is likely that you can still override the time function in your tests. That is less elegant, but can be a fair trade-off to avoid having its test suite rely on `time.sleep()`.\n\nOnce your code is using `stime`, you can precisely control the output of `stime.time()` (or `stime.monotonic()`) using `stime.reset()` and `stime.tick()`:\n\n- **`tick(n)`**: increments the current time by `n` seconds (e.g. `1.3` seconds)\n- **`reset(t)`**: (re-)sets the current time to the timestamp `t` (e.g. `1561120200`)\n\n### Example\n\nFind the full code for this example in [`examples/timer`](./examples/timer)!\n\n```python\n# test_timer.py\n\nimport unittest\nimport stime # \u2460\nfrom timer import Timer # your package with time-dependent functions to be tested\n\nclass TestTimer(unittest.TestCase):\n\n def test_timer_rings_for_five_seconds_starting_at_alarm_time(self):\n # create a new timer using stime as a time source\n cooking_timer = Timer(time_source=stime)\n cooking_timer.set_alarm(1561120200) # Unix timestamp for 21 June 2019 around noon\n\n stime.reset(1561120199) # \u2461 a second before alarm time\n is_ringing = cooking_timer.is_ringing() # calls stime.time() because it is the timer time_source\n self.assertEqual(is_ringing, False, \"expected the timer NOT to ring before alarm time\")\n\n stime.reset(1561120200) # \u2462 exactly alarm time\n is_ringing = cooking_timer.is_ringing() # calls stime.time() because it is the timer time_source\n self.assertEqual(is_ringing, True, \"expected the timer to ring at alarm time\")\n\n stime.tick(5) # \u2463 5 seconds after alarm time\n is_ringing = cooking_timer.is_ringing() # calls stime.time() because it is the timer time_source\n self.assertEqual(is_ringing, True, \"expected the timer to be ringing 5 seconds after alarm time\")\n\n stime.tick() # \u2464 add 1 more second\n is_ringing = cooking_timer.is_ringing() # calls stime.time() because it is the timer time_source\n self.assertEqual(is_ringing, False, \"expected the timer NOT to be ringing 6 seconds after alarm time\")\n\n# [...]\n```\n\n- \u2460 Import `stime` where you would have imported `time` if it wasn't testing.\n- \u2461 Set the current time to whatever is convenient...\n- \u2462 Reset it as often as needed...\n- \u2463 Fast-forward when convenient...\n- \u2464 or progress one second at a time!\n\nDevelopment\n-----------\n\n### Getting started\n\nOptionally, create a virtual environment for this project and activate it.\n\n```bash\npython -m venv timer_venv # assuming Python 3\n. timer_venv/bin/activate\n```\n\nThen do your thing!\n\n```bash\n# run the example test suite:\npython test_timer.py\n\n# once you're done deactivate the virtual environment if you use one:\ndeactivate\n```\n\n### Release\n\n```bash\n# Install the latest setuptools and wheel (in a virtual environment eventually)\npip install --upgrade setuptools wheel\n\n# Update the package version number and tag it:\nvim setup.py\ngit tag -a 'v1.0.0' -m 'Initial release'\ngit push origin master --tags\n\n# Build the distribution files\nmake build\n\n# And upload them to PyPI\nmake upload_to_pypi\n```\n\nCredits\n-------\n\nThe owl emoji in the header was rendered from an SVG that belongs to Google and [was published under the Apache License v2.0 as part of Noto Emoji](https://github.com/googlei18n/noto-emoji).\n\nLicense\n-------\n\n stime\n Copyright (C) 2019 Gonzalo Bulnes Guilpain\n\n This program is free software: you can redistribute it and/or modify\n it under the terms of the GNU General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n This program is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU General Public License for more details.\n\n You should have received a copy of the GNU General Public License\n along with this program. If not, see .\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/gonzalo-bulnes/stime", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "stime", "package_url": "https://pypi.org/project/stime/", "platform": "", "project_url": "https://pypi.org/project/stime/", "project_urls": { "Homepage": "https://github.com/gonzalo-bulnes/stime" }, "release_url": "https://pypi.org/project/stime/1.0.0/", "requires_dist": null, "requires_python": "", "summary": "A testing (and partial) replacement for the time package, for fully-controlled time-dependent tests.", "version": "1.0.0" }, "last_serial": 5434840, "releases": { "0.1.2": [ { "comment_text": "", "digests": { "md5": "a51c72a54c93b5dd1792ac6d59ebf1be", "sha256": "93573a312fb90651260fca62d3d8cdfe3ea771ab2d1c1ab6a41a3433d364fb48" }, "downloads": -1, "filename": "stime-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "a51c72a54c93b5dd1792ac6d59ebf1be", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 16532, "upload_time": "2019-06-22T14:15:25", "url": "https://files.pythonhosted.org/packages/06/37/1ef6c23ec316ee57a815794a13cee9d4b9f0571085a33029f42d58f93667/stime-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f647da5823f27393469c034731962c11", "sha256": "845f3c1b0574c1f7e3bca7f1936c78b4db1560b43d1d7ff7cab9f0fa2ac94bfe" }, "downloads": -1, "filename": "stime-0.1.2.tar.gz", "has_sig": false, "md5_digest": "f647da5823f27393469c034731962c11", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3886, "upload_time": "2019-06-22T14:15:27", "url": "https://files.pythonhosted.org/packages/e3/da/c5521ae1723decc3c0cd4e6c50d898f8d29e4048ad90b4baf89a22f15c5a/stime-0.1.2.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "304d410a742177909e460e7bfb44b79a", "sha256": "a911b381c5c31dce29a4d6f5547248fc664fae2701d761639e832e96dfc5eaf0" }, "downloads": -1, "filename": "stime-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "304d410a742177909e460e7bfb44b79a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 16927, "upload_time": "2019-06-22T14:40:02", "url": "https://files.pythonhosted.org/packages/fb/0c/7217618901c3d87beb13f59287170a4859c2b20cdbdd60a4a0efd6fbc04d/stime-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "05a27231de27638a3de13c9d4304782a", "sha256": "5bf56469afe6194c95a2c8a47200eaff008d488e089026c1a5da9e770e12104f" }, "downloads": -1, "filename": "stime-1.0.0.tar.gz", "has_sig": false, "md5_digest": "05a27231de27638a3de13c9d4304782a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4381, "upload_time": "2019-06-22T14:40:04", "url": "https://files.pythonhosted.org/packages/dc/8d/943ef63770aecbc93ed7805ea58bfec5a44c1bab7887cf94ab28537dab8a/stime-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "304d410a742177909e460e7bfb44b79a", "sha256": "a911b381c5c31dce29a4d6f5547248fc664fae2701d761639e832e96dfc5eaf0" }, "downloads": -1, "filename": "stime-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "304d410a742177909e460e7bfb44b79a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 16927, "upload_time": "2019-06-22T14:40:02", "url": "https://files.pythonhosted.org/packages/fb/0c/7217618901c3d87beb13f59287170a4859c2b20cdbdd60a4a0efd6fbc04d/stime-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "05a27231de27638a3de13c9d4304782a", "sha256": "5bf56469afe6194c95a2c8a47200eaff008d488e089026c1a5da9e770e12104f" }, "downloads": -1, "filename": "stime-1.0.0.tar.gz", "has_sig": false, "md5_digest": "05a27231de27638a3de13c9d4304782a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4381, "upload_time": "2019-06-22T14:40:04", "url": "https://files.pythonhosted.org/packages/dc/8d/943ef63770aecbc93ed7805ea58bfec5a44c1bab7887cf94ab28537dab8a/stime-1.0.0.tar.gz" } ] }