expyct.datetime module

class expyct.datetime.AfterBefore(after: Optional[expyct.datetime.T] = None, before: Optional[expyct.datetime.T] = None)

Bases: Generic[expyct.datetime.T], expyct.base.BaseMatcher

Mixin for matching a date, time, or datetime that takes place after, before, or on given date/time. In other words, it is inclusive on both sides.

Parameters
  • after – object must occur after or exactly on given

  • before – object must occur before or exactly on given

class expyct.datetime.AfterBeforeStrict(after_strict: Optional[expyct.datetime.T] = None, before_strict: Optional[expyct.datetime.T] = None)

Bases: Generic[expyct.datetime.T], expyct.base.BaseMatcher

Mixin for matching a date, time, or datetime that takes place after and/or before given date/time. In other words, it is exclusive on both sides.

Parameters
  • after_strict – object must occur after given

  • before_strict – object must occur before given

class expyct.datetime.Date(*args, **kwargs)

Bases: expyct.base.Satisfies, expyct.datetime.AfterBeforeStrict[datetime.date], expyct.datetime.AfterBefore[datetime.date], expyct.base.Equals[datetime.date], expyct.base.Optional, expyct.base.MapBefore, expyct.base.BaseMatcher, datetime.date

Match any object that is an instance of date.

Parameters
  • map_before – apply function before checking equality

  • optional – whether None is allowed

  • equals – object must equal exactly. This is useful together with map_before to check a value after applying a function

  • after – object must occur after or on given. If timedelta is given, then it is compared relative to when the assertion is run

  • before – object must occur before or on given. If timedelta is given, then it is compared relative to when the assertion is run

  • after_strict – object must occur after given

  • before_strict – object must occur before given

  • satisfies – object must satisfy predicate

class expyct.datetime.DateTime(*args, **kwargs)

Bases: expyct.base.Satisfies, expyct.datetime.AfterBeforeStrict[datetime.datetime], expyct.datetime.AfterBefore[datetime.datetime], expyct.base.Equals[datetime.datetime], expyct.base.Optional, expyct.base.MapBefore, expyct.base.BaseMatcher, datetime.datetime

Match any object that is an instance of datetime.

Parameters
  • map_before – apply function before checking equality

  • optional – whether None is allowed [default: False]

  • equals – object must equal exactly. This is useful together with map_before to check a value after applying a function

  • after – object must occur after or exactly on given

  • before – object must occur before or exactly on given

  • after_strict – object must occur after given

  • before_strict – object must occur before given

  • satisfies – object must satisfy predicate

class expyct.datetime.DateTimeTz(*args, **kwargs)

Bases: expyct.base.Satisfies, expyct.datetime.AfterBeforeStrict[datetime.datetime], expyct.datetime.AfterBefore[datetime.datetime], expyct.base.Equals[datetime.datetime], expyct.base.Optional, expyct.base.MapBefore, expyct.base.BaseMatcher, datetime.datetime

Match any object that is an instance of datetime and has timezone information (tzinfo). In other words, is a timestamp.

Parameters
  • map_before – apply function before checking equality

  • optional – whether None is allowed [default: False]

  • equals – object must equal exactly. This is useful together with map_before to check a value after applying a function

  • after – object must occur after or on given. If timedelta is given, then it is compared relative to when the assertion is run

  • before – object must occur before or on given. If timedelta is given, then it is compared relative to when the assertion is run

  • after_strict – object must occur after given

  • before_strict – object must occur before given

  • satisfies – object must satisfy predicate

class expyct.datetime.Time(*args, **kwargs)

Bases: expyct.base.Satisfies, expyct.datetime.AfterBeforeStrict[datetime.time], expyct.datetime.AfterBefore[datetime.time], expyct.base.Equals[datetime.time], expyct.base.Optional, expyct.base.MapBefore, expyct.base.BaseMatcher, datetime.time

Match any object that is an instance of time.

Parameters
  • map_before – apply function before checking equality

  • optional – whether None is allowed

  • equals – object must equal exactly. This is useful together with map_before to check a value after applying a function

  • after – object must occur after or on given. If timedelta is given, then it is compared relative to when the assertion is run

  • before – object must occur before or on given. If timedelta is given, then it is compared relative to when the assertion is run

  • after_strict – object must occur after given

  • before_strict – object must occur before given

  • satisfies – object must satisfy predicate

expyct.datetime.parse_isoformat(dt: str) Union[datetime.date, datetime.time, datetime.datetime]

Parse a ISO8601-formatted string as a date, datetime or datetime object.

This will depend on the amount of information that is given.

Parameters

dt – the date/time string to parse

expyct.datetime.ANY_DATE = expyct.Date()

Any instance of date

expyct.datetime.ANY_DATETIME = expyct.DateTime()

Any instance of datetime

expyct.datetime.ANY_DATETIME_ISO = expyct.DateTime(map_before=<function parse_isoformat>)

Any string that can be parsed as datetime using the ISO8601 format

expyct.datetime.ANY_DATE_ISO = expyct.Date(map_before=<function parse_isoformat>)

Any string that can be parsed as date using the ISO8601 format

expyct.datetime.ANY_TIME = expyct.Time()

Any instance time

expyct.datetime.ANY_TIME_ISO = expyct.Time(map_before=<function parse_isoformat>)

Any string that can be parsed as time using the ISO8601 format

expyct.datetime.LAST_DAY = expyct.DateTimeTz(after=datetime.timedelta(days=-1), before=datetime.timedelta(0))

Any timestamp occurring during the last 24 hours

expyct.datetime.LAST_DAY_ISO = expyct.DateTimeTz(map_before=<function parse_isoformat>, after=datetime.timedelta(days=-1), before=datetime.timedelta(0))

Any timestamp occurring during the last 24 hours, parsed from ISO8601 string

expyct.datetime.LAST_HOUR = expyct.DateTimeTz(after=datetime.timedelta(days=-1, seconds=82800), before=datetime.timedelta(0))

Any timestamp occurring during the last 60 minutes

expyct.datetime.LAST_HOUR_ISO = expyct.DateTimeTz(map_before=<function parse_isoformat>, after=datetime.timedelta(days=-1, seconds=82800), before=datetime.timedelta(0))

Any timestamp occurring during the last 60 minutes, parsed from ISO8601 string

expyct.datetime.LAST_MINUTE = expyct.DateTimeTz(after=datetime.timedelta(days=-1, seconds=86340), before=datetime.timedelta(0))

Any timestamp occurring during the last 60 seconds

expyct.datetime.LAST_MINUTE_ISO = expyct.DateTimeTz(map_before=<function parse_isoformat>, after=datetime.timedelta(days=-1, seconds=86340), before=datetime.timedelta(0))

Any timestamp occurring during the last 60 seconds, parsed from ISO8601 string

expyct.datetime.LAST_SECOND = expyct.DateTimeTz(after=datetime.timedelta(days=-1, seconds=86399), before=datetime.timedelta(0))

Any timestamp occurring during the last second

expyct.datetime.LAST_SECOND_ISO = expyct.DateTimeTz(map_before=<function parse_isoformat>, after=datetime.timedelta(days=-1, seconds=86399), before=datetime.timedelta(0))

Any timestamp occurring during the last second, parsed from ISO8601 string

expyct.datetime.LAST_WEEK = expyct.DateTimeTz(after=datetime.timedelta(days=-7), before=datetime.timedelta(0))

Any timestamp occurring during the last 7 days

expyct.datetime.LAST_WEEK_ISO = expyct.DateTimeTz(map_before=<function parse_isoformat>, after=datetime.timedelta(days=-7), before=datetime.timedelta(0))

Any timestamp occurring during the last 7 days, parsed from ISO8601 string

expyct.datetime.LAST_YEAR = expyct.DateTimeTz(after=datetime.timedelta(days=-365), before=datetime.timedelta(0))

Any timestamp occurring during the last 365 days

expyct.datetime.LAST_YEAR_ISO = expyct.DateTimeTz(map_before=<function parse_isoformat>, after=datetime.timedelta(days=-365), before=datetime.timedelta(0))

Any timestamp occurring during the last 365 days, parsed from ISO8601 string

expyct.datetime.THIS_DAY = expyct.DateTimeTz(after_strict=datetime.datetime(2024, 3, 19, 0, 0), before_strict=datetime.datetime(2024, 3, 21, 0, 0))

Any timestamp occurring on the current day

expyct.datetime.THIS_DAY_ISO = expyct.DateTimeTz(map_before=<function parse_isoformat>, after_strict=datetime.datetime(2024, 3, 19, 0, 0), before_strict=datetime.datetime(2024, 3, 21, 0, 0))

Any timestamp occurring on the current day, parsed from ISO8601 string

expyct.datetime.THIS_HOUR = expyct.DateTimeTz(after_strict=datetime.datetime(2024, 3, 20, 16, 0), before_strict=datetime.datetime(2024, 3, 20, 18, 0))

Any timestamp occurring in the current hour

expyct.datetime.THIS_MINUTE = expyct.DateTimeTz(after_strict=datetime.datetime(2024, 3, 20, 17, 6), before_strict=datetime.datetime(2024, 3, 20, 17, 8))

Any timestamp occurring in the current minute

expyct.datetime.THIS_SECOND = expyct.DateTimeTz(after_strict=datetime.datetime(2024, 3, 20, 17, 7, 46), before_strict=datetime.datetime(2024, 3, 20, 17, 7, 48))

Any timestamp occurring in the current second

expyct.datetime.TODAY = expyct.DateTimeTz(after_strict=datetime.datetime(2024, 3, 19, 0, 0), before_strict=datetime.datetime(2024, 3, 21, 0, 0))

The same as THIS_DAY

expyct.datetime.TODAY_ISO = expyct.DateTimeTz(map_before=<function parse_isoformat>, after_strict=datetime.datetime(2024, 3, 19, 0, 0), before_strict=datetime.datetime(2024, 3, 21, 0, 0))

The same as THIS_DAY_ISO