|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | +"""Pin the harness guarantee behind ``_preload_clock_reading_drivers``. |
| 18 | +
|
| 19 | +``clickhouse_connect`` reads the local timezone at import time and fails |
| 20 | +under a ``freeze_time`` clock, so the unit-test session imports it before any |
| 21 | +test runs. A test can therefore resolve the ClickHouse engine spec under a |
| 22 | +frozen clock on any worker, regardless of what ran before it. This test |
| 23 | +asserts that guarantee directly; if the preload fixture is removed, it fails |
| 24 | +on any worker where nothing else happened to import the driver first. |
| 25 | +""" |
| 26 | + |
| 27 | +import importlib.util |
| 28 | +import sys |
| 29 | + |
| 30 | +import pytest |
| 31 | +from freezegun import freeze_time |
| 32 | + |
| 33 | + |
| 34 | +@pytest.mark.skipif( |
| 35 | + importlib.util.find_spec("clickhouse_connect") is None, |
| 36 | + reason="clickhouse_connect is not installed", |
| 37 | +) |
| 38 | +def test_clock_reading_driver_is_preloaded_before_tests() -> None: |
| 39 | + """Verify the session fixture imports the driver before tests run.""" |
| 40 | + assert "clickhouse_connect" in sys.modules |
| 41 | + |
| 42 | + |
| 43 | +@pytest.mark.skipif( |
| 44 | + importlib.util.find_spec("clickhouse_connect") is None, |
| 45 | + reason="clickhouse_connect is not installed", |
| 46 | +) |
| 47 | +@freeze_time("2021-04-01T00:00:00Z") |
| 48 | +def test_clickhouse_engine_spec_resolves_under_frozen_clock() -> None: |
| 49 | + """Verify the ClickHouse Connect engine spec resolves under a frozen clock.""" |
| 50 | + # Defer the engine-spec package import until after the session preload; |
| 51 | + # a module-top import would execute during collection, before the fixture. |
| 52 | + from superset.db_engine_specs import get_engine_spec |
| 53 | + |
| 54 | + assert ( |
| 55 | + get_engine_spec("clickhousedb", "connect").__name__ |
| 56 | + == "ClickHouseConnectEngineSpec" |
| 57 | + ) |
0 commit comments