Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MAINTENANCE] Type checking test_metadataource #9759

Merged
merged 5 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ exclude = [
'docs/sphinx_api_docs_source',
'_version\.py', # generated by `versioneer`
'v012', # legacy code
'tests/datasource/fluent/test_metadatasource\.py', # metaprogramming leads to errors
'datasource/data_connector/configured_asset_sql_data_connector\.py', # 37 - This is legacy code and will not be typed.
'core/usage_statistics/anonymizers/batch_anonymizer\.py', # 10 - This code will be removed in 1.0
'core/usage_statistics/anonymizers/batch_request_anonymizer\.py', # 16 - This code will be removed in 1.0
Expand Down
34 changes: 22 additions & 12 deletions tests/datasource/fluent/test_metadatasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pathlib
import re
from pprint import pformat as pf
from typing import TYPE_CHECKING, ClassVar, Dict, List, Optional, Tuple, Type, Union
from typing import TYPE_CHECKING, ClassVar, Dict, Generator, List, Optional, Tuple, Type, Union

import pytest

Expand Down Expand Up @@ -132,11 +132,11 @@ def build_batch_request(


@pytest.fixture(scope="function")
def context_sources_cleanup() -> _SourceFactories:
def context_sources_cleanup() -> Generator[_SourceFactories, None, None]:
"""Return the sources object and reset types/factories on teardown"""
try:
# setup
sources_copy = copy.deepcopy(_SourceFactories._SourceFactories__crud_registry)
sources_copy = copy.deepcopy(_SourceFactories._SourceFactories__crud_registry) # type: ignore[attr-defined]
type_lookup_copy = copy.deepcopy(_SourceFactories.type_lookup)
sources = get_context().sources

Expand All @@ -146,13 +146,13 @@ def context_sources_cleanup() -> _SourceFactories:

yield sources
finally:
_SourceFactories._SourceFactories__crud_registry = sources_copy
_SourceFactories._SourceFactories__crud_registry = sources_copy # type: ignore[attr-defined]
_SourceFactories.type_lookup = type_lookup_copy


@pytest.fixture(scope="function")
def empty_sources(context_sources_cleanup) -> _SourceFactories:
_SourceFactories._SourceFactories__crud_registry.clear()
def empty_sources(context_sources_cleanup) -> Generator[_SourceFactories, None, None]:
_SourceFactories._SourceFactories__crud_registry.clear() # type: ignore[attr-defined]
_SourceFactories.type_lookup.clear()
assert not _SourceFactories.type_lookup
yield context_sources_cleanup
Expand All @@ -176,6 +176,7 @@ class MyTestDatasource(Datasource):
type: str = "my_test"

@property
@override
def execution_engine_type(self) -> Type[ExecutionEngine]:
return DummyExecutionEngine

Expand All @@ -198,6 +199,7 @@ class MyTestDatasource(Datasource):
type: str = "my_test"

@property
@override
def execution_engine_type(self) -> Type[ExecutionEngine]:
return DummyExecutionEngine

Expand All @@ -218,6 +220,7 @@ class MyTestDatasource(Datasource):
extra_field: str

@property
@override
def execution_engine_type(self) -> Type[ExecutionEngine]:
return DummyExecutionEngine

Expand Down Expand Up @@ -253,6 +256,7 @@ class FooBarDatasource(Datasource):
type: str = "foo_bar"

@property
@override
def execution_engine_type(self) -> Type[ExecutionEngine]:
return DummyExecutionEngine

Expand All @@ -278,6 +282,7 @@ def test_ds_type_field_not_set(self, empty_sources: _SourceFactories):

class MissingTypeDatasource(Datasource):
@property
@override
def execution_engine_type(self) -> Type[ExecutionEngine]:
return DummyExecutionEngine

Expand All @@ -290,10 +295,10 @@ def test_ds_execution_engine_type_not_defined(self, empty_sources: _SourceFactor
class MissingExecEngineTypeDatasource(Datasource):
type: str = "valid"

def test_connection(self) -> None: ...
def test_connection(self) -> None: ... # type: ignore[override]

with pytest.raises(NotImplementedError):
MissingExecEngineTypeDatasource(name="name").get_execution_engine()
MissingExecEngineTypeDatasource(name="name").get_execution_engine() # type: ignore[call-arg]

def test_ds_assets_type_field_not_set(self, empty_sources: _SourceFactories):
with pytest.raises(
Expand All @@ -309,10 +314,12 @@ class BadAssetDatasource(Datasource):
asset_types: ClassVar[List[Type[DataAsset]]] = [MissingTypeAsset]

@property
@override
def execution_engine_type(self) -> Type[ExecutionEngine]:
return DummyExecutionEngine

def test_connection(self) -> None: ...
@override
def test_connection(self) -> None: ... # type: ignore[override]

# check that no types were registered
assert len(empty_sources.type_lookup) < 1
Expand All @@ -322,6 +329,7 @@ class MissingTestConnectionDatasource(Datasource):
type: str = "valid"

@property
@override
def execution_engine_type(self) -> Type[ExecutionEngine]:
return DummyExecutionEngine

Expand All @@ -341,20 +349,22 @@ def test_connection(self): ...
class BlueAsset(DataAsset):
type = "blue"

def test_connection(self): ...
@override
def test_connection(self): ... # type: ignore[override]

class PurpleDatasource(Datasource):
asset_types = [RedAsset, BlueAsset]
type: str = "purple"

@property
@override
def execution_engine_type(self) -> Type[ExecutionEngine]:
return DummyExecutionEngine

def test_connection(self): ...
def test_connection(self): ... # type: ignore[override]

def add_red_asset(self, asset_name: str) -> RedAsset:
asset = RedAsset(name=asset_name)
asset = RedAsset(name=asset_name) # type: ignore[call-arg] # ?
self._add_asset(asset=asset)
return asset

Expand Down