2424
2525
2626ONE_MINUTE_IN_MICROSECONDS = 60 * 1e6
27- MESSAGE = ("The `from_rfc3339_nanos` function is deprecated"
28- " use `from_rfc3339` instead." )
27+ MESSAGE = (
28+ "The `from_rfc3339_nanos` function is deprecated" " use `from_rfc3339` instead."
29+ )
2930
3031
3132def test_utcnow ():
@@ -159,6 +160,18 @@ def test_from_rfc3339_nanos_with_truncated_nanos(truncated, micros):
159160 )
160161
161162
163+ def test_from_rfc3339_wo_nanos_raise_exception ():
164+ value = "2009-12-17T12:44:32"
165+ with pytest .raises (ValueError ):
166+ datetime_helpers .from_rfc3339 (value )
167+
168+
169+ def test_from_rfc3339_w_nanos_raise_exception ():
170+ value = "2009-12-17T12:44:32.123456"
171+ with pytest .raises (ValueError ):
172+ datetime_helpers .from_rfc3339 (value )
173+
174+
162175def test_to_rfc3339 ():
163176 value = datetime .datetime (2016 , 4 , 5 , 13 , 30 , 0 )
164177 expected = "2016-04-05T13:30:00.000000Z"
@@ -186,10 +199,11 @@ def test_to_rfc3339_with_non_utc_ignore_zone():
186199
187200
188201class Test_DateTimeWithNanos (object ):
189-
190202 @staticmethod
191203 def test_ctor_wo_nanos ():
192- stamp = datetime_helpers .DatetimeWithNanoseconds (2016 , 12 , 20 , 21 , 13 , 47 , 123456 )
204+ stamp = datetime_helpers .DatetimeWithNanoseconds (
205+ 2016 , 12 , 20 , 21 , 13 , 47 , 123456
206+ )
193207 assert stamp .year == 2016
194208 assert stamp .month == 12
195209 assert stamp .day == 20
@@ -229,7 +243,9 @@ def test_ctor_w_micros_keyword_and_nanos():
229243
230244 @staticmethod
231245 def test_rfc3339_wo_nanos ():
232- stamp = datetime_helpers .DatetimeWithNanoseconds (2016 , 12 , 20 , 21 , 13 , 47 , 123456 )
246+ stamp = datetime_helpers .DatetimeWithNanoseconds (
247+ 2016 , 12 , 20 , 21 , 13 , 47 , 123456
248+ )
233249 assert stamp .rfc3339 () == "2016-12-20T21:13:47.123456Z"
234250
235251 @staticmethod
@@ -314,12 +330,16 @@ def test_from_rfc3339_w_full_precision():
314330 )
315331 def test_from_rfc3339_test_nanoseconds (fractional , nanos ):
316332 value = "2009-12-17T12:44:32.{}Z" .format (fractional )
317- assert datetime_helpers .DatetimeWithNanoseconds .from_rfc3339 (value ).nanosecond == nanos
333+ assert (
334+ datetime_helpers .DatetimeWithNanoseconds .from_rfc3339 (value ).nanosecond
335+ == nanos
336+ )
318337
319338 @staticmethod
320339 def test_timestamp_pb_wo_nanos_naive ():
321340 stamp = datetime_helpers .DatetimeWithNanoseconds (
322- 2016 , 12 , 20 , 21 , 13 , 47 , 123456 )
341+ 2016 , 12 , 20 , 21 , 13 , 47 , 123456
342+ )
323343 delta = stamp .replace (tzinfo = pytz .UTC ) - datetime_helpers ._UTC_EPOCH
324344 seconds = int (delta .total_seconds ())
325345 nanos = 123456000
@@ -333,7 +353,8 @@ def test_timestamp_pb_w_nanos():
333353 )
334354 delta = stamp - datetime_helpers ._UTC_EPOCH
335355 timestamp = timestamp_pb2 .Timestamp (
336- seconds = int (delta .total_seconds ()), nanos = 123456789 )
356+ seconds = int (delta .total_seconds ()), nanos = 123456789
357+ )
337358 assert stamp .timestamp_pb () == timestamp
338359
339360 @staticmethod
@@ -343,8 +364,7 @@ def test_from_timestamp_pb_wo_nanos():
343364 seconds = int (delta .total_seconds ())
344365 timestamp = timestamp_pb2 .Timestamp (seconds = seconds )
345366
346- stamp = datetime_helpers .DatetimeWithNanoseconds .from_timestamp_pb (
347- timestamp )
367+ stamp = datetime_helpers .DatetimeWithNanoseconds .from_timestamp_pb (timestamp )
348368
349369 assert _to_seconds (when ) == _to_seconds (stamp )
350370 assert stamp .microsecond == 0
@@ -358,8 +378,7 @@ def test_from_timestamp_pb_w_nanos():
358378 seconds = int (delta .total_seconds ())
359379 timestamp = timestamp_pb2 .Timestamp (seconds = seconds , nanos = 123456789 )
360380
361- stamp = datetime_helpers .DatetimeWithNanoseconds .from_timestamp_pb (
362- timestamp )
381+ stamp = datetime_helpers .DatetimeWithNanoseconds .from_timestamp_pb (timestamp )
363382
364383 assert _to_seconds (when ) == _to_seconds (stamp )
365384 assert stamp .microsecond == 123456
0 commit comments