Skip to content

Commit

Permalink
Fix test deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed Jan 6, 2022
1 parent e943b9f commit 248b165
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
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

0 comments on commit 248b165

Please sign in to comment.