mirror of
https://github.com/Infinidat/infi.clickhouse_orm.git
synced 2024-11-22 00:56:34 +03:00
Skip some tests when the server isn't in UTC timezone
This commit is contained in:
parent
39eea8490f
commit
33ad54d6de
|
@ -213,7 +213,6 @@ class FuncsTestCase(TestCaseWithData):
|
|||
self._test_func(F.toDayOfMonth(dt), 31)
|
||||
self._test_func(F.toDayOfWeek(d), 1)
|
||||
self._test_func(F.toDayOfWeek(dt), 1)
|
||||
self._test_func(F.toHour(dt), 11)
|
||||
self._test_func(F.toMinute(dt), 22)
|
||||
self._test_func(F.toSecond(dt), 33)
|
||||
self._test_func(F.toMonday(d), d)
|
||||
|
@ -228,15 +227,10 @@ class FuncsTestCase(TestCaseWithData):
|
|||
self._test_func(F.toStartOfFiveMinute(dt), datetime(2018, 12, 31, 11, 20, 0, tzinfo=pytz.utc))
|
||||
self._test_func(F.toStartOfFifteenMinutes(dt), datetime(2018, 12, 31, 11, 15, 0, tzinfo=pytz.utc))
|
||||
self._test_func(F.toStartOfHour(dt), datetime(2018, 12, 31, 11, 0, 0, tzinfo=pytz.utc))
|
||||
self._test_func(F.toStartOfDay(dt), datetime(2018, 12, 31, 0, 0, 0, tzinfo=pytz.utc))
|
||||
self._test_func(F.toStartOfISOYear(dt), date(2018, 12, 31))
|
||||
self._test_func(F.toStartOfTenMinutes(dt), datetime(2018, 12, 31, 11, 20, 0, tzinfo=pytz.utc))
|
||||
self._test_func(F.toStartOfWeek(dt), date(2018, 12, 30))
|
||||
self._test_func(F.toTime(dt), datetime(1970, 1, 2, 11, 22, 33, tzinfo=pytz.utc))
|
||||
self._test_func(F.toTime(dt, pytz.utc), datetime(1970, 1, 2, 11, 22, 33, tzinfo=pytz.utc))
|
||||
self._test_func(F.toTime(dt, 'Europe/Athens'), datetime(1970, 1, 2, 13, 22, 33, tzinfo=pytz.utc))
|
||||
self._test_func(F.toTime(dt, pytz.timezone('Europe/Athens')), datetime(1970, 1, 2, 13, 22, 33, tzinfo=pytz.utc))
|
||||
self._test_func(F.toTimeZone(dt, 'Europe/Athens'), datetime(2018, 12, 31, 13, 22, 33, tzinfo=pytz.utc))
|
||||
self._test_func(F.toUnixTimestamp(dt, 'UTC'), int(dt.replace(tzinfo=pytz.utc).timestamp()))
|
||||
self._test_func(F.toYYYYMM(d), 201812)
|
||||
self._test_func(F.toYYYYMM(dt), 201812)
|
||||
|
@ -245,7 +239,6 @@ class FuncsTestCase(TestCaseWithData):
|
|||
self._test_func(F.toYYYYMMDD(dt), 20181231)
|
||||
self._test_func(F.toYYYYMMDD(dt, 'Europe/Athens'), 20181231)
|
||||
self._test_func(F.toYYYYMMDDhhmmss(d), 20181231000000)
|
||||
self._test_func(F.toYYYYMMDDhhmmss(dt), 20181231112233)
|
||||
self._test_func(F.toYYYYMMDDhhmmss(dt, 'Europe/Athens'), 20181231132233)
|
||||
self._test_func(F.toRelativeYearNum(dt), 2018)
|
||||
self._test_func(F.toRelativeYearNum(dt, 'Europe/Athens'), 2018)
|
||||
|
@ -262,17 +255,14 @@ class FuncsTestCase(TestCaseWithData):
|
|||
self._test_func(F.toRelativeSecondNum(dt), 1546255353)
|
||||
self._test_func(F.toRelativeSecondNum(dt, 'Europe/Athens'), 1546255353)
|
||||
self._test_func(F.now(), datetime.utcnow().replace(tzinfo=pytz.utc, microsecond=0)) # FIXME this may fail if the timing is just right
|
||||
self._test_func(F.today(), date.today()) # FIXME this may fail if the timing is just right
|
||||
self._test_func(F.yesterday(), date.today() - timedelta(days=1))
|
||||
self._test_func(F.today(), datetime.utcnow().date())
|
||||
self._test_func(F.yesterday(), datetime.utcnow().date() - timedelta(days=1))
|
||||
self._test_func(F.timeSlot(dt), datetime(2018, 12, 31, 11, 0, 0, tzinfo=pytz.utc))
|
||||
self._test_func(F.timeSlots(dt, 300), [datetime(2018, 12, 31, 11, 0, 0, tzinfo=pytz.utc)])
|
||||
self._test_func(F.formatDateTime(dt, '%D %T'), '12/31/18 11:22:33')
|
||||
self._test_func(F.formatDateTime(dt, '%D %T', 'Europe/Athens'), '12/31/18 13:22:33')
|
||||
self._test_func(F.addDays(d, 7), date(2019, 1, 7))
|
||||
self._test_func(F.addDays(dt, 7, 'Europe/Athens'))
|
||||
self._test_func(F.addHours(d, 7), datetime(2018, 12, 31, 7, 0, 0, tzinfo=pytz.utc))
|
||||
self._test_func(F.addHours(dt, 7, 'Europe/Athens'))
|
||||
self._test_func(F.addMinutes(d, 7), datetime(2018, 12, 31, 0, 7, 0, tzinfo=pytz.utc))
|
||||
self._test_func(F.addMinutes(dt, 7, 'Europe/Athens'))
|
||||
self._test_func(F.addMonths(d, 7), date(2019, 7, 31))
|
||||
self._test_func(F.addMonths(dt, 7, 'Europe/Athens'))
|
||||
|
@ -304,6 +294,22 @@ class FuncsTestCase(TestCaseWithData):
|
|||
self._test_func(F.now() + F.toIntervalWeek(3) + F.toIntervalMonth(3) + F.toIntervalQuarter(3) + F.toIntervalYear(3))
|
||||
self._test_func(F.now() + F.toIntervalSecond(3000) - F.toIntervalDay(3000) == F.now() + timedelta(seconds=3000, days=-3000))
|
||||
|
||||
def test_date_functions__utc_only(self):
|
||||
if self.database.server_timezone != pytz.utc:
|
||||
raise unittest.SkipTest('This test must run with UTC as the server timezone')
|
||||
d = date(2018, 12, 31)
|
||||
dt = datetime(2018, 12, 31, 11, 22, 33)
|
||||
self._test_func(F.toHour(dt), 11)
|
||||
self._test_func(F.toStartOfDay(dt), datetime(2018, 12, 31, 0, 0, 0, tzinfo=pytz.utc))
|
||||
self._test_func(F.toTime(dt, pytz.utc), datetime(1970, 1, 2, 11, 22, 33, tzinfo=pytz.utc))
|
||||
self._test_func(F.toTime(dt, 'Europe/Athens'), datetime(1970, 1, 2, 13, 22, 33, tzinfo=pytz.utc))
|
||||
self._test_func(F.toTime(dt, pytz.timezone('Europe/Athens')), datetime(1970, 1, 2, 13, 22, 33, tzinfo=pytz.utc))
|
||||
self._test_func(F.toTimeZone(dt, 'Europe/Athens'), datetime(2018, 12, 31, 13, 22, 33, tzinfo=pytz.utc))
|
||||
self._test_func(F.toYYYYMMDDhhmmss(dt), 20181231112233)
|
||||
self._test_func(F.formatDateTime(dt, '%D %T'), '12/31/18 11:22:33')
|
||||
self._test_func(F.addHours(d, 7), datetime(2018, 12, 31, 7, 0, 0, tzinfo=pytz.utc))
|
||||
self._test_func(F.addMinutes(d, 7), datetime(2018, 12, 31, 0, 7, 0, tzinfo=pytz.utc))
|
||||
|
||||
def test_type_conversion_functions(self):
|
||||
for f in (F.toUInt8, F.toUInt16, F.toUInt32, F.toUInt64, F.toInt8, F.toInt16, F.toInt32, F.toInt64, F.toFloat32, F.toFloat64):
|
||||
self._test_func(f(17), 17)
|
||||
|
@ -315,22 +321,26 @@ class FuncsTestCase(TestCaseWithData):
|
|||
self._test_func(f(17.17, 2), Decimal('17.17'))
|
||||
self._test_func(f('17.17', 2), Decimal('17.17'))
|
||||
self._test_func(F.toDate('2018-12-31'), date(2018, 12, 31))
|
||||
self._test_func(F.toDateTime('2018-12-31 11:22:33'), datetime(2018, 12, 31, 11, 22, 33, tzinfo=pytz.utc))
|
||||
self._test_func(F.toString(123), '123')
|
||||
self._test_func(F.toFixedString('123', 5), '123')
|
||||
self._test_func(F.toStringCutToZero('123\0'), '123')
|
||||
self._test_func(F.CAST(17, 'String'), '17')
|
||||
self._test_func(F.parseDateTimeBestEffort('31/12/2019 10:05AM'), datetime(2019, 12, 31, 10, 5, tzinfo=pytz.utc))
|
||||
self._test_func(F.parseDateTimeBestEffort('31/12/2019 10:05AM', 'Europe/Athens'))
|
||||
with self.assertRaises(ServerError):
|
||||
self._test_func(F.parseDateTimeBestEffort('foo'))
|
||||
self._test_func(F.parseDateTimeBestEffortOrNull('31/12/2019 10:05AM'), datetime(2019, 12, 31, 10, 5, tzinfo=pytz.utc))
|
||||
self._test_func(F.parseDateTimeBestEffortOrNull('31/12/2019 10:05AM', 'Europe/Athens'))
|
||||
self._test_func(F.parseDateTimeBestEffortOrNull('foo'), None)
|
||||
self._test_func(F.parseDateTimeBestEffortOrZero('31/12/2019 10:05AM'), datetime(2019, 12, 31, 10, 5, tzinfo=pytz.utc))
|
||||
self._test_func(F.parseDateTimeBestEffortOrZero('31/12/2019 10:05AM', 'Europe/Athens'))
|
||||
self._test_func(F.parseDateTimeBestEffortOrZero('foo'), DateTimeField.class_default)
|
||||
|
||||
def test_type_conversion_functions__utc_only(self):
|
||||
if self.database.server_timezone != pytz.utc:
|
||||
raise unittest.SkipTest('This test must run with UTC as the server timezone')
|
||||
self._test_func(F.toDateTime('2018-12-31 11:22:33'), datetime(2018, 12, 31, 11, 22, 33, tzinfo=pytz.utc))
|
||||
self._test_func(F.parseDateTimeBestEffort('31/12/2019 10:05AM'), datetime(2019, 12, 31, 10, 5, tzinfo=pytz.utc))
|
||||
self._test_func(F.parseDateTimeBestEffortOrNull('31/12/2019 10:05AM'), datetime(2019, 12, 31, 10, 5, tzinfo=pytz.utc))
|
||||
self._test_func(F.parseDateTimeBestEffortOrZero('31/12/2019 10:05AM'), datetime(2019, 12, 31, 10, 5, tzinfo=pytz.utc))
|
||||
|
||||
def test_string_functions(self):
|
||||
self._test_func(F.empty(''), 1)
|
||||
self._test_func(F.empty('x'), 0)
|
||||
|
|
Loading…
Reference in New Issue
Block a user