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

Fix test deprecation warnings #4556

Merged
merged 1 commit into from
Jan 12, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

### Under the hood
- Testing cleanup ([#4496](https://github.com/dbt-labs/dbt-core/pull/4496), [#4509](https://github.com/dbt-labs/dbt-core/pull/4509))
- Clean up test deprecation warnings ([#3988](https://github.com/dbt-labs/dbt-core/issue/3988), [#4556](https://github.com/dbt-labs/dbt-core/pull/4556))

## dbt-core 1.0.1 (January 03, 2022)

Expand Down
4 changes: 3 additions & 1 deletion core/dbt/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import List, Dict, Any, Tuple, cast, Optional

import networkx as nx # type: ignore
import pickle
import sqlparse

from dbt import flags
Expand Down Expand Up @@ -162,7 +163,8 @@ def write_graph(self, outfile: str, manifest: Manifest):
for node_id in self.graph:
data = manifest.expect(node_id).to_dict(omit_none=True)
out_graph.add_node(node_id, **data)
nx.write_gpickle(out_graph, outfile)
with open(outfile, 'wb') as outfh:
pickle.dump(out_graph, outfh, protocol=pickle.HIGHEST_PROTOCOL)


class Compiler:
Expand Down
12 changes: 7 additions & 5 deletions core/dbt/graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ def ancestors(
"""Returns all nodes having a path to `node` in `graph`"""
if not self.graph.has_node(node):
raise InternalException(f'Node {node} not found in the graph!')
with nx.utils.reversed(self.graph):
anc = nx.single_source_shortest_path_length(G=self.graph,
source=node,
cutoff=max_depth)\
.keys()
# This used to use nx.utils.reversed(self.graph), but that is deprecated,
# so changing to use self.graph.reverse(copy=False) as recommeneded
G = self.graph.reverse(copy=False) if self.graph.is_directed() else self.graph
anc = nx.single_source_shortest_path_length(G=G,
source=node,
cutoff=max_depth)\
.keys()
return anc - {node}

def descendants(
Expand Down
12 changes: 8 additions & 4 deletions core/dbt/semver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from dataclasses import dataclass
import re
import warnings
from typing import List

from packaging import version as packaging_version
Expand Down Expand Up @@ -145,10 +146,13 @@ def compare(self, other):
return 1
if b is None:
return -1
if packaging_version.parse(a) > packaging_version.parse(b):
return 1
elif packaging_version.parse(a) < packaging_version.parse(b):
return -1
# This suppresses the LegacyVersion deprecation warning
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=DeprecationWarning)
if packaging_version.parse(a) > packaging_version.parse(b):
return 1
elif packaging_version.parse(a) < packaging_version.parse(b):
return -1

equal = ((self.matcher == Matchers.GREATER_THAN_OR_EQUAL and
other.matcher == Matchers.LESS_THAN_OR_EQUAL) or
Expand Down
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
filterwarnings =
ignore:.*'soft_unicode' has been renamed to 'soft_str'*:DeprecationWarning
13 changes: 4 additions & 9 deletions test/unit/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
class GraphTest(unittest.TestCase):

def tearDown(self):
self.write_gpickle_patcher.stop()
self.mock_filesystem_search.stop()
self.mock_hook_constructor.stop()
self.load_state_check.stop()
Expand Down Expand Up @@ -58,13 +57,6 @@ def setUp(self):
{n.unique_id: n for n in generate_name_macros('test_models_compile')})
self.mock_models = [] # used by filesystem_searcher

# Create gpickle patcher
self.write_gpickle_patcher = patch('networkx.write_gpickle')
def mock_write_gpickle(graph, outfile):
self.graph_result = graph
self.mock_write_gpickle = self.write_gpickle_patcher.start()
self.mock_write_gpickle.side_effect = mock_write_gpickle

# Create file filesystem searcher
self.filesystem_search = patch('dbt.parser.read_files.filesystem_search')
def mock_filesystem_search(project, relative_dirs, extension):
Expand Down Expand Up @@ -139,7 +131,10 @@ def get_config(self, extra_cfg=None):
}
cfg.update(extra_cfg)

return config_from_parts_or_dicts(project=cfg, profile=self.profile)
config = config_from_parts_or_dicts(project=cfg, profile=self.profile)
dbt.flags.set_from_args({}, config)
dbt.flags.PARTIAL_PARSE = False
return config

def get_compiler(self, project):
return dbt.compilation.Compiler(project)
Expand Down