Skip to content

Commit 906e2de

Browse files
committed
adjustments
1 parent 85c2dbf commit 906e2de

File tree

8 files changed

+53
-82
lines changed

8 files changed

+53
-82
lines changed

.circleci/continue_config.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,14 @@ workflows:
302302
matrix:
303303
parameters:
304304
engine:
305-
#- snowflake
306-
#- databricks
307-
#- redshift
308-
#- bigquery
309-
#- clickhouse-cloud
310-
#- athena
305+
- snowflake
306+
- databricks
307+
- redshift
308+
- bigquery
309+
- clickhouse-cloud
310+
- athena
311311
- fabric
312-
#- gcp-postgres
312+
- gcp-postgres
313313
#filters:
314314
# branches:
315315
# only:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ athena-test: guard-AWS_ACCESS_KEY_ID guard-AWS_SECRET_ACCESS_KEY guard-ATHENA_S3
174174
pytest -n auto -m "athena" --retries 3 --junitxml=test-results/junit-athena.xml
175175

176176
fabric-test: guard-FABRIC_HOST guard-FABRIC_CLIENT_ID guard-FABRIC_CLIENT_SECRET guard-FABRIC_DATABASE engine-fabric-install
177-
pytest -n auto -m "fabric" --retries 3 --junitxml=test-results/junit-fabric.xml
177+
pytest -n auto -m "fabric" --retries 3 --junitxml=test-results/junit-fabric.xml
178178

179179
gcp-postgres-test: guard-GCP_POSTGRES_INSTANCE_CONNECTION_STRING guard-GCP_POSTGRES_USER guard-GCP_POSTGRES_PASSWORD guard-GCP_POSTGRES_KEYFILE_JSON engine-gcppostgres-install
180180
pytest -n auto -m "gcp_postgres" --retries 3 --junitxml=test-results/junit-gcp-postgres.xml

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ markers = [
259259
"mssql: test for MSSQL",
260260
"mysql: test for MySQL",
261261
"postgres: test for Postgres",
262+
"gcp_postgres: test for Postgres on GCP",
262263
"redshift: test for Redshift",
263264
"snowflake: test for Snowflake",
264265
"spark: test for Spark",
@@ -267,7 +268,7 @@ markers = [
267268
]
268269
addopts = "-n 0 --dist=loadgroup"
269270
asyncio_default_fixture_loop_scope = "session"
270-
log_cli = false # Set this to true to enable logging during tests
271+
log_cli = true # Set this to true to enable logging during tests
271272
log_cli_format = "%(asctime)s.%(msecs)03d %(filename)s:%(lineno)d %(levelname)s %(message)s"
272273
log_cli_level = "INFO"
273274
filterwarnings = [

sqlmesh/core/config/loader.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def load_config_from_paths(
8383
personal_paths: t.Optional[t.List[Path]] = None,
8484
config_name: str = "config",
8585
load_from_env: bool = True,
86+
variables: t.Optional[t.Dict[str, t.Any]] = None,
8687
**kwargs: t.Any,
8788
) -> C:
8889
project_paths = project_paths or []
@@ -116,7 +117,7 @@ def load_config_from_paths(
116117
"YAML configs do not support multiple configs. Use Python instead.",
117118
)
118119
yaml_config_path = path.resolve()
119-
non_python_configs.append(load_config_from_yaml(path))
120+
non_python_configs.append(load_config_from_yaml(path, variables))
120121
elif extension == "py":
121122
try:
122123
python_config = load_config_from_python_module(
@@ -194,8 +195,10 @@ def load_config_from_paths(
194195
return non_python_config
195196

196197

197-
def load_config_from_yaml(path: Path) -> t.Dict[str, t.Any]:
198-
content = yaml_load(path)
198+
def load_config_from_yaml(
199+
path: Path, variables: t.Optional[t.Dict[str, t.Any]] = None
200+
) -> t.Dict[str, t.Any]:
201+
content = yaml_load(path, variables=variables)
199202
if not isinstance(content, dict):
200203
raise ConfigError(
201204
f"Invalid YAML configuration: expected a dictionary but got {type(content).__name__}. "

tests/core/engine_adapter/integration/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ def __init__(
193193
engine_adapter: EngineAdapter,
194194
mark: str,
195195
gateway: str,
196+
tmp_path: pathlib.Path,
196197
is_remote: bool = False,
197198
columns_to_types: t.Optional[t.Dict[str, t.Union[str, exp.DataType]]] = None,
198199
):
@@ -210,6 +211,7 @@ def __init__(
210211
self._catalogs: t.List[
211212
str
212213
] = [] # keep track of any catalogs created via self.create_catalog() so we can drop them at the end
214+
self.tmp_path = tmp_path
213215

214216
@property
215217
def test_type(self) -> str:
@@ -655,6 +657,7 @@ def create_context(
655657
private_sqlmesh_dir / "config.yml",
656658
private_sqlmesh_dir / "config.yaml",
657659
],
660+
variables={"tmp_path": str(path or self.tmp_path)},
658661
)
659662
if config_mutator:
660663
config_mutator(self.gateway, config)

tests/core/engine_adapter/integration/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ gateways:
55
type: duckdb
66
catalogs:
77
memory: ':memory:'
8-
testing: 'testing.duckdb'
8+
testing: "{{ var('tmp_path') }}/testing.duckdb"
99

1010
# Databases with docker images available
1111
inttest_trino_hive:

tests/core/engine_adapter/integration/conftest.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
logger = logging.getLogger(__name__)
2828

2929

30-
@pytest.fixture(scope="session")
31-
def config() -> Config:
30+
@pytest.fixture
31+
def config(tmp_path: pathlib.Path) -> Config:
3232
return load_config_from_paths(
3333
Config,
3434
project_paths=[
35-
pathlib.Path("examples/wursthall/config.yaml"),
3635
pathlib.Path(os.path.join(os.path.dirname(__file__), "config.yaml")),
3736
],
3837
personal_paths=[pathlib.Path("~/.sqlmesh/config.yaml").expanduser()],
38+
variables={"tmp_path": str(tmp_path)},
3939
)
4040

4141

@@ -89,7 +89,9 @@ def _create(engine_name: str, gateway: str) -> EngineAdapter:
8989

9090
@pytest.fixture
9191
def create_test_context(
92-
request: FixtureRequest, create_engine_adapter: t.Callable[[str, str], EngineAdapter]
92+
request: FixtureRequest,
93+
create_engine_adapter: t.Callable[[str, str], EngineAdapter],
94+
tmp_path: pathlib.Path,
9395
) -> t.Callable[[IntegrationTestEngine, str, str, str], t.Iterable[TestContext]]:
9496
def _create(
9597
engine: IntegrationTestEngine, gateway: str, test_type: str, table_format: str
@@ -103,6 +105,7 @@ def _create(
103105
engine_adapter,
104106
f"{engine.engine}_{table_format}",
105107
gateway,
108+
tmp_path=tmp_path,
106109
is_remote=is_remote,
107110
)
108111

tests/core/engine_adapter/integration/test_integration.py

Lines changed: 26 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# type: ignore
22
from __future__ import annotations
33

4-
import os
54
import pathlib
65
import re
76
import sys
@@ -19,7 +18,6 @@
1918

2019
from sqlmesh import Config, Context
2120
from sqlmesh.cli.project_init import init_example_project
22-
from sqlmesh.core.config import load_config_from_paths
2321
from sqlmesh.core.config.connection import ConnectionConfig
2422
import sqlmesh.core.dialect as d
2523
from sqlmesh.core.environment import EnvironmentSuffixTarget
@@ -1936,49 +1934,16 @@ def test_transaction(ctx: TestContext):
19361934
ctx.compare_with_current(table, input_data)
19371935

19381936

1939-
def test_sushi(ctx: TestContext, tmp_path_factory: pytest.TempPathFactory):
1937+
def test_sushi(ctx: TestContext, tmp_path: pathlib.Path):
19401938
if ctx.mark == "athena_hive":
19411939
pytest.skip(
19421940
"Sushi end-to-end tests only need to run once for Athena because sushi needs a hybrid of both Hive and Iceberg"
19431941
)
19441942

1945-
tmp_path = tmp_path_factory.mktemp(f"sushi_{ctx.test_id}")
1946-
19471943
sushi_test_schema = ctx.add_test_suffix("sushi")
19481944
sushi_state_schema = ctx.add_test_suffix("sushi_state")
19491945
raw_test_schema = ctx.add_test_suffix("raw")
19501946

1951-
config = load_config_from_paths(
1952-
Config,
1953-
project_paths=[
1954-
pathlib.Path(os.path.join(os.path.dirname(__file__), "config.yaml")),
1955-
],
1956-
personal_paths=[pathlib.Path("~/.sqlmesh/config.yaml").expanduser()],
1957-
)
1958-
before_all = [
1959-
f"CREATE SCHEMA IF NOT EXISTS {raw_test_schema}",
1960-
f"DROP VIEW IF EXISTS {raw_test_schema}.demographics",
1961-
f"CREATE VIEW {raw_test_schema}.demographics AS (SELECT 1 AS customer_id, '00000' AS zip)",
1962-
]
1963-
config.before_all = [
1964-
quote_identifiers(
1965-
parse_one(e, dialect=config.model_defaults.dialect),
1966-
dialect=config.model_defaults.dialect,
1967-
).sql(dialect=config.model_defaults.dialect)
1968-
for e in before_all
1969-
]
1970-
1971-
# To enable parallelism in integration tests
1972-
config.gateways = {ctx.gateway: config.gateways[ctx.gateway]}
1973-
current_gateway_config = config.gateways[ctx.gateway]
1974-
current_gateway_config.state_schema = sushi_state_schema
1975-
1976-
if ctx.dialect == "athena":
1977-
# Ensure that this test is using the same s3_warehouse_location as TestContext (which includes the testrun_id)
1978-
current_gateway_config.connection.s3_warehouse_location = (
1979-
ctx.engine_adapter.s3_warehouse_location
1980-
)
1981-
19821947
# Copy sushi example to tmpdir
19831948
shutil.copytree(pathlib.Path("./examples/sushi"), tmp_path, dirs_exist_ok=True)
19841949

@@ -2000,7 +1965,23 @@ def test_sushi(ctx: TestContext, tmp_path_factory: pytest.TempPathFactory):
20001965
contents = contents.replace(search, replace)
20011966
f.write_text(contents)
20021967

2003-
context = Context(paths=tmp_path, config=config, gateway=ctx.gateway)
1968+
before_all = [
1969+
f"CREATE SCHEMA IF NOT EXISTS {raw_test_schema}",
1970+
f"DROP VIEW IF EXISTS {raw_test_schema}.demographics",
1971+
f"CREATE VIEW {raw_test_schema}.demographics AS (SELECT 1 AS customer_id, '00000' AS zip)",
1972+
]
1973+
1974+
def _mutate_config(gateway: str, config: Config) -> None:
1975+
config.gateways[gateway].state_schema = sushi_state_schema
1976+
config.before_all = [
1977+
quote_identifiers(
1978+
parse_one(e, dialect=config.model_defaults.dialect),
1979+
dialect=config.model_defaults.dialect,
1980+
).sql(dialect=config.model_defaults.dialect)
1981+
for e in before_all
1982+
]
1983+
1984+
context = ctx.create_context(_mutate_config, path=tmp_path, ephemeral_state_connection=False)
20041985

20051986
end = now()
20061987
start = to_date(end - timedelta(days=7))
@@ -2355,9 +2336,7 @@ def validate_no_comments(
23552336
ctx._schemas.append(schema)
23562337

23572338

2358-
def test_init_project(ctx: TestContext, tmp_path_factory: pytest.TempPathFactory):
2359-
tmp_path = tmp_path_factory.mktemp(f"init_project_{ctx.test_id}")
2360-
2339+
def test_init_project(ctx: TestContext, tmp_path: pathlib.Path):
23612340
schema_name = ctx.add_test_suffix(TEST_SCHEMA)
23622341
state_schema = ctx.add_test_suffix("sqlmesh_state")
23632342

@@ -2383,33 +2362,15 @@ def _normalize_snowflake(name: str, prefix_regex: str = "(sqlmesh__)(.*)"):
23832362

23842363
init_example_project(tmp_path, ctx.engine_type, schema_name=schema_name)
23852364

2386-
config = load_config_from_paths(
2387-
Config,
2388-
project_paths=[
2389-
pathlib.Path(os.path.join(os.path.dirname(__file__), "config.yaml")),
2390-
],
2391-
personal_paths=[pathlib.Path("~/.sqlmesh/config.yaml").expanduser()],
2392-
)
2393-
2394-
# ensure default dialect comes from init_example_project and not ~/.sqlmesh/config.yaml
2395-
if config.model_defaults.dialect != ctx.dialect:
2396-
config.model_defaults = config.model_defaults.copy(update={"dialect": ctx.dialect})
2397-
2398-
# To enable parallelism in integration tests
2399-
config.gateways = {ctx.gateway: config.gateways[ctx.gateway]}
2400-
current_gateway_config = config.gateways[ctx.gateway]
2401-
2402-
if ctx.dialect == "athena":
2403-
# Ensure that this test is using the same s3_warehouse_location as TestContext (which includes the testrun_id)
2404-
current_gateway_config.connection.s3_warehouse_location = (
2405-
ctx.engine_adapter.s3_warehouse_location
2406-
)
2365+
def _mutate_config(gateway: str, config: Config):
2366+
# ensure default dialect comes from init_example_project and not ~/.sqlmesh/config.yaml
2367+
if config.model_defaults.dialect != ctx.dialect:
2368+
config.model_defaults = config.model_defaults.copy(update={"dialect": ctx.dialect})
24072369

2408-
# Ensure the state schema is unique to this test
2409-
config.gateways[ctx.gateway].state_schema = state_schema
2370+
# Ensure the state schema is unique to this test (since we deliberately use the warehouse as the state connection)
2371+
config.gateways[gateway].state_schema = state_schema
24102372

2411-
context = Context(paths=tmp_path, config=config, gateway=ctx.gateway)
2412-
ctx.engine_adapter = context.engine_adapter
2373+
context = ctx.create_context(_mutate_config, path=tmp_path, ephemeral_state_connection=False)
24132374

24142375
if ctx.default_table_format:
24152376
# if the default table format is explicitly set, ensure its being used

0 commit comments

Comments
 (0)