Skip to content

Commit

Permalink
fixes after pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
daimor committed Sep 26, 2023
1 parent c8532fa commit bb08940
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 83 deletions.
16 changes: 8 additions & 8 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ select =
W
F
ignore =
W503 # makes Flake8 work like black
W504
E203 # makes Flake8 work like black
E741
E501
exclude =
tests
env
# makes Flake8 work like black
W503,
W504,
# makes Flake8 work like black
E203,
E741,
E501,
exclude = test
7 changes: 2 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: |
3.7
3.8
3.9
3.10
Expand All @@ -63,7 +62,6 @@ jobs:
run: |
pip install --user --upgrade pip
pip install pre-commit
pip install mypy==0.782
pip install -r requirements-dev.txt
pip --version
pre-commit --version
Expand All @@ -72,7 +70,7 @@ jobs:
- name: Run Tests
run: |
tox -e py37,py38,py39,py310
tox -e py38,py39,py310,py311
- name: Run pre-commit hooks
run: pre-commit run --all-files --show-diff-on-failure
Expand All @@ -86,7 +84,6 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: |
3.7
3.8
3.9
3.10
Expand All @@ -102,7 +99,7 @@ jobs:
-a 'iris session iris -U %SYS "##class(Security.Users).UnExpireUserPasswords(\"*\")"'
- name: Run Tests
run: |
tox -e py37-iris,py38-iris,py39-iris,py310-iris
tox -e py38-iris,py39-iris,py310-iris,py311-iris
build:
needs:
Expand Down
21 changes: 10 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# For more on configuring pre-commit hooks (see https://pre-commit.com/)

# TODO: remove global exclusion of tests when testing overhaul is complete
exclude: "^tests/.*"


# Force all unspecified python hooks to run python 3.8
default_language_version:
python: python3.10
python: python3

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
rev: v4.4.0
hooks:
- id: check-yaml
args: [--unsafe]
Expand All @@ -18,37 +15,39 @@ repos:
- id: trailing-whitespace
- id: check-case-conflict
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.1.0
hooks:
- id: black
additional_dependencies: ['click~=8.1']
args:
- "--line-length=99"
- "--target-version=py38"
- id: black
alias: black-check
stages: [manual]
additional_dependencies: ['click~=8.1']
args:
- "--line-length=99"
- "--target-version=py38"
- "--check"
- "--diff"
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
rev: 6.0.0
hooks:
- id: flake8
- id: flake8
alias: flake8-check
stages: [manual]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.782
rev: v1.2.0
hooks:
- id: mypy
args: [--show-error-codes, --ignore-missing-imports]
args: [--show-error-codes, --ignore-missing-imports, --explicit-package-bases, --warn-unused-ignores]
files: ^dbt/adapters/.*
language: system
- id: mypy
alias: mypy-check
stages: [manual]
args: [--show-error-codes, --pretty, --ignore-missing-imports]
args: [--show-error-codes, --pretty, --ignore-missing-imports, --explicit-package-bases]
files: ^dbt/adapters
language: system
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
3.7
3.8
3.9
3.10
3.11
4 changes: 2 additions & 2 deletions dbt/adapters/iris/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from dbt.adapters.iris.column import IRISColumn # noqa
from dbt.adapters.iris.impl import IRISAdapter

from dbt.adapters.base import AdapterPlugin # type: ignore
from dbt.include import iris # type: ignore
from dbt.adapters.base import AdapterPlugin
from dbt.include import iris


Plugin = AdapterPlugin(
Expand Down
4 changes: 2 additions & 2 deletions dbt/adapters/iris/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ class IRISCredentials(Credentials):
"user": "username",
}

def __init__(self, **kwargs):
def __init__(self, **kwargs: Any) -> None:
for k, v in kwargs.items():
setattr(self, k, v)

@property
def type(self):
def type(self) -> str:
"""Return name of adapter."""
return "iris"

Expand Down
6 changes: 3 additions & 3 deletions dbt/adapters/iris/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import agate
from dbt.exceptions import MacroArgTypeError
from dbt.exceptions import DbtRuntimeError
from dbt.adapters.base.relation import BaseRelation # type: ignore
from dbt.adapters.base.relation import BaseRelation

from dbt.adapters.sql import SQLAdapter # type: ignore
from dbt.adapters.sql import SQLAdapter
from dbt.events import AdapterLogger

from dbt.adapters.iris import IRISConnectionManager
Expand Down Expand Up @@ -172,5 +172,5 @@ def submit_python_job(self, parsed_model: dict, compiled_code: str):
self.execute(f"drop procedure if exists {proc_name}", auto_begin=False, fetch=False)
return response

def valid_incremental_strategies(self):
def valid_incremental_strategies(self) -> List[str]:
return ["append", "merge", "delete+insert"]
2 changes: 1 addition & 1 deletion dbt/adapters/iris/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def matches(
if str(self.path.get_lowered_part(k)).strip(self.quote_character) != v.lower().strip(
self.quote_character
):
approximate_match = False # type: ignore[union-attr]
approximate_match = False

# if approximate_match and not exact_match:
# target = self.create(database=database, schema=schema, identifier=identifier)
Expand Down
13 changes: 7 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

import os

# import json

# Import the fuctional fixtures as a plugin
Expand All @@ -13,10 +14,10 @@
@pytest.fixture(scope="class")
def dbt_profile_target():
return {
'type': 'iris',
'hostname': os.getenv('DBT_IRIS_HOST', 'localhost'),
'port': int(os.getenv('DBT_IRIS_PORT', '1972')),
'namespace': os.getenv('DBT_IRIS_NAMESPACE', 'USER'),
'username': os.getenv('DBT_IRIS_USER', '_SYSTEM'),
'password': os.getenv('DBT_IRIS_PASS', 'SYS'),
"type": "iris",
"hostname": os.getenv("DBT_IRIS_HOST", "localhost"),
"port": int(os.getenv("DBT_IRIS_PORT", "1972")),
"namespace": os.getenv("DBT_IRIS_NAMESPACE", "USER"),
"username": os.getenv("DBT_IRIS_USER", "_SYSTEM"),
"password": os.getenv("DBT_IRIS_PASS", "SYS"),
}
2 changes: 0 additions & 2 deletions tests/functional/adapter/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pytest

from dbt.tests.adapter.basic.test_base import BaseSimpleMaterializations
from dbt.tests.adapter.basic.test_singular_tests import BaseSingularTests
from dbt.tests.adapter.basic.test_singular_tests_ephemeral import (
Expand Down
2 changes: 0 additions & 2 deletions tests/functional/adapter/test_concurrency.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pytest

from dbt.tests.adapter.concurrency.test_concurrency import TestConcurenncy


Expand Down
6 changes: 3 additions & 3 deletions tests/functional/adapter/test_python_model.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from dbt.tests.adapter.python_model.test_python_model import BasePythonModelTests
from dbt.tests.adapter.python_model.test_python_model import BasePythonIncrementalTests
# from dbt.tests.adapter.python_model.test_python_model import BasePythonModelTests
# from dbt.tests.adapter.python_model.test_python_model import BasePythonIncrementalTests

# class TestPythonModelIRIS(BasePythonModelTests):
# pass

# class TestPythonIncrementalIRIS(BasePythonIncrementalTests):
# pass
# pass
46 changes: 22 additions & 24 deletions tests/unit/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,35 @@


class TestIRISAdapter(unittest.TestCase):

def setUp(self):
pass
flags.STRICT_MODE = True

profile_cfg = {
'outputs': {
'test': {
'type': 'iris',
'hostname': 'thishostshouldnotexist',
'port': 1972,
'namespace': 'USER',
'schema': 'dbt',
'username': 'dbt',
'password': 'dbt',
"outputs": {
"test": {
"type": "iris",
"hostname": "thishostshouldnotexist",
"port": 1972,
"namespace": "USER",
"schema": "dbt",
"username": "dbt",
"password": "dbt",
}
},
'target': 'test'
"target": "test",
}

project_cfg = {
'name': 'X',
'version': '0.1',
'profile': 'test',
'project-root': '/tmp/dbt/does-not-exist',
'quoting': {
'identifier': False,
'schema': True,
"name": "X",
"version": "0.1",
"profile": "test",
"project-root": "/tmp/dbt/does-not-exist",
"quoting": {
"identifier": False,
"schema": True,
},
'config-version': 2
"config-version": 2,
}

self.config = config_from_parts_or_dicts(project_cfg, profile_cfg)
Expand All @@ -48,13 +47,13 @@ def adapter(self):
self._adapter = IRISAdapter(self.config)
return self._adapter

@mock.patch('dbt.adapters.iris.connections.dbapi')
@mock.patch("dbt.adapters.iris.connections.dbapi")
def test_acquire_connection(self, connector):
connection = self.adapter.acquire_connection('dummy')
connection = self.adapter.acquire_connection("dummy")

connector.connect.assert_not_called()
connection.handle
self.assertEqual(connection.state, 'open')
self.assertEqual(connection.state, "open")
self.assertNotEqual(connection.handle, None)
connector.connect.assert_called_once()

Expand All @@ -63,8 +62,7 @@ def test_cancel_open_connections_empty(self):

def test_cancel_open_connections_main(self):
key = self.adapter.connections.get_thread_identifier()
self.adapter.connections.thread_connections[key] = mock_connection(
'main')
self.adapter.connections.thread_connections[key] = mock_connection("main")
self.assertEqual(len(list(self.adapter.cancel_open_connections())), 0)

def test_placeholder(self):
Expand Down
29 changes: 16 additions & 13 deletions tests/unit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def normalize(path):


class Obj:
which = 'blah'
which = "blah"
single_threaded = False


Expand Down Expand Up @@ -115,6 +115,7 @@ def config_from_parts_or_dicts(project, profile, packages=None, selectors=None,

def inject_plugin(plugin):
from dbt.adapters.factory import FACTORY

key = plugin.adapter.type()
FACTORY.plugins[key] = plugin

Expand All @@ -125,6 +126,7 @@ def inject_adapter(value, plugin):
"""
inject_plugin(plugin)
from dbt.adapters.factory import FACTORY

key = value.type()
FACTORY.adapters[key] = value

Expand All @@ -142,7 +144,7 @@ def assert_to_dict(self, obj, dct):
def assert_from_dict(self, obj, dct, cls=None):
if cls is None:
cls = self.ContractType
self.assertEqual(cls.from_dict(dct), obj)
self.assertEqual(cls.from_dict(dct), obj)

def assert_symmetric(self, obj, dct, cls=None):
self.assert_to_dict(obj, dct)
Expand All @@ -159,26 +161,27 @@ def assert_fails_validation(self, dct, cls=None):
def generate_name_macros(package):
from dbt.contracts.graph.parsed import ParsedMacro
from dbt.node_types import NodeType

name_sql = {}
for component in ('database', 'schema', 'alias'):
if component == 'alias':
source = 'node.name'
for component in ("database", "schema", "alias"):
if component == "alias":
source = "node.name"
else:
source = f'target.{component}'
name = f'generate_{component}_name'
sql = f'{{% macro {name}(value, node) %}} {{% if value %}} {{{{ value }}}} {{% else %}} {{{{ {source} }}}} {{% endif %}} {{% endmacro %}}'
source = f"target.{component}"
name = f"generate_{component}_name"
sql = f"{{% macro {name}(value, node) %}} {{% if value %}} {{{{ value }}}} {{% else %}} {{{{ {source} }}}} {{% endif %}} {{% endmacro %}}"
name_sql[name] = sql

all_sql = '\n'.join(name_sql.values())
all_sql = "\n".join(name_sql.values())
for name, sql in name_sql.items():
pm = ParsedMacro(
name=name,
resource_type=NodeType.Macro,
unique_id=f'macro.{package}.{name}',
unique_id=f"macro.{package}.{name}",
package_name=package,
original_file_path=normalize('macros/macro.sql'),
root_path='./dbt_modules/root',
path=normalize('macros/macro.sql'),
original_file_path=normalize("macros/macro.sql"),
root_path="./dbt_modules/root",
path=normalize("macros/macro.sql"),
raw_sql=all_sql,
macro_sql=sql,
)
Expand Down

0 comments on commit bb08940

Please sign in to comment.