From 05c46ac974a5cf984747285b18adee970716ad34 Mon Sep 17 00:00:00 2001 From: Jochem van Dooren Date: Thu, 21 Mar 2024 11:42:40 +0100 Subject: [PATCH] Clean up conftest and add json resource --- tests/conftest.py | 104 +++------------------------------- tests/resources/manifest.json | 88 ++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 95 deletions(-) create mode 100644 tests/resources/manifest.json diff --git a/tests/conftest.py b/tests/conftest.py index 77c61bd..5534cba 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,7 @@ """Test configuration.""" + +import json +from pathlib import Path from typing import Any, Type from dbt_score.models import Model @@ -13,84 +16,13 @@ def pytest_sessionfinish(session: Session, exitstatus: int): @fixture -def raw_manifest() -> dict[str, Any]: +def raw_manifest() -> Any: """Mock the raw manifest.""" - return { - "nodes": { - "analysis.package.analysis1": {"resource_type": "analysis"}, - "model.package.model1": { - "resource_type": "model", - "unique_id": "model.package.model1", - "name": "model1", - "relation_name": "database.schema.model1", - "description": "Description1.", - "original_file_path": "/path/to/model1.sql", - "config": {}, - "meta": {}, - "columns": { - "a": { - "name": "column_a", - "description": "Column A.", - "data_type": "string", - "meta": {}, - "constraints": [], - "tags": [], - } - }, - "package_name": "package", - "database": "db", - "schema": "schema", - "raw_code": "SELECT x FROM y", - "alias": "model1_alias", - "patch_path": "/path/to/model1.yml", - "tags": [], - "depends_on": {}, - }, - "model.package.model2": { - "resource_type": "model", - "unique_id": "model.package.model2", - "name": "model2", - "relation_name": "database.schema.model2", - "description": "Description2.", - "original_file_path": "/path/to/model2.sql", - "config": {}, - "meta": {}, - "columns": { - "a": { - "name": "column_a", - "description": "Column A.", - "data_type": "string", - "meta": {}, - "constraints": [], - "tags": [], - } - }, - "package_name": "package", - "database": "db", - "schema": "schema", - "raw_code": "SELECT x FROM y", - "alias": "model2_alias", - "patch_path": "/path/to/model2.yml", - "tags": [], - "depends_on": {}, - }, - "test.package.test1": { - "resource_type": "test", - "attached_node": "model.package.model1", - "name": "test1", - "test_metadata": {"name": "type", "kwargs": {"column_name": "a"}}, - "tags": [], - }, - "test.package.test2": { - "resource_type": "test", - "attached_node": "model.package.model1", - "name": "test2", - "test_metadata": {"name": "type", "kwargs": {}}, - "tags": [], - }, - "test.package.test3": {"resource_type": "test"}, - } - } + return json.loads( + Path(__file__) + .parent.joinpath("resources/manifest.json") + .read_text(encoding="utf-8") + ) @fixture @@ -135,21 +67,3 @@ def evaluate(self, model: Model) -> RuleViolation | None: return None return ExampleRule - - -@fixture -def invalid_class_rule() -> Type[Rule]: - """An example rule created with a class.""" - - class ExampleRule(Rule): - """Example rule.""" - - description = "Description of the rule." - - def evaluate(self, model: Model) -> RuleViolation | None: - """Evaluate model.""" - if model.name == "model1": - return RuleViolation(message="Model1 is a violation.") - return None - - return ExampleRule diff --git a/tests/resources/manifest.json b/tests/resources/manifest.json new file mode 100644 index 0000000..0385938 --- /dev/null +++ b/tests/resources/manifest.json @@ -0,0 +1,88 @@ +{ + "nodes": { + "analysis.package.analysis1": { + "resource_type": "analysis" + }, + "model.package.model1": { + "resource_type": "model", + "unique_id": "model.package.model1", + "name": "model1", + "relation_name": "database.schema.model1", + "description": "Description1.", + "original_file_path": "/path/to/model1.sql", + "config": {}, + "meta": {}, + "columns": { + "a": { + "name": "column_a", + "description": "Column A.", + "data_type": "string", + "meta": {}, + "constraints": [], + "tags": [] + } + }, + "package_name": "package", + "database": "db", + "schema": "schema", + "raw_code": "SELECT x FROM y", + "alias": "model1_alias", + "patch_path": "/path/to/model1.yml", + "tags": [], + "depends_on": {} + }, + "model.package.model2": { + "resource_type": "model", + "unique_id": "model.package.model2", + "name": "model2", + "relation_name": "database.schema.model2", + "description": "Description2.", + "original_file_path": "/path/to/model2.sql", + "config": {}, + "meta": {}, + "columns": { + "a": { + "name": "column_a", + "description": "Column A.", + "data_type": "string", + "meta": {}, + "constraints": [], + "tags": [] + } + }, + "package_name": "package", + "database": "db", + "schema": "schema", + "raw_code": "SELECT x FROM y", + "alias": "model2_alias", + "patch_path": "/path/to/model2.yml", + "tags": [], + "depends_on": {} + }, + "test.package.test1": { + "resource_type": "test", + "attached_node": "model.package.model1", + "name": "test1", + "test_metadata": { + "name": "type", + "kwargs": { + "column_name": "a" + } + }, + "tags": [] + }, + "test.package.test2": { + "resource_type": "test", + "attached_node": "model.package.model1", + "name": "test2", + "test_metadata": { + "name": "type", + "kwargs": {} + }, + "tags": [] + }, + "test.package.test3": { + "resource_type": "test" + } + } +} \ No newline at end of file