File tree Expand file tree Collapse file tree 3 files changed +14
-4
lines changed
python/google/protobuf/internal Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,11 @@ def test_duration_add_annotation(self):
93
93
# Duration + Duration
94
94
self .assertEqual (dr + dr2 , dr2 + dr )
95
95
96
+ def test_assign_datetime_to_duration (self ):
97
+ message = well_known_types_test_pb2 .WKTMessage ()
98
+ with self .assertRaises ((TypeError , AttributeError )):
99
+ message .optional_duration = datetime .datetime .now ()
100
+
96
101
97
102
if __name__ == '__main__' :
98
103
unittest .main ()
Original file line number Diff line number Diff line change @@ -90,6 +90,11 @@ def test_timestamp_add_annotation(self):
90
90
# Timestamp + Duration and Duration + Timestamp
91
91
self .assertEqual (ts + msg .optional_duration , msg .optional_duration + ts )
92
92
93
+ def test_assign_duration_to_timestamp (self ):
94
+ message = well_known_types_test_pb2 .WKTMessage ()
95
+ with self .assertRaises ((TypeError , AttributeError )):
96
+ message .optional_timestamp = datetime .timedelta (microseconds = 123 )
97
+
93
98
94
99
if __name__ == '__main__' :
95
100
unittest .main ()
Original file line number Diff line number Diff line change @@ -540,10 +540,10 @@ def testInvalidTimestamp(self):
540
540
self .assertRaisesRegex (ValueError , 'Timestamp is not valid' ,
541
541
message .FromSeconds , - 62135596801 )
542
542
msg = well_known_types_test_pb2 .WKTMessage ()
543
- with self .assertRaises (AttributeError ):
543
+ with self .assertRaises (( TypeError , AttributeError ) ):
544
544
msg .optional_timestamp = 1
545
545
546
- with self .assertRaises (AttributeError ):
546
+ with self .assertRaises (( TypeError , AttributeError ) ):
547
547
msg2 = well_known_types_test_pb2 .WKTMessage (optional_timestamp = 1 )
548
548
549
549
with self .assertRaises (TypeError ):
@@ -606,10 +606,10 @@ def testInvalidDuration(self):
606
606
message .ToJsonString ,
607
607
)
608
608
msg = well_known_types_test_pb2 .WKTMessage ()
609
- with self .assertRaises (AttributeError ):
609
+ with self .assertRaises (( TypeError , AttributeError ) ):
610
610
msg .optional_duration = 1
611
611
612
- with self .assertRaises (AttributeError ):
612
+ with self .assertRaises (( TypeError , AttributeError ) ):
613
613
msg2 = well_known_types_test_pb2 .WKTMessage (optional_duration = 1 )
614
614
615
615
with self .assertRaises (TypeError ):
You can’t perform that action at this time.
0 commit comments