Skip to content

Commit

Permalink
Copy Makefile test infrastructure from dbt-snowflake and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mwallace582 committed Jan 8, 2024
1 parent 3b13594 commit d634515
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 6 deletions.
56 changes: 56 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
.DEFAULT_GOAL:=help

.PHONY: dev
dev: ## Installs adapter in develop mode along with development dependencies
@\
pip install -e . -r dev-requirements.txt && pre-commit install

.PHONY: dev-uninstall
dev-uninstall: ## Uninstalls all packages while maintaining the virtual environment
## Useful when updating versions, or if you accidentally installed into the system interpreter
pip freeze | grep -v "^-e" | cut -d "@" -f1 | xargs pip uninstall -y
pip uninstall -y dbt-mysql

.PHONY: flake8
flake8: ## Runs flake8 against staged changes to enforce style guide.
@\
pre-commit run --hook-stage manual flake8-check | grep -v "INFO"

.PHONY: lint
lint: ## Runs flake8 code checks against staged changes.
@\
pre-commit run flake8-check --hook-stage manual | grep -v "INFO";

.PHONY: linecheck
linecheck: ## Checks for all Python lines 100 characters or more
@\
find dbt -type f -name "*.py" -exec grep -I -r -n '.\{100\}' {} \;

.PHONY: unit
unit: ## Runs unit tests with py38.
@\
tox -e py38

.PHONY: test
test: ## Runs unit tests with py38 and code checks against staged changes.
@\
tox -p -e py38; \
pre-commit run flake8-check --hook-stage manual | grep -v "INFO";

.PHONY: integration
integration: ## Runs mysql integration tests with py38.
@\
tox -e py38-mysql --; \
tox -e py38-mysql5 --; \
tox -e py38-mariadb --;

.PHONY: clean
@echo "cleaning repo"
@git clean -f -X

.PHONY: help
help: ## Show this help message.
@echo 'usage: make [target]'
@echo
@echo 'targets:'
@grep -E '^[7+a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
33 changes: 27 additions & 6 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,22 @@ PYTHONPATH=. pytest tests/functional/adapter/test_basic.py
## Full example

### Prerequisites
- [`dbt-tests-adapter`](https://github.com/dbt-labs/dbt-core/tree/main/tests/adapter) package

#### Dependencies

`pip install -r ./dev-requirements.txt`

#### Python Version

Python 3.8 and 3.9 are supported test targets and may need to be installed before tests can run.

##### Ubuntu

```
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.8 python3.8-distutils python3.9 python3.9-distutils
```

### Environment variables

Expand Down Expand Up @@ -87,19 +102,25 @@ sql_mode = "ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ALLOW_INVALID

### Run tests

Run the test specs in this repository:
Run all the tests via `make`:
```shell
PYTHONPATH=. pytest -v --profile mysql tests/functional && \
PYTHONPATH=. pytest -v --profile mysql5 tests/functional && \
PYTHONPATH=. pytest -v --profile mariadb tests/functional
make unit
make integration
```

Or run all the tests via `tox`:
```shell
tox
```

Run a single test
Or run the test specs directly
```shell
PYTHONPATH=. pytest -v --profile mysql tests/functional && \
PYTHONPATH=. pytest -v --profile mysql5 tests/functional && \
PYTHONPATH=. pytest -v --profile mariadb tests/functional
```

Or run a single test
```shell
pytest -v --profile mysql tests/functional/adapter/test_basic.py::TestEmptyMySQL::test_empty
```
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ description = adapter plugin integration testing
skip_install = true
passenv =
DBT_*
PYTEST_ADDOPTS
commands =
mysql: {envpython} -m pytest -v --profile mysql {posargs} tests/functional
mysql5: {envpython} -m pytest -v --profile mysql5 {posargs} tests/functional
Expand Down

0 comments on commit d634515

Please sign in to comment.