-
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
[ENHANCEMENT] DataContext.clean_data_docs now raises helpful errors #2621
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import os | ||
from unittest import mock | ||
|
||
import pytest | ||
|
@@ -43,7 +44,7 @@ def test_open_docs_with_single_local_site(mock_webbrowser, empty_data_context): | |
|
||
|
||
@pytest.fixture | ||
def context_with_multiple_sites(empty_data_context): | ||
def context_with_multiple_built_sites(empty_data_context): | ||
context = empty_data_context | ||
config = context.project_config_with_variables_substituted | ||
multi_sites = { | ||
|
@@ -66,6 +67,7 @@ def context_with_multiple_sites(empty_data_context): | |
} | ||
config.data_docs_sites = multi_sites | ||
context._project_config = config | ||
context.build_data_docs() | ||
obs = context.get_docs_sites_urls(only_if_exists=False) | ||
assert len(obs) == 2 | ||
assert obs[0]["site_url"].endswith( | ||
|
@@ -77,6 +79,16 @@ def context_with_multiple_sites(empty_data_context): | |
"great_expectations/uncommitted/data_docs/another_local_site/index.html" | ||
) | ||
assert obs[1]["site_name"] == "another_local_site" | ||
for site in ["local_site", "another_local_site"]: | ||
assert os.path.isfile( | ||
os.path.join( | ||
context.root_directory, | ||
context.GE_UNCOMMITTED_DIR, | ||
"data_docs", | ||
site, | ||
"index.html", | ||
) | ||
) | ||
|
||
return context | ||
|
||
|
@@ -129,8 +141,10 @@ def context_with_multiple_local_sites_and_s3_site(empty_data_context): | |
|
||
|
||
@mock.patch("webbrowser.open", return_value=True, side_effect=None) | ||
def test_open_docs_with_two_local_sites(mock_webbrowser, context_with_multiple_sites): | ||
context = context_with_multiple_sites | ||
def test_open_docs_with_two_local_sites( | ||
mock_webbrowser, context_with_multiple_built_sites | ||
): | ||
context = context_with_multiple_built_sites | ||
context.open_data_docs(only_if_exists=False) | ||
assert mock_webbrowser.call_count == 2 | ||
first_call = mock_webbrowser.call_args_list[0][0][0] | ||
|
@@ -147,9 +161,9 @@ def test_open_docs_with_two_local_sites(mock_webbrowser, context_with_multiple_s | |
|
||
@mock.patch("webbrowser.open", return_value=True, side_effect=None) | ||
def test_open_docs_with_two_local_sites_specify_open_one( | ||
mock_webbrowser, context_with_multiple_sites | ||
mock_webbrowser, context_with_multiple_built_sites | ||
): | ||
context = context_with_multiple_sites | ||
context = context_with_multiple_built_sites | ||
context.open_data_docs(site_name="another_local_site", only_if_exists=False) | ||
|
||
assert mock_webbrowser.call_count == 1 | ||
|
@@ -176,17 +190,17 @@ def test_get_docs_sites_urls_with_no_sites_specify_one(context_with_no_sites): | |
|
||
|
||
def test_get_docs_sites_urls_with_non_existent_site_raises_error( | ||
context_with_multiple_sites, | ||
context_with_multiple_built_sites, | ||
): | ||
context = context_with_multiple_sites | ||
context = context_with_multiple_built_sites | ||
with pytest.raises(DataContextError): | ||
context.get_docs_sites_urls(site_name="not_a_real_site") | ||
|
||
|
||
def test_get_docs_sites_urls_with_two_local_sites_specify_one( | ||
context_with_multiple_sites, | ||
context_with_multiple_built_sites, | ||
): | ||
context = context_with_multiple_sites | ||
context = context_with_multiple_built_sites | ||
obs = context.get_docs_sites_urls( | ||
site_name="another_local_site", only_if_exists=False | ||
) | ||
|
@@ -198,3 +212,50 @@ def test_get_docs_sites_urls_with_two_local_sites_specify_one( | |
assert url.endswith( | ||
"/great_expectations/uncommitted/data_docs/another_local_site/index.html" | ||
) | ||
|
||
|
||
def test_clean_data_docs_on_context_with_no_sites_raises_error( | ||
context_with_no_sites, | ||
): | ||
context = context_with_no_sites | ||
with pytest.raises(DataContextError): | ||
context.clean_data_docs() | ||
|
||
|
||
def test_clean_data_docs_on_context_with_multiple_sites_with_no_site_name_cleans_all_sites_and_returns_true( | ||
context_with_multiple_built_sites, | ||
): | ||
context = context_with_multiple_built_sites | ||
assert context.clean_data_docs() is True | ||
for site in ["local_site", "another_local_site"]: | ||
assert not os.path.isfile( | ||
os.path.join( | ||
context.root_directory, | ||
context.GE_UNCOMMITTED_DIR, | ||
"data_docs", | ||
site, | ||
"index.html", | ||
) | ||
) | ||
|
||
|
||
def test_clean_data_docs_on_context_with_multiple_sites_with_existing_site_name_cleans_selected_site_and_returns_true( | ||
context_with_multiple_built_sites, | ||
): | ||
context = context_with_multiple_built_sites | ||
assert context.clean_data_docs(site_name="another_local_site") is True | ||
data_docs_dir = os.path.join( | ||
context.root_directory, context.GE_UNCOMMITTED_DIR, "data_docs" | ||
) | ||
assert not os.path.isfile( | ||
os.path.join(data_docs_dir, "another_local_site", "index.html") | ||
) | ||
assert os.path.isfile(os.path.join(data_docs_dir, "local_site", "index.html")) | ||
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. 👌 |
||
|
||
|
||
def test_clean_data_docs_on_context_with_multiple_sites_with_non_existent_site_name_raises_error( | ||
context_with_multiple_built_sites, | ||
): | ||
context = context_with_multiple_built_sites | ||
with pytest.raises(DataContextError): | ||
assert context.clean_data_docs(site_name="not_a_real_site") |
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.
❤️