|
1 | | -from datetime import date, datetime, timezone |
| 1 | +from datetime import date, datetime, timedelta, timezone |
2 | 2 | from decimal import Decimal |
3 | 3 | import enum |
4 | 4 | from ipaddress import IPv4Address, IPv6Address |
@@ -54,6 +54,7 @@ class CustomStr(str): |
54 | 54 |
|
55 | 55 | SaType = Union[sa.types.TypeEngine, Type[sa.types.TypeEngine]] |
56 | 56 |
|
| 57 | + |
57 | 58 | def combine_typed_rapameters(spec_seq: Iterable[Tuple[SaType, Iterable]]): |
58 | 59 | return list( # Wrap into list to make it reusable (iterator is one-off) |
59 | 60 | itertools.chain(*[ |
@@ -175,13 +176,29 @@ async def test_as_is_round(conn, value): |
175 | 176 | ], |
176 | 177 | ids = parametrized_id, |
177 | 178 | ) |
178 | | -async def test_zero_dates(conn, sa_type, value): |
| 179 | +async def test_zero_dates(clickhouse_version, conn, sa_type, value): |
| 180 | + if clickhouse_version >= (20, 7): |
| 181 | + pytest.skip('Feature is dropped in 20.7') |
179 | 182 | result = await conn.fetchval( |
180 | 183 | sa.select([sa.func.cast(value, sa_type)]) |
181 | 184 | ) |
182 | 185 | assert result is None |
183 | 186 |
|
184 | 187 |
|
| 188 | +@pytest.mark.parametrize('tz_name,tz_offset', [ |
| 189 | + ('UTC', 0), |
| 190 | + ('EST', -18_000), |
| 191 | + ('Europe/Moscow', 10_800), |
| 192 | +]) |
| 193 | +async def test_timezones(conn, tz_name, tz_offset): |
| 194 | + dt = datetime(2020, 1, 1) |
| 195 | + result = await conn.fetchval( |
| 196 | + sa.func.toTimeZone(sa.func.toDateTime(dt), tz_name).select() |
| 197 | + ) |
| 198 | + assert result.utcoffset().total_seconds() == tz_offset |
| 199 | + assert result.astimezone(timezone.utc).replace(tzinfo=None) == dt |
| 200 | + |
| 201 | + |
185 | 202 | @pytest.fixture |
186 | 203 | async def conn_utc(dsn): |
187 | 204 | types = TypeRegistry() |
@@ -246,6 +263,19 @@ async def test_datetime_utc_insert_naive(conn_utc, table_for_type): |
246 | 263 | ) |
247 | 264 |
|
248 | 265 |
|
| 266 | +@pytest.mark.parametrize('tz_name,tz_offset', [ |
| 267 | + ('UTC', 0), |
| 268 | + ('EST', -18_000), |
| 269 | + ('Europe/Moscow', 10_800), |
| 270 | +]) |
| 271 | +async def test_timezones_with_utc(conn_utc, tz_name, tz_offset): |
| 272 | + dt = datetime(2020, 1, 1, tzinfo=timezone.utc) |
| 273 | + result = await conn_utc.fetchval( |
| 274 | + sa.func.toTimeZone(sa.func.toDateTime(dt, 'UTC'), tz_name).select() |
| 275 | + ) |
| 276 | + assert result == dt |
| 277 | + |
| 278 | + |
249 | 279 | @pytest.mark.parametrize('value', [0, 4294967295]) |
250 | 280 | async def test_simple_aggregate_function(conn, recreate_table_for_type, value): |
251 | 281 | table_name = await recreate_table_for_type( |
|
0 commit comments