11# See https://github.com/python/cpython/blob/3.9/Lib/test/datetimetester.py
22import unittest
3- from datetime import \
4- timedelta as td ,\
5- timezone as tz ,\
6- datetime as dt ,\
7- fromisoformat as fif
3+ from datetime import timedelta as td , timezone as tz , datetime as dt , fromisoformat as fif
84
95
106### timedelta ################################################################
1713t2 = td (2 , 3 , 4 )
1814t3 = td (2 , 3 , 5 )
1915
20- class TestTimeDelta (unittest .TestCase ):
2116
17+ class TestTimeDelta (unittest .TestCase ):
2218 def test_constructor01 (self ):
2319 self .assertEqual (td (), td (weeks = 0 , days = 0 , hours = 0 , minutes = 0 , seconds = 0 ))
2420
@@ -65,16 +61,22 @@ def test_constructor15(self):
6561 self .assertEqual (td (microseconds = 0.001 ), td (nanoseconds = 1 ))
6662
6763 def test_constant01 (self ):
68- self .assertTrue (td (0 , 0 , 0 , 365 * td .MINYEAR ).total_seconds () >= - 2 ** 63 / 10 ** 9 )
64+ self .assertTrue (td (0 , 0 , 0 , 365 * td .MINYEAR ).total_seconds () >= - ( 2 ** 63 ) / 10 ** 9 )
6965
7066 def test_constant02 (self ):
71- self .assertFalse (td (0 , 0 , 0 , 365 * (td .MINYEAR - 1 )).total_seconds () >= - 2 ** 63 / 10 ** 9 )
67+ self .assertFalse (
68+ td (0 , 0 , 0 , 365 * (td .MINYEAR - 1 )).total_seconds () >= - (2 ** 63 ) / 10 ** 9
69+ )
7270
7371 def test_constant03 (self ):
74- self .assertTrue (td (23 , 59 , 59 , 365 * td .MAXYEAR ).total_seconds () <= (2 ** 63 - 1 ) / 10 ** 9 )
72+ self .assertTrue (
73+ td (23 , 59 , 59 , 365 * td .MAXYEAR ).total_seconds () <= (2 ** 63 - 1 ) / 10 ** 9
74+ )
7575
7676 def test_constant04 (self ):
77- self .assertFalse (td (23 , 59 , 59 , 365 * (td .MAXYEAR + 1 )).total_seconds () <= (2 ** 63 - 1 ) / 10 ** 9 )
77+ self .assertFalse (
78+ td (23 , 59 , 59 , 365 * (td .MAXYEAR + 1 )).total_seconds () <= (2 ** 63 - 1 ) / 10 ** 9
79+ )
7880
7981 def test_computation01 (self ):
8082 self .assertEqual (a + b + c , td (7 , 6 , 10 ))
@@ -270,40 +272,40 @@ def test_compare06(self):
270272 self .assertTrue (not t1 > t2 )
271273
272274 def test_compare07 (self ):
273- self .assertTrue (t1 < t3 )
275+ self .assertTrue (t1 < t3 )
274276
275277 def test_compare08 (self ):
276- self .assertTrue (t3 > t1 )
278+ self .assertTrue (t3 > t1 )
277279
278280 def test_compare09 (self ):
279- self .assertTrue (t1 <= t3 )
281+ self .assertTrue (t1 <= t3 )
280282
281283 def test_compare10 (self ):
282- self .assertTrue (t3 >= t1 )
284+ self .assertTrue (t3 >= t1 )
283285
284286 def test_compare11 (self ):
285- self .assertTrue (t1 != t3 )
287+ self .assertTrue (t1 != t3 )
286288
287289 def test_compare12 (self ):
288- self .assertTrue (t3 != t1 )
290+ self .assertTrue (t3 != t1 )
289291
290292 def test_compare13 (self ):
291- self .assertTrue (not t1 == t3 )
293+ self .assertTrue (not t1 == t3 )
292294
293295 def test_compare14 (self ):
294- self .assertTrue (not t3 == t1 )
296+ self .assertTrue (not t3 == t1 )
295297
296298 def test_compare15 (self ):
297- self .assertTrue (not t1 > t3 )
299+ self .assertTrue (not t1 > t3 )
298300
299301 def test_compare16 (self ):
300- self .assertTrue (not t3 < t1 )
302+ self .assertTrue (not t3 < t1 )
301303
302304 def test_compare17 (self ):
303- self .assertTrue (not t1 >= t3 )
305+ self .assertTrue (not t1 >= t3 )
304306
305307 def test_compare18 (self ):
306- self .assertTrue (not t3 <= t1 )
308+ self .assertTrue (not t3 <= t1 )
307309
308310 def test_str01 (self ):
309311 self .assertEqual (str (td (days = 1 )), "1d 00:00:00" )
@@ -324,13 +326,18 @@ def test_str06(self):
324326 self .assertEqual (str (td (2 , 3 , 4 )), "02:03:04" )
325327
326328 def test_repr01 (self ):
327- self .assertEqual (repr (td (1 )), "datetime.timedelta(seconds={})" .format (1 * 3600.0 ))
329+ self .assertEqual (repr (td (1 )), "datetime.timedelta(seconds={})" .format (1 * 3600.0 ))
328330
329331 def test_repr02 (self ):
330- self .assertEqual (repr (td (10 , 2 )), "datetime.timedelta(seconds={})" .format (10 * 3600 + 2 * 60.0 ))
332+ self .assertEqual (
333+ repr (td (10 , 2 )), "datetime.timedelta(seconds={})" .format (10 * 3600 + 2 * 60.0 )
334+ )
331335
332336 def test_repr03 (self ):
333- self .assertEqual (repr (td (- 10 , 2 , 40 )), "datetime.timedelta(seconds={})" .format (- 10 * 3600 + 2 * 60 + 40.0 ))
337+ self .assertEqual (
338+ repr (td (- 10 , 2 , 40 )),
339+ "datetime.timedelta(seconds={})" .format (- 10 * 3600 + 2 * 60 + 40.0 ),
340+ )
334341
335342 def test_bool01 (self ):
336343 self .assertTrue (td (1 ))
@@ -381,6 +388,7 @@ def test_divmod02(self):
381388
382389### timezone #################################################################
383390
391+ 384392class Cet (tz ):
385393 # Central European Time (see https://en.wikipedia.org/wiki/Summer_time_in_Europe)
386394
@@ -391,7 +399,7 @@ def dst(self, dt):
391399 return td (hours = 1 ) if self .isdst (dt ) else td (0 )
392400
393401 def tzname (self , dt ):
394- return ' CEST' if self .isdst (dt ) else ' CET'
402+ return " CEST" if self .isdst (dt ) else " CET"
395403
396404 def isdst (self , dt ):
397405 if dt is None :
@@ -402,54 +410,59 @@ def isdst(self, dt):
402410 if 3 < month < 10 :
403411 return True
404412 if month == 3 :
405- beg = 31 - (5 * year // 4 + 4 ) % 7 # last Sunday of March
406- if day < beg : return False
407- if day > beg : return True
413+ beg = 31 - (5 * year // 4 + 4 ) % 7 # last Sunday of March
414+ if day < beg :
415+ return False
416+ if day > beg :
417+ return True
408418 return hour >= 3
409419 if month == 10 :
410- end = 31 - (5 * year // 4 + 1 ) % 7 # last Sunday of October
411- if day < end : return True
412- if day > end : return False
420+ end = 31 - (5 * year // 4 + 1 ) % 7 # last Sunday of October
421+ if day < end :
422+ return True
423+ if day > end :
424+ return False
413425 return hour < 3
414426 return False
415427
428+ 416429tz1 = tz (td (hours = - 1 ))
417430tz2 = Cet ()
418431
419- class TestTimeZone (unittest .TestCase ):
420432
433+ class TestTimeZone (unittest .TestCase ):
421434 def test_constructor01 (self ):
422- self .assertEqual (str (tz1 ), ' UTC-01:00' )
435+ self .assertEqual (str (tz1 ), " UTC-01:00" )
423436
424437 def test_constructor02 (self ):
425- self .assertEqual (str (tz2 ), ' CET' )
438+ self .assertEqual (str (tz2 ), " CET" )
426439
427440 def test_utcoffset01 (self ):
428- self .assertEqual (str (tz2 .utcoffset (None )), ' 01:00:00' )
441+ self .assertEqual (str (tz2 .utcoffset (None )), " 01:00:00" )
429442
430443 def test_utcoffset02 (self ):
431- self .assertEqual (str (tz2 .utcoffset (dt (2010 , 3 , 27 , 12 ))), ' 01:00:00' )
444+ self .assertEqual (str (tz2 .utcoffset (dt (2010 , 3 , 27 , 12 ))), " 01:00:00" )
432445
433446 def test_utcoffset03 (self ):
434- self .assertEqual (str (tz2 .utcoffset (dt (2010 , 3 , 28 , 12 ))), ' 02:00:00' )
447+ self .assertEqual (str (tz2 .utcoffset (dt (2010 , 3 , 28 , 12 ))), " 02:00:00" )
435448
436449 def test_utcoffset04 (self ):
437- self .assertEqual (str (tz2 .utcoffset (dt (2010 , 10 , 30 , 12 ))), ' 02:00:00' )
450+ self .assertEqual (str (tz2 .utcoffset (dt (2010 , 10 , 30 , 12 ))), " 02:00:00" )
438451
439452 def test_utcoffset05 (self ):
440- self .assertEqual (str (tz2 .utcoffset (dt (2010 , 10 , 31 , 12 ))), ' 01:00:00' )
453+ self .assertEqual (str (tz2 .utcoffset (dt (2010 , 10 , 31 , 12 ))), " 01:00:00" )
441454
442455 def test_isoformat01 (self ):
443- self .assertEqual (tz2 .isoformat (dt (2011 , 1 , 1 )), ' UTC+01:00' )
456+ self .assertEqual (tz2 .isoformat (dt (2011 , 1 , 1 )), " UTC+01:00" )
444457
445458 def test_isoformat02 (self ):
446- self .assertEqual (tz2 .isoformat (dt (2011 , 8 , 1 )), ' UTC+02:00' )
459+ self .assertEqual (tz2 .isoformat (dt (2011 , 8 , 1 )), " UTC+02:00" )
447460
448461 def test_tzname01 (self ):
449- self .assertEqual (tz2 .tzname (dt (2011 , 1 , 1 )), ' CET' )
462+ self .assertEqual (tz2 .tzname (dt (2011 , 1 , 1 )), " CET" )
450463
451464 def test_tzname02 (self ):
452- self .assertEqual (tz2 .tzname (dt (2011 , 8 , 1 )), ' CEST' )
465+ self .assertEqual (tz2 .tzname (dt (2011 , 8 , 1 )), " CEST" )
453466
454467
455468### datetime #################################################################
@@ -464,8 +477,8 @@ def test_tzname02(self):
464477day = td (days = 1 )
465478week = td (weeks = 1 )
466479
467- class TestTimeZone (unittest .TestCase ):
468480
481+ class TestTimeZone (unittest .TestCase ):
469482 def test_constructor01 (self ):
470483 d = dt (2002 , 3 , 1 , 12 , 0 )
471484 year , month , day , hour , minute , second , nanosecond , tz = d .tuple ()
@@ -551,8 +564,7 @@ def test_constructor22(self):
551564
552565 def test_computation01 (self ):
553566 d = d1 - d2
554- self .assertEqual (d .total_seconds (),
555- (46 * 365 + len (range (1956 , 2002 , 4 )))* 24 * 60 * 60 )
567+ self .assertEqual (d .total_seconds (), (46 * 365 + len (range (1956 , 2002 , 4 ))) * 24 * 60 * 60 )
556568
557569 def test_computation02 (self ):
558570 self .assertEqual (d4 + hour , dt (2002 , 3 , 2 , 18 , 6 ))
@@ -561,7 +573,7 @@ def test_computation02(self):
561573 self .assertEqual (hour + d4 , dt (2002 , 3 , 2 , 18 , 6 ))
562574
563575 def test_computation03 (self ):
564- self .assertEqual (d4 + 10 * hour , dt (2002 , 3 , 3 , 3 , 6 ))
576+ self .assertEqual (d4 + 10 * hour , dt (2002 , 3 , 3 , 3 , 6 ))
565577
566578 def test_computation04 (self ):
567579 self .assertEqual (d4 - hour , dt (2002 , 3 , 2 , 16 , 6 ))
@@ -573,7 +585,7 @@ def test_computation06(self):
573585 self .assertEqual (d4 - hour , d4 + - hour )
574586
575587 def test_computation07 (self ):
576- self .assertEqual (d4 - 20 * hour , dt (2002 , 3 , 1 , 21 , 6 ))
588+ self .assertEqual (d4 - 20 * hour , dt (2002 , 3 , 1 , 21 , 6 ))
577589
578590 def test_computation08 (self ):
579591 self .assertEqual (d4 + day , dt (2002 , 3 , 3 , 17 , 6 ))
@@ -588,10 +600,10 @@ def test_computation11(self):
588600 self .assertEqual (d4 - week , dt (2002 , 2 , 23 , 17 , 6 ))
589601
590602 def test_computation12 (self ):
591- self .assertEqual (d4 + 52 * week , dt (2003 , 3 , 1 , 17 , 6 ))
603+ self .assertEqual (d4 + 52 * week , dt (2003 , 3 , 1 , 17 , 6 ))
592604
593605 def test_computation13 (self ):
594- self .assertEqual (d4 - 52 * week , dt (2001 , 3 , 3 , 17 , 6 ))
606+ self .assertEqual (d4 - 52 * week , dt (2001 , 3 , 3 , 17 , 6 ))
595607
596608 def test_computation14 (self ):
597609 self .assertEqual ((d4 + week ) - d4 , week )
@@ -738,5 +750,5 @@ def test_fromisoformat05(self):
738750 self .assertEqual (str (fif ("1975年08月10日 23:30:12+01:00" )), "1975年08月10日 23:30:12+01:00" )
739751
740752
741- if __name__ == ' __main__' :
753+ if __name__ == " __main__" :
742754 unittest .main ()
0 commit comments