Skip to content

Commit

Permalink
* [ENHANCEMENT] CLI docs build command implemented for v3 api
Browse files Browse the repository at this point in the history
  • Loading branch information
Aylr committed Mar 26, 2021
1 parent dc9f4fd commit 9879959
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 55 deletions.
2 changes: 1 addition & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Changelog
Develop
-----------------
* [ENHANCEMENT] CLI `docs list` command implemented for v3 api

* [ENHANCEMENT] CLI `docs build` command implemented for v3 api

0.13.15
-----------------
Expand Down
3 changes: 1 addition & 2 deletions great_expectations/cli/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def docs(ctx):
)
@click.pass_context
def docs_build(ctx, site_name, view=True):
""" Build Data Docs for a project."""
display_not_implemented_message_and_exit()
"""Build Data Docs for a project."""
context: DataContext = ctx.obj.data_context
build_docs(context, site_name=site_name, view=view, assume_yes=ctx.obj.assume_yes)
toolkit.send_usage_message(
Expand Down
167 changes: 115 additions & 52 deletions tests/cli/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,152 +24,215 @@ def test_docs_help_output(caplog):
assert_no_logging_messages_or_tracebacks(caplog, result)


@pytest.mark.xfail(
reason="This command is not yet implemented for the modern API",
run=True,
strict=True,
@mock.patch(
"great_expectations.core.usage_statistics.usage_statistics.UsageStatisticsHandler.emit"
)
@mock.patch("webbrowser.open", return_value=True, side_effect=None)
def test_docs_build_view(
mock_webbrowser,
mock_emit,
caplog,
monkeypatch,
site_builder_data_context_v013_with_html_store_titanic_random,
titanic_data_context_stats_enabled_config_version_3,
):
context = site_builder_data_context_v013_with_html_store_titanic_random
context = titanic_data_context_stats_enabled_config_version_3
root_dir = context.root_directory

runner = CliRunner(mix_stderr=False)
monkeypatch.chdir(os.path.dirname(context.root_directory))
result = runner.invoke(
cli,
[
"--v3-api",
"docs",
"build",
],
"--v3-api docs build",
input="\n",
catch_exceptions=False,
)
stdout = result.stdout
print(result.output)

assert result.exit_code == 0
assert mock_webbrowser.call_count == 1
assert "Would you like to proceed?" in stdout
assert "Building" in stdout
assert "The following Data Docs sites will be built:" in stdout
assert "local_site" in stdout
assert "great_expectations/uncommitted/data_docs/local_site/index.html" in stdout

assert mock_emit.call_count == 4
assert mock_emit.call_args_list == [
mock.call(
{"event_payload": {}, "event": "data_context.__init__", "success": True}
),
mock.call(
{
"event_payload": {},
"event": "data_context.build_data_docs",
"success": True,
}
),
mock.call(
{
"event_payload": {},
"event": "data_context.open_data_docs",
"success": True,
}
),
mock.call(
{
"event": "cli.docs.build",
"event_payload": {"api_version": "v3"},
"success": True,
}
),
]

context = DataContext(root_dir)
obs_urls = context.get_docs_sites_urls()

assert len(obs_urls) == 2
assert len(obs_urls) == 1
assert (
"great_expectations/uncommitted/data_docs/local_site/index.html"
in obs_urls[0]["site_url"]
)
local_site_dir = os.path.join(root_dir, "uncommitted/data_docs/local_site/")
site_dir = os.path.join(
root_dir, context.GE_UNCOMMITTED_DIR, "data_docs", "local_site"
)
assert os.path.isdir(site_dir)
# Note the fixture has no expectations or validations - only check the index
assert os.path.isfile(os.path.join(site_dir, "index.html"))

assert os.path.isdir(os.path.join(local_site_dir))
assert os.path.isfile(os.path.join(local_site_dir, "index.html"))
assert os.path.isdir(os.path.join(local_site_dir, "expectations"))
assert os.path.isdir(os.path.join(local_site_dir, "validations"))
assert_no_logging_messages_or_tracebacks(
my_caplog=caplog,
click_result=result,
allowed_deprecation_message=VALIDATION_OPERATORS_DEPRECATION_MESSAGE,
)


@pytest.mark.xfail(
reason="This command is not yet implemented for the modern API",
run=True,
strict=True,
@mock.patch(
"great_expectations.core.usage_statistics.usage_statistics.UsageStatisticsHandler.emit"
)
@mock.patch("webbrowser.open", return_value=True, side_effect=None)
def test_docs_build_no_view(
mock_webbrowser,
mock_emit,
caplog,
monkeypatch,
site_builder_data_context_v013_with_html_store_titanic_random,
titanic_data_context_stats_enabled_config_version_3,
):
context = site_builder_data_context_v013_with_html_store_titanic_random
context = titanic_data_context_stats_enabled_config_version_3
root_dir = context.root_directory

runner = CliRunner(mix_stderr=False)
monkeypatch.chdir(os.path.dirname(context.root_directory))
result = runner.invoke(
cli,
[
"--v3-api",
"docs",
"build",
"--no-view",
],
"--v3-api docs build --no-view",
input="\n",
catch_exceptions=False,
)
stdout = result.stdout

assert result.exit_code == 0
assert mock_webbrowser.call_count == 0

assert "Would you like to proceed?" in stdout
assert "Building" in stdout
assert "The following Data Docs sites will be built:" in stdout
assert "local_site" in stdout
assert "great_expectations/uncommitted/data_docs/local_site/index.html" in stdout

assert mock_emit.call_count == 3
assert mock_emit.call_args_list == [
mock.call(
{"event_payload": {}, "event": "data_context.__init__", "success": True}
),
mock.call(
{
"event_payload": {},
"event": "data_context.build_data_docs",
"success": True,
}
),
mock.call(
{
"event": "cli.docs.build",
"event_payload": {"api_version": "v3"},
"success": True,
}
),
]

context = DataContext(root_dir)
obs_urls = context.get_docs_sites_urls()

assert len(obs_urls) == 2
assert len(obs_urls) == 1
assert (
"great_expectations/uncommitted/data_docs/local_site/index.html"
in obs_urls[0]["site_url"]
)
local_site_dir = os.path.join(root_dir, "uncommitted/data_docs/local_site/")
site_dir = os.path.join(
root_dir, context.GE_UNCOMMITTED_DIR, "data_docs", "local_site"
)
assert os.path.isdir(site_dir)
# Note the fixture has no expectations or validations - only check the index
assert os.path.isfile(os.path.join(site_dir, "index.html"))

assert os.path.isdir(os.path.join(local_site_dir))
assert os.path.isfile(os.path.join(local_site_dir, "index.html"))
assert os.path.isdir(os.path.join(local_site_dir, "expectations"))
assert os.path.isdir(os.path.join(local_site_dir, "validations"))
assert_no_logging_messages_or_tracebacks(
my_caplog=caplog,
click_result=result,
allowed_deprecation_message=VALIDATION_OPERATORS_DEPRECATION_MESSAGE,
)


@pytest.mark.xfail(
reason="This command is not yet implemented for the modern API",
run=True,
strict=True,
@mock.patch(
"great_expectations.core.usage_statistics.usage_statistics.UsageStatisticsHandler.emit"
)
@mock.patch("webbrowser.open", return_value=True, side_effect=None)
def test_docs_build_assume_yes(
caplog, monkeypatch, site_builder_data_context_v013_with_html_store_titanic_random
mock_webbrowser,
mock_emit,
caplog,
monkeypatch,
titanic_data_context_stats_enabled_config_version_3,
):
context = site_builder_data_context_v013_with_html_store_titanic_random
context = titanic_data_context_stats_enabled_config_version_3

runner = CliRunner(mix_stderr=False)
monkeypatch.chdir(os.path.dirname(context.root_directory))
result = runner.invoke(
cli,
[
"--v3-api",
"--assume-yes",
"docs",
"build",
"--no-view",
],
"--v3-api --assume-yes docs build --no-view",
catch_exceptions=False,
)
stdout = result.stdout

assert result.exit_code == 0
assert mock_webbrowser.call_count == 0

assert "Would you like to proceed? [Y/n]:" not in stdout
# This assertion is extra assurance since this test is too permissive if we change the confirmation message
assert "[Y/n]" not in stdout

assert mock_emit.call_count == 3
assert mock_emit.call_args_list == [
mock.call(
{"event_payload": {}, "event": "data_context.__init__", "success": True}
),
mock.call(
{
"event_payload": {},
"event": "data_context.build_data_docs",
"success": True,
}
),
mock.call(
{
"event": "cli.docs.build",
"event_payload": {"api_version": "v3"},
"success": True,
}
),
]

assert_no_logging_messages_or_tracebacks(
my_caplog=caplog,
click_result=result,
allowed_deprecation_message=VALIDATION_OPERATORS_DEPRECATION_MESSAGE,
)


Expand Down

0 comments on commit 9879959

Please sign in to comment.