-
Notifications
You must be signed in to change notification settings - Fork 313
Adding in NoMissingUnitTest linter rule #5294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 9 commits
776a679
346ad72
2aabde8
04a82c2
c1d20dc
c09d2a8
795ac64
0c27875
f18f7e4
638999a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,6 +115,7 @@ | |
| ModelTestMetadata, | ||
| generate_test, | ||
| run_tests, | ||
| filter_tests_by_patterns, | ||
| ) | ||
| from sqlmesh.core.user import User | ||
| from sqlmesh.utils import UniqueKeyDict, Verbosity | ||
|
|
@@ -146,8 +147,8 @@ | |
| from typing_extensions import Literal | ||
|
|
||
| from sqlmesh.core.engine_adapter._typing import ( | ||
| BigframeSession, | ||
| DF, | ||
| BigframeSession, | ||
| PySparkDataFrame, | ||
| PySparkSession, | ||
| SnowparkSession, | ||
|
|
@@ -398,6 +399,8 @@ def __init__( | |
| self._standalone_audits: UniqueKeyDict[str, StandaloneAudit] = UniqueKeyDict( | ||
| "standaloneaudits" | ||
| ) | ||
| self._models_with_tests: t.Set[str] = set() | ||
| self._model_test_metadata: t.List[ModelTestMetadata] = [] | ||
| self._macros: UniqueKeyDict[str, ExecutableOrMacro] = UniqueKeyDict("macros") | ||
| self._metrics: UniqueKeyDict[str, Metric] = UniqueKeyDict("metrics") | ||
| self._jinja_macros = JinjaMacroRegistry() | ||
|
|
@@ -636,6 +639,8 @@ def load(self, update_schemas: bool = True) -> GenericContext[C]: | |
| self._excluded_requirements.clear() | ||
| self._linters.clear() | ||
| self._environment_statements = [] | ||
| self._models_with_tests.clear() | ||
| self._model_test_metadata.clear() | ||
|
|
||
| for loader, project in zip(self._loaders, loaded_projects): | ||
| self._jinja_macros = self._jinja_macros.merge(project.jinja_macros) | ||
|
|
@@ -647,6 +652,8 @@ def load(self, update_schemas: bool = True) -> GenericContext[C]: | |
| self._requirements.update(project.requirements) | ||
| self._excluded_requirements.update(project.excluded_requirements) | ||
| self._environment_statements.extend(project.environment_statements) | ||
| self._models_with_tests.update(project.models_with_tests) | ||
| self._model_test_metadata.extend(project.model_test_metadata) | ||
|
|
||
| config = loader.config | ||
| self._linters[config.project] = Linter.from_rules( | ||
|
|
@@ -1049,6 +1056,11 @@ def standalone_audits(self) -> MappingProxyType[str, StandaloneAudit]: | |
| """Returns all registered standalone audits in this context.""" | ||
| return MappingProxyType(self._standalone_audits) | ||
|
|
||
| @property | ||
| def models_with_tests(self) -> t.Set[str]: | ||
| """Returns all models with tests in this context.""" | ||
| return self._models_with_tests | ||
|
|
||
| @property | ||
| def snapshots(self) -> t.Dict[str, Snapshot]: | ||
| """Generates and returns snapshots based on models registered in this context. | ||
|
|
@@ -2220,7 +2232,9 @@ def test( | |
|
|
||
| pd.set_option("display.max_columns", None) | ||
|
|
||
| test_meta = self.load_model_tests(tests=tests, patterns=match_patterns) | ||
| test_meta = self._filter_preloaded_tests( | ||
| test_meta=self._model_test_metadata, tests=tests, patterns=match_patterns | ||
| ) | ||
|
|
||
| result = run_tests( | ||
| model_test_metadata=test_meta, | ||
|
|
@@ -2782,6 +2796,33 @@ def _get_engine_adapter(self, gateway: t.Optional[str] = None) -> EngineAdapter: | |
| raise SQLMeshError(f"Gateway '{gateway}' not found in the available engine adapters.") | ||
| return self.engine_adapter | ||
|
|
||
| def _filter_preloaded_tests( | ||
| self, | ||
| test_meta: t.List[ModelTestMetadata], | ||
| tests: t.Optional[t.List[str]] = None, | ||
| patterns: t.Optional[t.List[str]] = None, | ||
| ) -> t.List[ModelTestMetadata]: | ||
| """Filter pre-loaded test metadata based on tests and patterns.""" | ||
|
|
||
| if tests: | ||
| filtered_tests = [] | ||
| for test in tests: | ||
| if "::" in test: | ||
| filename, test_name = test.split("::", maxsplit=1) | ||
| test_path = Path(filename) | ||
| filtered_tests.extend( | ||
| [t for t in test_meta if t.path == test_path and t.test_name == test_name] | ||
| ) | ||
| else: | ||
| test_path = Path(test) | ||
| filtered_tests.extend([t for t in test_meta if t.path == test_path]) | ||
|
||
| test_meta = filtered_tests | ||
|
|
||
| if patterns: | ||
| test_meta = filter_tests_by_patterns(test_meta, patterns) | ||
|
|
||
| return test_meta | ||
|
|
||
| def _snapshots( | ||
| self, models_override: t.Optional[UniqueKeyDict[str, Model]] = None | ||
| ) -> t.Dict[str, Snapshot]: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.