l.t.FakeTime : class documentation

Part of lp.testing View In Hierarchy

Provides a controllable implementation of time.time().

You can either advance the time manually using advance() or have it done automatically using next_now(). The amount of seconds to advance the time by is set during initialization but can also be changed for single calls of advance() or next_now().

>>> faketime = FakeTime(1000)
>>> print faketime.now()
1000
>>> print faketime.now()
1000
>>> faketime.advance(10)
>>> print faketime.now()
1010
>>> print faketime.next_now()
1011
>>> print faketime.next_now(100)
1111
>>> faketime = FakeTime(1000, 5)
>>> print faketime.next_now()
1005
>>> print faketime.next_now()
1010
Method __init__ Set up the instance.
Method advance Advance the value that will be returned by now().
Method now Use this bound method instead of time.time in tests.
Method next_now Read the current time and advance it.
def __init__(self, start=None, advance=1):
Set up the instance.
ParametersstartThe value that will initially be returned by now(). If None, the current time will be used.
advanceThe value in secounds to advance the clock by by default.
def advance(self, amount=None):
Advance the value that will be returned by now().
ParametersamountThe amount of seconds to advance the value by. If None, the configured default value will be used.
def now(self):
Use this bound method instead of time.time in tests.
def next_now(self, amount=None):
Read the current time and advance it.

Calls advance() and returns the current value of now().
:param amount: The amount of seconds to advance the value by.
    If None, the configured default value will be used.
API Documentation for Launchpad, generated by pydoctor at 2022-06-16 00:00:12.