-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add working script to run macro * Add comment about adapters * Try using a project instead of runtime config * Remove spark credentials and Project * Use connection from soda spark * Add test requirements * Add pytest ini * Move everything into pytest fixtures * Copy connection * Remove pytest-dbt-core code * Add pytest dbt core as test requirement * Add workflow for testing * Bump pytest dbt core version * Add profile to dbt project * Add profiles * Add profiles dir when running pytest * Remove redundant from future import annotations * Bump pytest-dbt-core version * Change version * Add pyspark dependency * Change pyspark dependency to dbt-spark session * Change required by to dbt-spark * Add test docstring * Make test less strict * Create and delete table with fixture * Fix typo * Add section about testing to the documentation * Move test macros into tests/unit * Run unit tests only in Github action * Merge dev and test requirements * Move conftest into functional
- Loading branch information
1 parent
65ae910
commit 143c1e7
Showing
8 changed files
with
108 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Test | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Python 3.9 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.9 | ||
|
||
- name: Install dependencies | ||
shell: bash | ||
run: | | ||
sudo apt-get install libsasl2-dev | ||
python -m pip install --upgrade pip | ||
python -m pip install -r dev-requirements.txt | ||
- name: Run unit tests | ||
shell: bash | ||
run: DBT_PROFILES_DIR=$PWD pytest tests/unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
name: 'spark_utils' | ||
profile: 'sparkutils' | ||
version: '0.3.0' | ||
config-version: 2 | ||
require-dbt-version: [">=1.2.0", "<2.0.0"] | ||
macro-paths: ["macros"] | ||
macro-paths: ["macros"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
sparkutils: | ||
target: test | ||
outputs: | ||
test: | ||
type: spark | ||
method: session | ||
schema: test | ||
host: NA # not used, but required by `dbt-spark` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import uuid | ||
|
||
import pytest | ||
from dbt.clients.jinja import MacroGenerator | ||
from pyspark.sql import SparkSession | ||
|
||
|
||
@pytest.fixture | ||
def simple_table(spark_session: SparkSession) -> str: | ||
"""Create and delete a simple table used for testing.""" | ||
table_name = f"default.table_{uuid.uuid4()}".replace("-", "_") | ||
spark_session.sql(f"CREATE TABLE {table_name} (id int) USING parquet") | ||
yield table_name | ||
spark_session.sql(f"DROP TABLE IF EXISTS {table_name}") | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"macro_generator", ["macro.spark_utils.get_tables"], indirect=True | ||
) | ||
def test_create_table( | ||
macro_generator: MacroGenerator, simple_table: str | ||
) -> None: | ||
"""The `get_tables` macro should return the created table.""" | ||
tables = macro_generator() | ||
assert simple_table in tables | ||
|