Skip to content

Commit

Permalink
Revert "[MAINTENANCE] Add context to BatchConfig, and fetch assets …
Browse files Browse the repository at this point in the history
…by name (#8982)"

This reverts commit 6bd8a63.
  • Loading branch information
tyler-hoffman committed Nov 28, 2023
1 parent a4b87de commit a296ae7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 97 deletions.
20 changes: 2 additions & 18 deletions great_expectations/core/batch_config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from typing import Optional

from great_expectations.compatibility import pydantic
from great_expectations.data_context.data_context.abstract_data_context import (
AbstractDataContext,
)
from great_expectations.datasource.fluent.batch_request import (
BatchRequest,
BatchRequestOptions,
)
from great_expectations.datasource.fluent.interfaces import DataAsset, Datasource
from great_expectations.datasource.fluent.interfaces import DataAsset


class BatchConfig(pydantic.BaseModel):
Expand All @@ -18,20 +15,7 @@ class BatchConfig(pydantic.BaseModel):
TODO: Add splitters and sorters?
"""

class Config:
arbitrary_types_allowed = True

context: AbstractDataContext
datasource_name: str
data_asset_name: str

@property
def data_asset(self) -> DataAsset:
"""Get the DataAsset referenced by this BatchConfig."""
datasource = self.context.get_datasource(self.datasource_name)
assert isinstance(datasource, Datasource)

return datasource.get_asset(self.data_asset_name)
data_asset: DataAsset

def build_batch_request(
self, batch_request_options: Optional[BatchRequestOptions] = None
Expand Down
13 changes: 2 additions & 11 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3245,22 +3245,13 @@ def sqlite_connection_string() -> str:
return f"sqlite:///{db_file_path}"


@pytest.fixture
def fds_data_context_datasource_name() -> str:
return "sqlite_datasource"


@pytest.fixture
def fds_data_context(
sa,
fds_data_context_datasource_name: str,
empty_data_context: AbstractDataContext,
sqlite_connection_string: str,
sa, empty_data_context: AbstractDataContext, sqlite_connection_string: str
) -> AbstractDataContext:
context = empty_data_context
datasource = context.sources.add_sqlite(
name=fds_data_context_datasource_name,
connection_string=sqlite_connection_string,
name="sqlite_datasource", connection_string=sqlite_connection_string
)

datasource.add_query_asset(
Expand Down
60 changes: 3 additions & 57 deletions tests/core/test_batch_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,8 @@
import pytest

from great_expectations.core.batch_config import BatchConfig
from great_expectations.data_context.data_context.abstract_data_context import (
AbstractDataContext,
)
from great_expectations.datasource.fluent.batch_request import BatchRequestOptions
from great_expectations.datasource.fluent.interfaces import DataAsset
from great_expectations.datasource.fluent.sql_datasource import TableAsset
from great_expectations.datasource.fluent.sqlite_datasource import SqliteDatasource


@pytest.fixture
def mock_asset_name() -> str:
return "foo"


@pytest.fixture
def mock_asset(
mock_asset_name: str,
) -> TableAsset:
mock_data_asset = Mock(spec=TableAsset)
mock_data_asset.name = mock_asset_name
return mock_data_asset


@pytest.fixture
def data_context(
fds_data_context: AbstractDataContext,
fds_data_context_datasource_name: str,
mock_asset: TableAsset,
) -> AbstractDataContext:
datasource = fds_data_context.get_datasource(fds_data_context_datasource_name)
assert isinstance(datasource, SqliteDatasource)
datasource.assets.append(mock_asset)
return fds_data_context


@pytest.mark.unit
def test_data_asset(
data_context: AbstractDataContext,
fds_data_context_datasource_name: str,
mock_asset_name: str,
mock_asset: DataAsset,
):
batch_config = BatchConfig(
context=data_context,
datasource_name=fds_data_context_datasource_name,
data_asset_name=mock_asset_name,
)
assert batch_config.data_asset == mock_asset


@pytest.mark.parametrize(
Expand All @@ -64,20 +18,12 @@ def test_data_asset(
],
)
@pytest.mark.unit
def test_build_batch_request(
batch_request_options: Optional[BatchRequestOptions],
data_context: AbstractDataContext,
fds_data_context_datasource_name: str,
mock_asset_name: str,
):
batch_config = BatchConfig(
context=data_context,
datasource_name=fds_data_context_datasource_name,
data_asset_name=mock_asset_name,
)
def test_build_batch_request(batch_request_options: Optional[BatchRequestOptions]):
batch_config = BatchConfig(data_asset=Mock(spec=DataAsset))

batch_config.build_batch_request(batch_request_options=batch_request_options)

mock_build_batch_request = batch_config.data_asset.build_batch_request
assert isinstance(mock_build_batch_request, Mock)

mock_build_batch_request.assert_called_once_with(options=batch_request_options)
19 changes: 8 additions & 11 deletions tests/validator/test_v1_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from great_expectations.data_context.data_context.abstract_data_context import (
AbstractDataContext,
)
from great_expectations.datasource.fluent.sqlite_datasource import SqliteDatasource
from great_expectations.expectations.core.expect_column_values_to_be_between import (
ExpectColumnValuesToBeBetween,
)
Expand Down Expand Up @@ -43,26 +44,22 @@ def expectation_suite(


@pytest.fixture
def batch_config(
fds_data_context: AbstractDataContext,
fds_data_context_datasource_name: str,
) -> BatchConfig:
def batch_config(fds_data_context: AbstractDataContext) -> BatchConfig:
datasource = fds_data_context.get_datasource("sqlite_datasource")
assert isinstance(datasource, SqliteDatasource)
return BatchConfig(
context=fds_data_context,
datasource_name=fds_data_context_datasource_name,
data_asset_name="trip_asset",
data_asset=datasource.get_asset("trip_asset"),
)


@pytest.fixture
def batch_config_with_event_type_splitter(
fds_data_context: AbstractDataContext,
fds_data_context_datasource_name: str,
) -> BatchConfig:
datasource = fds_data_context.get_datasource("sqlite_datasource")
assert isinstance(datasource, SqliteDatasource)
return BatchConfig(
context=fds_data_context,
datasource_name=fds_data_context_datasource_name,
data_asset_name="trip_asset_split_by_event_type",
data_asset=datasource.get_asset("trip_asset_split_by_event_type"),
)


Expand Down

0 comments on commit a296ae7

Please sign in to comment.