Skip to content
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

[Tidy first] Fix three unit tests without set_args, fix mock in test_graph.py #9897

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/unit/test_docs_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

from .utils import config_from_parts_or_dicts

from dbt.flags import set_from_args
from argparse import Namespace

set_from_args(Namespace(WARN_ERROR=False), None)

SNOWPLOW_SESSIONS_DOCS = r"""
This table contains one record for every session recorded by Snowplow.
Expand Down
27 changes: 14 additions & 13 deletions tests/unit/test_graph.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os

from argparse import Namespace
import unittest
from unittest.mock import MagicMock, patch

Expand All @@ -23,11 +22,15 @@
from queue import Empty
from .utils import config_from_parts_or_dicts, generate_name_macros, inject_plugin

from dbt.flags import set_from_args
from argparse import Namespace

set_from_args(Namespace(WARN_ERROR=False), None)


class GraphTest(unittest.TestCase):
def tearDown(self):
self.mock_filesystem_search.stop()
self.mock_hook_constructor.stop()
self.load_state_check.stop()
self.load_source_file_patcher.stop()
reset_adapters()
Expand Down Expand Up @@ -69,17 +72,6 @@ def mock_filesystem_search(project, relative_dirs, extension, ignore_spec):
self.mock_filesystem_search = self.filesystem_search.start()
self.mock_filesystem_search.side_effect = mock_filesystem_search

# Create HookParser patcher
self.hook_patcher = patch.object(dbt.parser.hooks.HookParser, "__new__")

def create_hook_patcher(cls, project, manifest, root_project):
result = MagicMock(project=project, manifest=manifest, root_project=root_project)
result.__iter__.side_effect = lambda: iter([])
return result

self.mock_hook_constructor = self.hook_patcher.start()
self.mock_hook_constructor.side_effect = create_hook_patcher

# Create the Manifest.state_check patcher
@patch("dbt.parser.manifest.ManifestLoader.build_manifest_state_check")
def _mock_state_check(self):
Expand Down Expand Up @@ -112,6 +104,15 @@ def mock_load_source_file(path, parse_file_type, project_name, saved_files):

self.mock_source_file.side_effect = mock_load_source_file

# Create hookparser source file patcher
self.load_source_file_manifest_patcher = patch("dbt.parser.manifest.load_source_file")
self.mock_source_file_manifest = self.load_source_file_manifest_patcher.start()

def mock_load_source_file_manifest(path, parse_file_type, project_name, saved_files):
return []

self.mock_source_file_manifest.side_effect = mock_load_source_file_manifest

def get_config(self, extra_cfg=None):
if extra_cfg is None:
extra_cfg = {}
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_linker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
from dbt.graph.cli import parse_difference
from queue import Empty

from dbt.flags import set_from_args
from argparse import Namespace

set_from_args(Namespace(WARN_ERROR=False), None)


def _mock_manifest(nodes):
config = mock.MagicMock(enabled=True)
Expand Down