@@ -39,9 +39,7 @@ def test_chrono_system_clock_roundtrip():
39
39
40
40
# They should be identical (no information lost on roundtrip)
41
41
diff = abs (date1 - date2 )
42
- assert diff .days == 0
43
- assert diff .seconds == 0
44
- assert diff .microseconds == 0
42
+ assert diff == datetime .timedelta (0 )
45
43
46
44
47
45
def test_chrono_system_clock_roundtrip_date ():
@@ -64,9 +62,7 @@ def test_chrono_system_clock_roundtrip_date():
64
62
assert diff .microseconds == 0
65
63
66
64
# Year, Month & Day should be the same after the round trip
67
- assert date1 .year == date2 .year
68
- assert date1 .month == date2 .month
69
- assert date1 .day == date2 .day
65
+ assert date1 == date2
70
66
71
67
# There should be no time information
72
68
assert time2 .hour == 0
@@ -117,10 +113,7 @@ def test_chrono_system_clock_roundtrip_time(time1, tz, monkeypatch):
117
113
assert isinstance (time2 , datetime .time )
118
114
119
115
# Hour, Minute, Second & Microsecond should be the same after the round trip
120
- assert time1 .hour == time2 .hour
121
- assert time1 .minute == time2 .minute
122
- assert time1 .second == time2 .second
123
- assert time1 .microsecond == time2 .microsecond
116
+ assert time1 == time2
124
117
125
118
# There should be no date information (i.e. date = python base date)
126
119
assert date2 .year == 1970
@@ -140,9 +133,13 @@ def test_chrono_duration_roundtrip():
140
133
141
134
cpp_diff = m .test_chrono3 (diff )
142
135
143
- assert cpp_diff .days == diff .days
144
- assert cpp_diff .seconds == diff .seconds
145
- assert cpp_diff .microseconds == diff .microseconds
136
+ assert cpp_diff == diff
137
+
138
+ # Negative timedelta roundtrip
139
+ diff = datetime .timedelta (microseconds = - 1 )
140
+ cpp_diff = m .test_chrono3 (diff )
141
+
142
+ assert cpp_diff == diff
146
143
147
144
148
145
def test_chrono_duration_subtraction_equivalence ():
@@ -153,9 +150,7 @@ def test_chrono_duration_subtraction_equivalence():
153
150
diff = date2 - date1
154
151
cpp_diff = m .test_chrono4 (date2 , date1 )
155
152
156
- assert cpp_diff .days == diff .days
157
- assert cpp_diff .seconds == diff .seconds
158
- assert cpp_diff .microseconds == diff .microseconds
153
+ assert cpp_diff == diff
159
154
160
155
161
156
def test_chrono_duration_subtraction_equivalence_date ():
@@ -166,9 +161,7 @@ def test_chrono_duration_subtraction_equivalence_date():
166
161
diff = date2 - date1
167
162
cpp_diff = m .test_chrono4 (date2 , date1 )
168
163
169
- assert cpp_diff .days == diff .days
170
- assert cpp_diff .seconds == diff .seconds
171
- assert cpp_diff .microseconds == diff .microseconds
164
+ assert cpp_diff == diff
172
165
173
166
174
167
def test_chrono_steady_clock ():
@@ -183,9 +176,7 @@ def test_chrono_steady_clock_roundtrip():
183
176
assert isinstance (time2 , datetime .timedelta )
184
177
185
178
# They should be identical (no information lost on roundtrip)
186
- assert time1 .days == time2 .days
187
- assert time1 .seconds == time2 .seconds
188
- assert time1 .microseconds == time2 .microseconds
179
+ assert time1 == time2
189
180
190
181
191
182
def test_floating_point_duration ():
0 commit comments