Skip to content

Commit 4bcf651

Browse files
committed
Update test_datetime_helpers.py
added test to check the deprecation warning
1 parent dc4f896 commit 4bcf651

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

api_core/tests/unit/test_datetime_helpers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import calendar
1616
import datetime
1717

18+
import mock
1819
import pytest
1920
import pytz
2021

@@ -23,6 +24,8 @@
2324

2425

2526
ONE_MINUTE_IN_MICROSECONDS = 60 * 1e6
27+
MESSAGE = ("The `from_rfc3339_nanos` function is deprecated"
28+
" use `from_rfc3339` instead.")
2629

2730

2831
def test_utcnow():
@@ -123,6 +126,19 @@ def test_from_rfc3339_with_truncated_nanos(truncated, micros):
123126
)
124127

125128

129+
def test_from_rfc3339_nanos_is_deprecated():
130+
from_rfc3339_patch = mock.patch("google.api_core.datetime_helpers.from_rfc3339")
131+
warnings_patch = mock.patch("warnings.warn")
132+
value = "2009-12-17T12:44:32.123456Z"
133+
134+
with from_rfc3339_patch as from_rfc3339, warnings_patch as warn:
135+
result = datetime_helpers.from_rfc3339_nanos(value)
136+
137+
assert result is from_rfc3339.return_value
138+
from_rfc3339.assert_called_once_with(value)
139+
warn.assert_called_once_with(MESSAGE, DeprecationWarning, stacklevel=2)
140+
141+
126142
@pytest.mark.parametrize(
127143
"truncated, micros",
128144
[

0 commit comments

Comments
 (0)