diff options
author | gleeper <31918270+gleeper@users.noreply.github.com> | 2019-04-07 21:44:08 -0400 |
---|---|---|
committer | Christopher Wilcox <crwilcox@google.com> | 2019-04-07 18:44:08 -0700 |
commit | ca8822b19be3247a99e7b50494b0f6adfa8132d8 (patch) | |
tree | 7cf0e7f8e9c19558bb8cbe60209ffc5d7f333ea1 /tests | |
parent | e6eb1c55805db6151771ec7f2312490da17b636f (diff) | |
download | python-api-core-ca8822b19be3247a99e7b50494b0f6adfa8132d8.tar.gz |
Append leading zeros for nanosecond precision DateTimes (#7663)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/test_datetime_helpers.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/unit/test_datetime_helpers.py b/tests/unit/test_datetime_helpers.py index e5220ae..a53086e 100644 --- a/tests/unit/test_datetime_helpers.py +++ b/tests/unit/test_datetime_helpers.py @@ -204,6 +204,11 @@ class Test_DateTimeWithNanos(object): assert stamp.rfc3339() == "2016-12-20T21:13:47.123456Z" @staticmethod + def test_rfc3339_wo_nanos_w_leading_zero(): + stamp = datetime_helpers.DatetimeWithNanoseconds(2016, 12, 20, 21, 13, 47, 1234) + assert stamp.rfc3339() == "2016-12-20T21:13:47.001234Z" + + @staticmethod def test_rfc3339_w_nanos(): stamp = datetime_helpers.DatetimeWithNanoseconds( 2016, 12, 20, 21, 13, 47, nanosecond=123456789 @@ -211,6 +216,13 @@ class Test_DateTimeWithNanos(object): assert stamp.rfc3339() == "2016-12-20T21:13:47.123456789Z" @staticmethod + def test_rfc3339_w_nanos_w_leading_zero(): + stamp = datetime_helpers.DatetimeWithNanoseconds( + 2016, 12, 20, 21, 13, 47, nanosecond=1234567 + ) + assert stamp.rfc3339() == "2016-12-20T21:13:47.001234567Z" + + @staticmethod def test_rfc3339_w_nanos_no_trailing_zeroes(): stamp = datetime_helpers.DatetimeWithNanoseconds( 2016, 12, 20, 21, 13, 47, nanosecond=100000000 @@ -218,6 +230,13 @@ class Test_DateTimeWithNanos(object): assert stamp.rfc3339() == "2016-12-20T21:13:47.1Z" @staticmethod + def test_rfc3339_w_nanos_w_leading_zero_and_no_trailing_zeros(): + stamp = datetime_helpers.DatetimeWithNanoseconds( + 2016, 12, 20, 21, 13, 47, nanosecond=1234500 + ) + assert stamp.rfc3339() == "2016-12-20T21:13:47.0012345Z" + + @staticmethod def test_from_rfc3339_w_invalid(): stamp = "2016-12-20T21:13:47" with pytest.raises(ValueError): |