-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some unit tests to validate CI pipeline
- Loading branch information
1 parent
9d3c13a
commit 116826d
Showing
6 changed files
with
80 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
''' | ||
Utility functions. | ||
''' | ||
|
||
from datetime import datetime, timezone | ||
|
||
|
||
def timezone_aware(date: datetime) -> datetime: | ||
''' | ||
Convert naive to timezone-aware datetime (UTC timezone). | ||
Arguments: | ||
date (datetime): Datetime object. | ||
Returns: | ||
datetime: A timezone-aware datetime. | ||
''' | ||
|
||
return date.replace(tzinfo=timezone.utc) if date.tzinfo is None else date | ||
|
||
|
||
__all__ = [ | ||
'timezone_aware' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
''' | ||
Test utility functions. | ||
''' | ||
|
||
from datetime import datetime, timezone | ||
|
||
from metastore import utils | ||
|
||
|
||
def test_timezone_aware_should_return_same_timezone_aware_datetime_with_timezone_aware_datetime_argument(): # pylint: disable=C0301 | ||
''' | ||
Test converting naive to timezone-aware datetime (UTC timezone) | ||
with timezone-aware datetime argument. | ||
Raises: | ||
AssertionError: Expected value does not match the returned value. | ||
''' | ||
|
||
expected_datetime = datetime.now(tz=timezone.utc) | ||
actual_datetime = utils.timezone_aware(expected_datetime) | ||
|
||
assert actual_datetime == expected_datetime | ||
|
||
|
||
def test_timezone_aware_should_return_new_timezone_aware_datetime_with_naive_timezone_datetime_argument(): # pylint: disable=C0301 | ||
''' | ||
Test converting naive to timezone-aware datetime (UTC timezone) | ||
with naive datetime argument. | ||
Raises: | ||
AssertionError: Expected value does not match the returned value. | ||
''' | ||
|
||
input_datetime = datetime.now() | ||
expected_datetime = input_datetime.replace(tzinfo=timezone.utc) | ||
actual_datetime = utils.timezone_aware(input_datetime) | ||
|
||
assert actual_datetime == expected_datetime |