Commit a5570504 authored by Christophe Combelles's avatar Christophe Combelles

Improved the doc

parent 71d6d5fbb1d7
Version 0.5(unreleased)
-----------------------
Version 0.4.1 (2013-04-24)
--------------------------
- #3: fixed compatibility problem with ``sqlite3`` (spotted via IPython/IPdb)
Changes
~~~~~~~
Version 0.3.1 (2012-11-28)
--------------------------
0.4.2 (2013-06-11)
------------------
- #1: tested code using time zone optional arg of now() doesn't break
any more (no real time zone support, though)
- A few improvements in the doc
Version 0.3 (2012-11-23)
------------------------
0.4.1 (2013-04-24)
------------------
- Fixed the problem that ``datetime`` objects generated from
computations used to fail ``isinstance`` tests.
- #3: fixed compatibility problem with ``sqlite3`` (spotted via IPython/IPdb)
Version 0.2.1 (2012-11-22)
--------------------------
0.3.1 (2012-11-28)
------------------
- Fixed issue with ``datetime.time`` masking
- #1: tested code using time zone optional arg of now() doesn't break
any more (no real time zone support, though)
Version 0.1 (2012-07-15)
------------------------
- initial version
0.3 (2012-11-23)
----------------
- Fixed the problem that ``datetime`` objects generated from
computations used to fail ``isinstance`` tests.
0.2.1 (2012-11-22)
------------------
- Fixed issue with ``datetime.time`` masking
0.1 (2012-07-15)
----------------
- initial version
A module to allow cheating with current time in tests.
======================================================
anybox.testing.datetime
=======================
This README is also a doctest. To it and other doctests for this package,
simply do::
This package allows to **cheat with current time** in tests.
It has initially been used in OpenERP to test workflows spanning over a long period of time.
nosetests --with-doctest --doctest-extension=txt
Currently it mainly provides a ``datetime.set_now()`` method to fake the current time.
Usage
~~~~~
......@@ -12,65 +12,65 @@ Usage
Before anything, the package must be imported in order to replace the
regular ``datetime`` module with the modified one::
>>> import anybox.testing.datetime
>>> from datetime import datetime
>>> import time
>>> import anybox.testing.datetime
>>> from datetime import datetime
>>> import time
Let's keep the real value of ``now`` around::
>>> start = datetime.now()
>>> start_t = time.time()
>>> start = datetime.now()
>>> start_t = time.time()
Then you can::
Then you can change the current time::
>>> datetime.set_now(datetime(2001, 01, 01, 3, 57, 0))
>>> datetime.now()
datetime(2001, 1, 1, 3, 57)
>>> datetime.today()
datetime(2001, 1, 1, 3, 57)
>>> datetime.set_now(datetime(2001, 01, 01, 3, 57, 0))
>>> datetime.now()
datetime(2001, 1, 1, 3, 57)
>>> datetime.today()
datetime(2001, 1, 1, 3, 57)
The time module goes along::
>>> datetime.fromtimestamp(time.time())
datetime(2001, 1, 1, 3, 57)
>>> datetime.fromtimestamp(time.time())
datetime(2001, 1, 1, 3, 57)
Note that you can expect a few microseconds difference (not displayed
here because ``datetime.fromtimestamp`` ignores them).
Don't forget afterwards get back to the regular system clock, otherwise
Don't forget afterwards to get back to the regular system clock, otherwise
many pieces of code might get very suprised if the system clock looks as if
it's frozen::
>>> datetime.real_now()
>>> datetime.real_now()
Now let's check it worked::
>>> now = datetime.now()
>>> now > start
True
>>> from datetime import timedelta
>>> now - start < timedelta(0, 0, 10000) # 10 ms
True
>>> now = datetime.now()
>>> now > start
True
>>> from datetime import timedelta
>>> now - start < timedelta(0, 0, 10000) # 10 ms
True
And with the ``time`` module::
>>> now_t = time.time()
>>> now_t > start_t
True
>>> now_t - start_t < 0.01 # 10 ms again
True
>>> now_t = time.time()
>>> now_t > start_t
True
>>> now_t - start_t < 0.01 # 10 ms again
True
Other constructors are still available (this is a non regression
test)::
>>> import datetime
>>> datetime.time(3, 57, 0)
datetime.time(3, 57)
>>> datetime.datetime(2013, 1, 1, 3, 57, 0)
datetime(2013, 1, 1, 3, 57)
>>> datetime.date(2013, 1, 1)
datetime.date(2013, 1, 1)
>>> import datetime
>>> datetime.time(3, 57, 0)
datetime.time(3, 57)
>>> datetime.datetime(2013, 1, 1, 3, 57, 0)
datetime(2013, 1, 1, 3, 57)
>>> datetime.date(2013, 1, 1)
datetime.date(2013, 1, 1)
Behind the hood
~~~~~~~~~~~~~~~
......@@ -138,3 +138,12 @@ Now let's try this again with the original ones::
>>> cr = cr.execute("INSERT INTO dates VALUES (?, ?)", (dt, d))
>>> cr = cr.execute("SELECT dt, d from dates")
>>> res = cr.fetchall() # can't check the value, it changes a lot !
Test
~~~~
This README is also a doctest. To it and other doctests for this package,
simply do::
nosetests --with-doctest --doctest-extension=txt
from setuptools import setup, find_packages
version = '0.5'
version = '0.4.2'
setup(
name="anybox.testing.datetime",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment