Date & time assertions¶
Assertions for datetime.date and datetime.datetime values.
Date and time assertions mixin.
is_before ¶
Asserts that val is a date and is before other date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
the other date, expected to be after val |
required |
Examples:
Usage:
import datetime
today = datetime.datetime.now()
yesterday = today - datetime.timedelta(days=1)
assert_that(yesterday).is_before(today)
Returns:
| Name | Type | Description |
|---|---|---|
AssertionBuilder |
Self
|
returns this instance to chain to the next assertion |
Raises:
| Type | Description |
|---|---|
AssertionError
|
if val is not before the given date |
See Also
is_less_than() - numeric assertion, but
also works with datetime
is_less_than_or_equal_to() -
also works with datetime
Source code in assertpy2/date.py
is_after ¶
Asserts that val is a date and is after other date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
the other date, expected to be before val |
required |
Examples:
Usage:
import datetime
today = datetime.datetime.now()
yesterday = today - datetime.timedelta(days=1)
assert_that(today).is_after(yesterday)
Returns:
| Name | Type | Description |
|---|---|---|
AssertionBuilder |
Self
|
returns this instance to chain to the next assertion |
Raises:
| Type | Description |
|---|---|
AssertionError
|
if val is not after the given date |
See Also
is_greater_than() - numeric assertion,
but also works with datetime
is_greater_than_or_equal_to() -
also works with datetime
Source code in assertpy2/date.py
is_before_or_equal_to ¶
Asserts that val is a date and is before or equal to other date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
the other date, expected to be after or equal to val |
required |
Examples:
Usage:
import datetime
today = datetime.datetime.now()
yesterday = today - datetime.timedelta(days=1)
assert_that(yesterday).is_before_or_equal_to(today)
assert_that(today).is_before_or_equal_to(today)
Returns:
| Name | Type | Description |
|---|---|---|
AssertionBuilder |
Self
|
returns this instance to chain to the next assertion |
Raises:
| Type | Description |
|---|---|
AssertionError
|
if val is not before or equal to the given date |
Source code in assertpy2/date.py
is_after_or_equal_to ¶
Asserts that val is a date and is after or equal to other date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
the other date, expected to be before or equal to val |
required |
Examples:
Usage:
import datetime
today = datetime.datetime.now()
yesterday = today - datetime.timedelta(days=1)
assert_that(today).is_after_or_equal_to(yesterday)
assert_that(today).is_after_or_equal_to(today)
Returns:
| Name | Type | Description |
|---|---|---|
AssertionBuilder |
Self
|
returns this instance to chain to the next assertion |
Raises:
| Type | Description |
|---|---|
AssertionError
|
if val is not after or equal to the given date |
Source code in assertpy2/date.py
is_equal_to_ignoring_milliseconds ¶
Asserts that val is a date and is equal to other date to the second.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
the other date, expected to be equal to the second |
required |
Examples:
Usage:
import datetime
d1 = datetime.datetime(2020, 1, 2, 3, 4, 5, 6) # 2020-01-02 03:04:05.000006
d2 = datetime.datetime(2020, 1, 2, 3, 4, 5, 777777) # 2020-01-02 03:04:05.777777
assert_that(d1).is_equal_to_ignoring_milliseconds(d2)
Returns:
| Name | Type | Description |
|---|---|---|
AssertionBuilder |
Self
|
returns this instance to chain to the next assertion |
Raises:
| Type | Description |
|---|---|
AssertionError
|
if val is not equal to the given date to the second |
Source code in assertpy2/date.py
is_equal_to_ignoring_seconds ¶
Asserts that val is a date and is equal to other date to the minute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
the other date, expected to be equal to the minute |
required |
Examples:
Usage:
import datetime
d1 = datetime.datetime(2020, 1, 2, 3, 4, 5) # 2020-01-02 03:04:05
d2 = datetime.datetime(2020, 1, 2, 3, 4, 55) # 2020-01-02 03:04:55
assert_that(d1).is_equal_to_ignoring_seconds(d2)
Returns:
| Name | Type | Description |
|---|---|---|
AssertionBuilder |
Self
|
returns this instance to chain to the next assertion |
Raises:
| Type | Description |
|---|---|
AssertionError
|
if val is not equal to the given date to the minute |
Source code in assertpy2/date.py
is_equal_to_ignoring_time ¶
Asserts that val is a date and is equal to other date ignoring time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
the other date, expected to be equal ignoring time |
required |
Examples:
Usage:
import datetime
d1 = datetime.datetime(2020, 1, 2, 3, 4, 5) # 2020-01-02 03:04:05
d2 = datetime.datetime(2020, 1, 2, 13, 44, 55) # 2020-01-02 13:44:55
assert_that(d1).is_equal_to_ignoring_time(d2)
Returns:
| Name | Type | Description |
|---|---|---|
AssertionBuilder |
Self
|
returns this instance to chain to the next assertion |
Raises:
| Type | Description |
|---|---|
AssertionError
|
if val is not equal to the given date ignoring time |