pyoda_time.testing package¶
Subpackages¶
Module contents¶
- class pyoda_time.testing.FakeClock¶
Bases:
IClockClock which can be constructed with an initial instant, and then advanced programmatically (and optionally, automatically advanced on each read).
This class is designed to be used when testing classes which take an
IClockas a dependency.This class is somewhere between a fake and a stub, depending on how it’s used - if it’s set to
auto_advancethen time will pass, but in a pretty odd way (i.e. dependent on how often it’s consulted).- __init__(initial: ~pyoda_time._instant.Instant, auto_advance: ~pyoda_time._duration.Duration = 0:00:00:00) None¶
Creates a fake clock initially set to the given instant.
The clock will advance by the given duration on each read, defaulting to
Duration.zero.- Parameters:
initial – The initial instant.
auto_advance – The duration to advance the clock on each read.
- advance(duration: Duration) None¶
Advances the clock by the given duration.
- Parameters:
duration – The duration to advance the clock by (or if negative, the duration to move it back by).
- advance_days(days: int) None¶
Advances the clock by the given number of days.
- Parameters:
days – The number of days to advance the clock by (or if negative, the number to move it back by).
- advance_hours(hours: int) None¶
Advances the clock by the given number of hours.
- Parameters:
hours – The number of hours to advance the clock by (or if negative, the number to move it back by).
- advance_milliseconds(milliseconds: int) None¶
Advances the clock by the given number of milliseconds.
- Parameters:
milliseconds – The number of milliseconds to advance the clock by (or if negative, the number to move it back by).
- advance_minutes(minutes: int) None¶
Advances the clock by the given number of minutes.
- Parameters:
minutes – The number of minutes to advance the clock by (or if negative, the number to move it back by).
- advance_nanoseconds(nanoseconds: int) None¶
Advances the clock by the given number of nanoseconds.
- Parameters:
nanoseconds – The number of nanoseconds to advance the clock by (or if negative, the number to move it back by).
- advance_seconds(seconds: int) None¶
Advances the clock by the given number of seconds.
- Parameters:
seconds – The number of seconds to advance the clock by (or if negative, the number to move it back by).
- advance_ticks(ticks: int) None¶
Advances the clock by the given number of ticks.
- Parameters:
ticks – The number of ticks to advance the clock by (or if negative, the number to move it back by).
- property auto_advance: Duration¶
Gets/Sets the amount of time to advance the clock by on each call to read the current time.
If this is
Duration.zero, the current time as reported by this clock will not change other than by calls toresetor to one of theadvancemethods.The value could even be negative, to simulate particularly odd system clock effects.
- Returns:
The amount of time to advance the clock by on each call to read the current time.
- classmethod from_utc(year: int, month_of_year: int, day_of_month: int, hour_of_day: int = 0, minute_of_hour: int = 0, second_of_minute: int = 0) FakeClock¶
Returns a fake clock initially set to the given year/month/day/time in UTC in the ISO calendar.
The value of the
auto_advanceproperty will be initialised to zero.- Parameters:
year – The year. This is the “absolute year”, so a value of 0 means 1 BC, for example.
month_of_year – The month of year.
day_of_month – The day of month.
hour_of_day – The hour.
minute_of_hour – The minute.
second_of_minute – The second.
- Returns:
A
FakeClockinitialised to the given instant, with no auto-advance.
- get_current_instant() Instant¶
Returns the “current time” for this clock.
Unlike a normal clock, this property may return the same value from repeated calls until one of the methods to change the time is called.
If the value of the
auto_advanceproperty is non-zero, then every call to this method will advance the current time by that value.- Returns:
The “current time” from this (fake) clock.