Skip to content

Commit ffc97ed

Browse files
authored
Add parameterized test for from_rfc3339 with nanos (#7675)
* Add parameterized test for from_rfc3339 with nanos
1 parent b8bfce4 commit ffc97ed

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

api_core/tests/unit/test_datetime_helpers.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,24 @@ def test_from_rfc3339_w_full_precision():
269269
stamp = datetime_helpers.DatetimeWithNanoseconds.from_rfc3339(timestamp)
270270
assert stamp == expected
271271

272+
@staticmethod
273+
@pytest.mark.parametrize(
274+
"fractional, nanos",
275+
[
276+
("12345678", 123456780),
277+
("1234567", 123456700),
278+
("123456", 123456000),
279+
("12345", 123450000),
280+
("1234", 123400000),
281+
("123", 123000000),
282+
("12", 120000000),
283+
("1", 100000000),
284+
],
285+
)
286+
def test_from_rfc3339_test_nanoseconds(fractional, nanos):
287+
value = "2009-12-17T12:44:32.{}Z".format(fractional)
288+
assert datetime_helpers.DatetimeWithNanoseconds.from_rfc3339(value).nanosecond == nanos
289+
272290
@staticmethod
273291
def test_timestamp_pb_wo_nanos_naive():
274292
stamp = datetime_helpers.DatetimeWithNanoseconds(

0 commit comments

Comments
 (0)