Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
bump to v0.4.0 for dbt v0.19.0 artifact changes, not compatible with …
Browse files Browse the repository at this point in the history
…<0.19.0
  • Loading branch information
Kyle Wigley committed Jan 7, 2021
1 parent cc9251e commit a411336
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 56 deletions.
18 changes: 9 additions & 9 deletions pytest_dbt_adapter/sequences/data_test.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: data_test
project: data_tests
sequence:
- type: dbt
cmd: test
check: false
- type: run_results
length: fact.test.length
names: fact.test.names
attributes:
passing.status: pass
failing.status: fail
- type: dbt
cmd: test
check: false
- type: run_results
length: fact.test.length
names: fact.test.names
attributes:
passing.status: pass
failing.status: fail
36 changes: 18 additions & 18 deletions pytest_dbt_adapter/sequences/data_test_ephemeral_models.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
name: data_test_ephemeral_models
project: data_test_ephemeral_models
sequence:
- type: dbt
cmd: seed
- type: run_results
length: fact.seed.length
- type: dbt
cmd: test
check: false
- type: run_results
length: fact.test.length
names: fact.test.names
attributes:
passing.status: pass
failing.status: fail
- type: dbt
cmd: run
- type: run_results
length: fact.run.length
names: fact.run.names
- type: dbt
cmd: seed
- type: run_results
length: fact.seed.length
- type: dbt
cmd: test
check: false
- type: run_results
length: fact.test.length
names: fact.test.names
attributes:
passing.status: pass
failing.status: fail
- type: dbt
cmd: run
- type: run_results
length: fact.run.length
names: fact.run.names
67 changes: 40 additions & 27 deletions pytest_dbt_adapter/spec_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,27 +273,45 @@ def _build_expected_attributes_dict(

@staticmethod
def _get_name(
unique_id: str
result: Dict[str, Any],
nodes: Dict[str, Any]
) -> str:
""" turn a unique_id into just a node name. """
# The last part of the unique_id is the name
# Example:
# Consider unique_id "test.dbt_test_project.failing"
# Then the name is "failing"
return unique_id.split(".")[-1]
"""Given a run result get the unique_id and lookup the name from
a dict of nodes mapped to their unique_id.
"""
try:
unique_id = result['unique_id']
except KeyError as exc:
raise DBTException(
f'Invalid result, missing required key {exc}'
) from None
try:
return nodes[unique_id]['name']
except KeyError as exc:
raise DBTException(
f'Invalid node, missing required key {exc}'
) from None

def step_run_results(self, sequence_item, tmpdir):
path = os.path.join(tmpdir, 'project', 'target', 'run_results.json')
run_results_path = os.path.join(
tmpdir, 'project', 'target', 'run_results.json')
manifest_path = os.path.join(
tmpdir, 'project', 'target', 'manifest.json')

expect_exists = sequence_item.get('exists', True)

assert expect_exists == os.path.exists(path)
assert expect_exists == os.path.exists(run_results_path)
if not expect_exists:
return None

try:
with open(path) as fp:
run_results_data = json.load(fp)
with open(
run_results_path
) as results_fp, open(
manifest_path
) as manifest_fp:
run_results_data = json.load(results_fp)
manifest_data = json.load(manifest_fp)
except Exception as exc:
raise DBTException(
f'could not load run_results.json: {exc}'
Expand All @@ -304,6 +322,13 @@ def step_run_results(self, sequence_item, tmpdir):
raise DBTException(
'Invalid run_results.json - no results'
) from None
try:
nodes = manifest_data['nodes']
except KeyError:
raise DBTException(
'Invalid manifest.json - no nodes'
) from None

if 'length' in sequence_item:
expected = self.get_fact(sequence_item['length'])
assert expected == len(results)
Expand All @@ -312,13 +337,7 @@ def step_run_results(self, sequence_item, tmpdir):
extra_results_ok = sequence_item.get('extra_results_ok', False)

for result in results:
try:
unique_id = result['unique_id']
name = self._get_name(unique_id)
except KeyError as exc:
raise DBTException(
f'Invalid result, missing required key {exc}'
) from None
name = self._get_name(result, nodes)
if (not extra_results_ok) and (name not in expected_names):
raise DBTException(
f'Got unexpected name {name} in results'
Expand All @@ -334,14 +353,7 @@ def step_run_results(self, sequence_item, tmpdir):
attributes = self._build_expected_attributes_dict(values)

for result in results:
try:
unique_id = result['unique_id']
name = self._get_name(unique_id)
except KeyError as exc:
raise DBTException(
f'Invalid result, missing required key {exc}'
) from None

name = self._get_name(result, nodes)
if name in attributes:
for key, value in attributes[name].items():
try:
Expand Down Expand Up @@ -521,7 +533,8 @@ def step_relation_types(self, sequence_item):
schemas.add(relation.without_identifier())
with self.adapter.connection_named('__test'):
for schema in schemas:
found_relations.extend(self.adapter.list_relations_without_caching(schema))
found_relations.extend(
self.adapter.list_relations_without_caching(schema))

for key, value in expected.items():
for relation in found_relations:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dbt-core>=0.17.0,<=0.18
dbt-core>=0.19.0rc1
pytest
typing_extensions>=3.7.4,<3.8
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def read(path):
author="Fishtown Analytics",
author_email="[email protected]",
url="https://github.com/fishtown-analytics/dbt-adapter-tests",
version='0.3.0',
version='0.4.0',
package_data={
'pytest_dbt_adapter': [
'projects/*.yml',
Expand Down

0 comments on commit a411336

Please sign in to comment.