frozendate-0.1.4
توضیحات
Frozen date: freeze datetime.now at a known value for testing
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | frozendate-0.1.4 |
| نام | frozendate |
| نسخه کتابخانه | 0.1.4 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Oliver Cope |
| ایمیل نویسنده | oliver@redgecko.org |
| آدرس صفحه اصلی | https://bitbucket.org/ollyc/frozendate/ |
| آدرس اینترنتی | https://pypi.org/project/frozendate/ |
| مجوز | BSD |
Frozendate: stop time for your tests
====================================
Frozendate suspends time while your tests run.
Frozendate mocks ``datetime.datetime`` and ``datetime.date`` to provide known
times when testing.
Usage
-----
::
import frozendate
with frozendate.freeze(1999, 1, 1):
party_like_its_1999()
# freeze relative freezes time relative to the current date...
with freeze_relative(days=-1):
assert all_my_troubles_seemed_so_far_away()
with freeze(1999, 12, 31):
# ...or relative to the previous freeze
with freeze_relative(days=1):
print "happy new year!"
Normally time doesn't actually stop when you use freeze – it just starts
again from the fixed point you specify, eg::
>>> import frozendate
>>> import datetime
>>> with frozendate.freeze(2000, 1, 1):
... print datetime.now().replace(microsecond=0)
... time.sleep(1)
... print datetime.now().replace(microsecond=0)
...
2000-01-01 00:00:00
2000-01-01 00:00:01
But you can always get the same value back if you pass ``hard=True``::
>>> with frozendate.freeze(2000, 1, 1, hard=True):
... print datetime.now().replace(microsecond=0)
... time.sleep(1)
... print datetime.now().replace(microsecond=0)
...
2000-01-01 00:00:00
2000-01-01 00:00:00
Instead of a context manager there are also regular patch and unpatch
functions.
These are useful in test case setup/teardown methods::
def setUp(self):
frozendate.patch(2000, 1, 1)
def tearDown(self):
frozendate.unpatch()
When you call freeze or patch, it freezes time for all modules found in
``sys.modules``.
Sometimes you want to restrict to a few named modules::
frozendate.freeze(modules=['mypackage.mymodule'])
Or patch everything, but exclude a few modules that need the real datetime
still::
frozendate.freeze(dontpatch=['somemodule', 'someotherpackage'])
0.1.4 (released 2022-10-04)
---------------------------
- Bugfix: don't attempt to patch pkg_resources
0.1.3 (released 2018-10-10)
---------------------------
- Fix exception when used with dateutil
- Add support for Python 3.7
- Drop support for Python 2.6
Version 0.1.2
-------------
- Add support for freezing datetime.utcnow()
Version 0.1.1
-------------
- Fix for ImportErrors when used with six
Version 0.1
------------
- Initial release
نیازمندی
| مقدار | نام |
|---|---|
| - | mock |
نحوه نصب
نصب پکیج whl frozendate-0.1.4:
pip install frozendate-0.1.4.whl
نصب پکیج tar.gz frozendate-0.1.4:
pip install frozendate-0.1.4.tar.gz