diff options
author | Laurent Peuch <cortex@worlddomination.be> | 2020-04-01 00:11:10 +0200 |
---|---|---|
committer | Laurent Peuch <cortex@worlddomination.be> | 2020-04-01 00:11:10 +0200 |
commit | b8899451fa861b04568e2a0bb4e3fe4acc0daee3 (patch) | |
tree | 1446c809e19b5571b31b1999246aa0e50b19f5c8 /test/test_date.py | |
parent | 32cd73810056594f55eff0ffafebbdeb50c7a860 (diff) | |
download | logilab-common-b8899451fa861b04568e2a0bb4e3fe4acc0daee3.tar.gz |
Black the whole code base
Diffstat (limited to 'test/test_date.py')
-rw-r--r-- | test/test_date.py | 64 |
1 files changed, 43 insertions, 21 deletions
diff --git a/test/test_date.py b/test/test_date.py index 9ae444b..cf09b11 100644 --- a/test/test_date.py +++ b/test/test_date.py @@ -20,20 +20,34 @@ Unittests for date helpers """ from logilab.common.testlib import TestCase, unittest_main, tag -from logilab.common.date import (date_range, endOfMonth, add_days_worked, - nb_open_days, get_national_holidays, ustrftime, ticks2datetime, - utcdatetime, datetime2ticks) +from logilab.common.date import ( + date_range, + endOfMonth, + add_days_worked, + nb_open_days, + get_national_holidays, + ustrftime, + ticks2datetime, + utcdatetime, + datetime2ticks, +) from datetime import date, datetime, timedelta from calendar import timegm import pytz try: - from mx.DateTime import Date as mxDate, DateTime as mxDateTime, \ - now as mxNow, RelativeDateTime, RelativeDate + from mx.DateTime import ( + Date as mxDate, + DateTime as mxDateTime, + now as mxNow, + RelativeDateTime, + RelativeDate, + ) except ImportError: mxDate = mxDateTime = RelativeDateTime = mxNow = None + class DateTC(TestCase): datecls = date datetimecls = datetime @@ -65,8 +79,9 @@ class DateTC(TestCase): def test_get_national_holidays(self): holidays = get_national_holidays - yield self.assertEqual, holidays(self.datecls(2008, 4, 29), self.datecls(2008, 5, 2)), \ - [self.datecls(2008, 5, 1)] + yield self.assertEqual, holidays(self.datecls(2008, 4, 29), self.datecls(2008, 5, 2)), [ + self.datecls(2008, 5, 1) + ] yield self.assertEqual, holidays(self.datecls(2008, 5, 7), self.datecls(2008, 5, 8)), [] x = self.datetimecls(2008, 5, 7, 12, 12, 12) yield self.assertEqual, holidays(x, x + self.timedeltacls(days=1)), [] @@ -129,22 +144,26 @@ class DateTC(TestCase): def test_open_days_afternoon(self): self.assertOpenDays(self.datetimecls(2008, 5, 6, 14), self.datetimecls(2008, 5, 7, 14), 1) - @tag('posix', '1900') + @tag("posix", "1900") def test_ustrftime_before_1900(self): date = self.datetimecls(1328, 3, 12, 6, 30) - self.assertEqual(ustrftime(date, '%Y-%m-%d %H:%M:%S'), u'1328-03-12 06:30:00') + self.assertEqual(ustrftime(date, "%Y-%m-%d %H:%M:%S"), "1328-03-12 06:30:00") - @tag('posix', '1900') + @tag("posix", "1900") def test_ticks2datetime_before_1900(self): ticks = -2209075200000 date = ticks2datetime(ticks) - self.assertEqual(ustrftime(date, '%Y-%m-%d'), u'1899-12-31') + self.assertEqual(ustrftime(date, "%Y-%m-%d"), "1899-12-31") def test_month(self): """enumerate months""" - r = list(date_range(self.datecls(2006, 5, 6), self.datecls(2006, 8, 27), - incmonth=True)) - expected = [self.datecls(2006, 5, 6), self.datecls(2006, 6, 1), self.datecls(2006, 7, 1), self.datecls(2006, 8, 1)] + r = list(date_range(self.datecls(2006, 5, 6), self.datecls(2006, 8, 27), incmonth=True)) + expected = [ + self.datecls(2006, 5, 6), + self.datecls(2006, 6, 1), + self.datecls(2006, 7, 1), + self.datecls(2006, 8, 1), + ] self.assertListEqual(expected, r) def test_utcdatetime(self): @@ -155,14 +174,12 @@ class DateTC(TestCase): self.assertEqual(d, self.datetimecls(2014, 11, 26, 12, 0, 0, 57)) self.assertIsNone(d.tzinfo) - d = pytz.timezone('Europe/Paris').localize( - self.datetimecls(2014, 11, 26, 12, 0, 0, 57)) + d = pytz.timezone("Europe/Paris").localize(self.datetimecls(2014, 11, 26, 12, 0, 0, 57)) d = utcdatetime(d) self.assertEqual(d, self.datetimecls(2014, 11, 26, 11, 0, 0, 57)) self.assertIsNone(d.tzinfo) - d = pytz.timezone('Europe/Paris').localize( - self.datetimecls(2014, 7, 26, 12, 0, 0, 57)) + d = pytz.timezone("Europe/Paris").localize(self.datetimecls(2014, 7, 26, 12, 0, 0, 57)) d = utcdatetime(d) self.assertEqual(d, self.datetimecls(2014, 7, 26, 10, 0, 0, 57)) self.assertIsNone(d.tzinfo) @@ -188,7 +205,7 @@ class MxDateTC(DateTC): def check_mx(self): if mxDate is None: - self.skipTest('mx.DateTime is not installed') + self.skipTest("mx.DateTime is not installed") def setUp(self): self.check_mx() @@ -199,8 +216,13 @@ class MxDateTC(DateTC): expected = [self.datecls(2000, 1, 2), self.datecls(2000, 2, 29), self.datecls(2000, 3, 31)] self.assertListEqual(r, expected) r = list(date_range(self.datecls(2000, 11, 30), self.datecls(2001, 2, 3), endOfMonth)) - expected = [self.datecls(2000, 11, 30), self.datecls(2000, 12, 31), self.datecls(2001, 1, 31)] + expected = [ + self.datecls(2000, 11, 30), + self.datecls(2000, 12, 31), + self.datecls(2001, 1, 31), + ] self.assertListEqual(r, expected) -if __name__ == '__main__': + +if __name__ == "__main__": unittest_main() |