-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from great-expectations/f/core-765/use_validat…
…ion_definition Use ValidationDefinition.run
- Loading branch information
Showing
14 changed files
with
352 additions
and
62 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
Empty file.
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,47 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, Literal | ||
|
||
if TYPE_CHECKING: | ||
from great_expectations import ExpectationSuite | ||
from great_expectations.core.batch_definition import BatchDefinition | ||
from great_expectations.core.expectation_validation_result import ( | ||
ExpectationSuiteValidationResult, | ||
) | ||
from great_expectations.data_context import AbstractDataContext | ||
from great_expectations.expectations import Expectation | ||
|
||
|
||
def run_validation_definition( | ||
task_id: str, | ||
expect: Expectation | ExpectationSuite, | ||
batch_definition: BatchDefinition, | ||
result_format: Literal["BOOLEAN_ONLY", "BASIC", "SUMMARY", "COMPLETE"] | None, | ||
batch_parameters: dict, | ||
gx_context: AbstractDataContext, | ||
) -> ExpectationSuiteValidationResult: | ||
"""Given a BatchDefinition and an Expectation or ExpectationSuite, ensure a | ||
ValidationDefinition and run it.""" | ||
import great_expectations as gx | ||
|
||
if isinstance(expect, gx.expectations.Expectation): | ||
suite = gx.ExpectationSuite(name=task_id, expectations=[expect]) | ||
else: | ||
suite = expect | ||
validation_definition = gx_context.validation_definitions.add_or_update( | ||
validation=gx.ValidationDefinition( | ||
name=task_id, | ||
suite=suite, | ||
data=batch_definition, | ||
), | ||
) | ||
if result_format: | ||
result = validation_definition.run( | ||
batch_parameters=batch_parameters, | ||
result_format=result_format, | ||
) | ||
else: | ||
result = validation_definition.run( | ||
batch_parameters=batch_parameters, | ||
) | ||
return result |
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
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
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
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,21 @@ | ||
from typing import Generator | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
from great_expectations.expectations import Expectation | ||
from pytest_mock import MockerFixture | ||
|
||
|
||
@pytest.fixture | ||
def mock_gx(mocker: MockerFixture) -> Generator[Mock, None, None]: | ||
"""Due to constraints from Airflow, GX must be imported locally | ||
within the Operator, which makes mocking the GX namespace difficult. | ||
This fixture allows us to globally patch GX. | ||
One known issue with this approach is that isinstance checks fail against | ||
mocks. | ||
""" | ||
mock_gx = Mock() | ||
mock_gx.expectations.Expectation = Expectation # required for isinstance check | ||
mocker.patch.dict("sys.modules", {"great_expectations": mock_gx}) | ||
yield mock_gx |
Oops, something went wrong.