|
40 | 40 | import time |
41 | 41 | import traceback |
42 | 42 | import typing as t |
| 43 | +from datetime import datetime |
43 | 44 | from functools import cached_property |
44 | 45 | from io import StringIO |
45 | 46 | from itertools import chain |
46 | 47 | from pathlib import Path |
47 | 48 | from shutil import rmtree |
48 | 49 | from types import MappingProxyType |
49 | | -from datetime import datetime |
50 | 50 |
|
51 | 51 | from sqlglot import Dialect, exp |
52 | 52 | from sqlglot.helper import first |
|
63 | 63 | ) |
64 | 64 | from sqlmesh.core.config.connection import ConnectionConfig |
65 | 65 | from sqlmesh.core.config.loader import C |
| 66 | +from sqlmesh.core.config.model import ModelDefaultsConfig |
66 | 67 | from sqlmesh.core.config.root import RegexKeyDict |
67 | 68 | from sqlmesh.core.console import get_console |
68 | 69 | from sqlmesh.core.context_diff import ContextDiff |
|
76 | 77 | ) |
77 | 78 | from sqlmesh.core.engine_adapter import EngineAdapter |
78 | 79 | from sqlmesh.core.environment import Environment, EnvironmentNamingInfo, EnvironmentStatements |
79 | | -from sqlmesh.core.loader import Loader |
80 | 80 | from sqlmesh.core.linter.definition import AnnotatedRuleViolation, Linter |
81 | 81 | from sqlmesh.core.linter.rules import BUILTIN_RULES |
| 82 | +from sqlmesh.core.loader import Loader |
82 | 83 | from sqlmesh.core.macros import ExecutableOrMacro, macro |
83 | 84 | from sqlmesh.core.metric import Metric, rewrite |
84 | 85 | from sqlmesh.core.model import Model, update_model_schemas |
85 | | -from sqlmesh.core.config.model import ModelDefaultsConfig |
86 | 86 | from sqlmesh.core.notification_target import ( |
87 | 87 | NotificationEvent, |
88 | 88 | NotificationTarget, |
89 | 89 | NotificationTargetManager, |
90 | 90 | ) |
91 | | -from sqlmesh.core.plan import Plan, PlanBuilder, SnapshotIntervals, PlanExplainer |
| 91 | +from sqlmesh.core.plan import Plan, PlanBuilder, PlanExplainer, SnapshotIntervals |
92 | 92 | from sqlmesh.core.plan.definition import UserProvidedFlags |
93 | 93 | from sqlmesh.core.reference import ReferenceGraph |
94 | | -from sqlmesh.core.scheduler import Scheduler, CompletionStatus |
| 94 | +from sqlmesh.core.scheduler import CompletionStatus, Scheduler |
95 | 95 | from sqlmesh.core.schema_loader import create_external_models_file |
96 | | -from sqlmesh.core.selector import Selector, NativeSelector |
| 96 | +from sqlmesh.core.selector import NativeSelector, Selector |
97 | 97 | from sqlmesh.core.snapshot import ( |
98 | 98 | DeployabilityIndex, |
99 | 99 | Snapshot, |
|
111 | 111 | ) |
112 | 112 | from sqlmesh.core.table_diff import TableDiff |
113 | 113 | from sqlmesh.core.test import ( |
114 | | - ModelTextTestResult, |
115 | 114 | ModelTestMetadata, |
| 115 | + ModelTextTestResult, |
116 | 116 | generate_test, |
117 | 117 | run_tests, |
118 | 118 | ) |
119 | 119 | from sqlmesh.core.user import User |
120 | 120 | from sqlmesh.utils import UniqueKeyDict, Verbosity |
121 | 121 | from sqlmesh.utils.concurrency import concurrent_apply_to_values |
| 122 | +from sqlmesh.utils.config import print_config |
122 | 123 | from sqlmesh.utils.dag import DAG |
123 | 124 | from sqlmesh.utils.date import ( |
124 | 125 | TimeLike, |
125 | | - to_timestamp, |
126 | 126 | format_tz_datetime, |
127 | | - now_timestamp, |
| 127 | + make_exclusive, |
128 | 128 | now, |
| 129 | + now_timestamp, |
129 | 130 | to_datetime, |
130 | | - make_exclusive, |
| 131 | + to_timestamp, |
131 | 132 | ) |
132 | 133 | from sqlmesh.utils.errors import ( |
133 | 134 | CircuitBreakerError, |
134 | 135 | ConfigError, |
| 136 | + LinterError, |
135 | 137 | PlanError, |
136 | 138 | SQLMeshError, |
137 | 139 | UncategorizedPlanError, |
138 | | - LinterError, |
139 | 140 | ) |
140 | | -from sqlmesh.utils.config import print_config |
141 | 141 | from sqlmesh.utils.jinja import JinjaMacroRegistry |
142 | 142 |
|
143 | 143 | if t.TYPE_CHECKING: |
144 | 144 | import pandas as pd |
145 | 145 | from typing_extensions import Literal |
146 | 146 |
|
147 | 147 | from sqlmesh.core.engine_adapter._typing import ( |
148 | | - BigframeSession, |
149 | 148 | DF, |
| 149 | + BigframeSession, |
150 | 150 | PySparkDataFrame, |
151 | 151 | PySparkSession, |
152 | 152 | SnowparkSession, |
@@ -389,6 +389,7 @@ def __init__( |
389 | 389 | self._standalone_audits: UniqueKeyDict[str, StandaloneAudit] = UniqueKeyDict( |
390 | 390 | "standaloneaudits" |
391 | 391 | ) |
| 392 | + self._models_with_tests: t.Set[str] = set() |
392 | 393 | self._macros: UniqueKeyDict[str, ExecutableOrMacro] = UniqueKeyDict("macros") |
393 | 394 | self._metrics: UniqueKeyDict[str, Metric] = UniqueKeyDict("metrics") |
394 | 395 | self._jinja_macros = JinjaMacroRegistry() |
@@ -638,6 +639,7 @@ def load(self, update_schemas: bool = True) -> GenericContext[C]: |
638 | 639 | self._requirements.update(project.requirements) |
639 | 640 | self._excluded_requirements.update(project.excluded_requirements) |
640 | 641 | self._environment_statements.extend(project.environment_statements) |
| 642 | + self._models_with_tests.update(project.models_with_tests) |
641 | 643 |
|
642 | 644 | config = loader.config |
643 | 645 | self._linters[config.project] = Linter.from_rules( |
@@ -1040,6 +1042,11 @@ def standalone_audits(self) -> MappingProxyType[str, StandaloneAudit]: |
1040 | 1042 | """Returns all registered standalone audits in this context.""" |
1041 | 1043 | return MappingProxyType(self._standalone_audits) |
1042 | 1044 |
|
| 1045 | + @property |
| 1046 | + def models_with_tests(self) -> t.Set[str]: |
| 1047 | + """Returns all models with tests in this context.""" |
| 1048 | + return self._models_with_tests |
| 1049 | + |
1043 | 1050 | @property |
1044 | 1051 | def snapshots(self) -> t.Dict[str, Snapshot]: |
1045 | 1052 | """Generates and returns snapshots based on models registered in this context. |
|
0 commit comments