-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[FEATURE] ValidationConfig.save()
#9579
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
89c5953
save
cdkini 6e3efd4
mypy
cdkini beff4a9
public_api
cdkini 2eeb464
Merge branch 'develop' into m/v1-223/validation_config_save
cdkini 807fe52
Merge branch 'develop' into m/v1-223/validation_config_save
cdkini a89e569
override init
cdkini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -34,21 +34,27 @@ | |
) | ||
|
||
|
||
class TestValidationRun: | ||
@pytest.fixture | ||
def validation_config(self) -> ValidationConfig: | ||
context = gx.get_context(mode="ephemeral") | ||
batch_config = ( | ||
context.sources.add_pandas("my_datasource") | ||
.add_csv_asset("csv_asset", "taxi.csv") # type: ignore | ||
.add_batch_config("my_batch_config") | ||
) | ||
return ValidationConfig( | ||
name="my_validation", | ||
data=batch_config, | ||
suite=ExpectationSuite(name="my_suite"), | ||
) | ||
@pytest.fixture | ||
def ephemeral_context(): | ||
return gx.get_context(mode="ephemeral") | ||
|
||
|
||
@pytest.fixture | ||
def validation_config(ephemeral_context: EphemeralDataContext) -> ValidationConfig: | ||
context = ephemeral_context | ||
batch_config = ( | ||
context.sources.add_pandas("my_datasource") | ||
.add_csv_asset("csv_asset", "taxi.csv") # type: ignore | ||
.add_batch_config("my_batch_config") | ||
) | ||
return ValidationConfig( | ||
name="my_validation", | ||
data=batch_config, | ||
suite=ExpectationSuite(name="my_suite"), | ||
) | ||
|
||
|
||
class TestValidationRun: | ||
@pytest.fixture | ||
def mock_validator(self): | ||
"""Set up our ProjectManager to return a mock Validator""" | ||
|
@@ -491,3 +497,28 @@ def test_validation_config_deserialization_non_existant_resource( | |
): | ||
with pytest.raises(ValueError, match=f"{error_substring}*."): | ||
ValidationConfig.parse_obj(serialized_config) | ||
|
||
|
||
@pytest.mark.unit | ||
def test_validation_config_save_success( | ||
ephemeral_context: EphemeralDataContext, validation_config: ValidationConfig | ||
): | ||
context = ephemeral_context | ||
vc = validation_config | ||
|
||
vc = context.validations.add(vc) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: to make the intention of the test here more clear, having the initial |
||
|
||
other_suite = ExpectationSuite(name="my_other_suite") | ||
vc.suite = other_suite | ||
vc.save() | ||
|
||
assert vc.suite == other_suite | ||
assert context.validations.get(vc.name).suite == other_suite | ||
|
||
|
||
@pytest.mark.unit | ||
def test_validation_config_save_failure(validation_config: ValidationConfig): | ||
with pytest.raises( | ||
ValueError, match="ValidationConfig must be added to a store before saving." | ||
): | ||
validation_config.save() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't we say we want the pattern here to be that we get the store upon initialization? (e.g. that's what we do for expectation suites). Both for raising earlier, and for predictability in case someone switches contexts. I think we could hijack a root_validator for this, even though I don't love it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay yeah wasn’t sure the pattern to follow when using Pydantic but you’re right