Skip to content

Commit

Permalink
requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ciklista committed Aug 9, 2023
1 parent 5d77ce4 commit 4b1143c
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.8', '3.10']
python-version: ['3.8', '3.11']
dbt-version: [1.5.x]

steps:
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,8 @@ dmypy.json
cython_debug/

# testing stuff
dbt_invoke/test_run.py
dbt_invoke/test_run.py

# duck db files
*.duckdb
.user.yml
Binary file removed dbt.duckdb
Binary file not shown.
45 changes: 11 additions & 34 deletions dbt_invoke/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,25 +521,7 @@ def _transform_ls_results(ctx, **kwargs):
potential_result_paths = None
results = dict()
for i, potential_result in enumerate(potential_results):
if 'original_file_path' in potential_result:
potential_result_path = potential_result['original_file_path']
# Before dbt version 0.20.0, original_file_path was not
# included in the json response of "dbt ls". For older
# versions of dbt, we need to run "dbt ls" with the
# "--output path" argument in order to retrieve paths
else:
if potential_result_paths is None:
potential_result_paths = _utils.dbt_ls(
ctx,
supported_resource_types=_SUPPORTED_RESOURCE_TYPES,
logger=_LOGGER,
output='path',
**kwargs,
)
assert len(potential_result_paths) == len(
potential_results
), 'Length of results differs from length of result details'
potential_result_path = potential_result_paths[i]
potential_result_path = potential_result['original_file_path']
if Path(ctx.config['project_path'], potential_result_path).exists():
results[potential_result_path] = potential_result
_LOGGER.info(
Expand Down Expand Up @@ -792,21 +774,16 @@ def _get_columns(ctx, resource_location, resource_dict, **kwargs):
'msg',
relevant_line.get('info', dict()).get('msg'),
)
else:
# for older dbt-core versions, we need to cross fingers a little harder
relevant_lines = result_lines[1:]
# also, the message key is different
columns = relevant_lines[-1].get('message')
# In some version of dbt columns are not passed as valid json but as
# a string representation of a list
is_string_list = (
isinstance(columns, str)
and columns.startswith('[')
and columns.endswith(']')
)
if is_string_list:
columns = ast.literal_eval(columns)
return columns
# In some version of dbt columns are not passed as valid json but as
# a string representation of a list
is_string_list = (
isinstance(columns, str)
and columns.startswith('[')
and columns.endswith(']')
)
if is_string_list:
columns = ast.literal_eval(columns)
return columns


def _structure_property_file_dict(location, resource_dict, columns_list):
Expand Down
4 changes: 4 additions & 0 deletions tests/data_files/customers.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
customer_id,created_at
1,2022-01-01
2,2022-01-01
3,2022-01-01
Binary file removed tests/data_files/customers.parquet
Binary file not shown.
2 changes: 2 additions & 0 deletions tests/data_files/items.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
item_id,price,updated_at
1,1,2023-01-01
Binary file removed tests/data_files/items.parquet
Binary file not shown.
2 changes: 2 additions & 0 deletions tests/data_files/orders.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
order_id,customer_id,item_id,quantity,order_at
1,1,1,2,2022-01-01
Binary file removed tests/data_files/orders.parquet
Binary file not shown.
Binary file modified tests/dbt.duckdb
Binary file not shown.
File renamed without changes.
16 changes: 0 additions & 16 deletions tests/dbt_project_files/dbt_project_pre_dbt_v1.yml

This file was deleted.

20 changes: 0 additions & 20 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import itertools
import os
import shutil
import sys
import unittest
from pathlib import Path
from unittest.mock import patch

import invoke
import pkg_resources

from dbt_invoke import properties
from dbt_invoke.internal import _utils
Expand All @@ -27,24 +25,6 @@ def setUpClass(cls):
cls.config_path = Path(PARENT_DIR, 'test_config.yml')
cls.config = _utils.parse_yaml(cls.config_path)

# for backward compatibility, select the correct dbt_project.yml file
if pkg_resources.get_distribution("dbt-core").version >= '1.0.0':
shutil.copy(
Path(PARENT_DIR, 'dbt_project_files/dbt_project.yml'),
Path(
PARENT_DIR, cls.config['project_name'], 'dbt_project.yml'
),
)
else:
shutil.copy(
Path(
PARENT_DIR, 'dbt_project_files/dbt_project_pre_dbt_v1.yml'
),
Path(
PARENT_DIR, cls.config['project_name'], 'dbt_project.yml'
),
)

cls.project_dir = Path(PARENT_DIR, cls.config['project_name'])
cls.profiles_dir = Path(PARENT_DIR, cls.config['project_name'])
cls.test_base_dir = PARENT_DIR
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dbt_project/models/sources.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sources:
- name: external_source
meta:
external_location: "tests/data_files/{name}.parquet"
external_location: "tests/data_files/{name}.csv"
tables:
- name: customers
- name: orders
Expand Down

0 comments on commit 4b1143c

Please sign in to comment.