Skip to content

Commit

Permalink
Add basic expectations for error printing
Browse files Browse the repository at this point in the history
Use tmpdir for SQL logging

Try creating parents too

Mock logging call
  • Loading branch information
joshtemple committed Jun 20, 2020
1 parent 1d52909 commit 07a80ab
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions tests/test_printer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from unittest.mock import patch
from spectacles import printer
from spectacles.logger import delete_color_codes

Expand Down Expand Up @@ -37,3 +38,80 @@ def test_mark_line_even_number_of_lines():
result = printer.mark_line(lines=text, line_number=2)
result = [delete_color_codes(line) for line in result]
assert result == expected_result


@patch("spectacles.printer.log_sql_error", return_value="path_to_sql_file")
def test_sql_error_prints_with_relevant_info(mock_log, sql_error, caplog):
model = "model_a"
explore = "explore_a"
dimension = "view_a.dimension_a"
message = "A super important error occurred."

printer.print_sql_error(
model=model,
explore=explore,
message=message,
sql="SELECT * FROM test",
log_dir="logs",
)
assert "LookML:" not in caplog.text
assert model in caplog.text
assert explore in caplog.text
assert message in caplog.text
assert dimension not in caplog.text

printer.print_sql_error(
model=model,
explore=explore,
message=message,
sql="SELECT * FROM test",
log_dir=None,
lookml_url="https://spectacles.looker.com",
)
assert "LookML:" in caplog.text


def test_content_error_prints_with_relevant_info(sql_error, caplog):
model = "model_a"
explore = "explore_a"
content_type = "dashboard"
space = "Shared"
message = "A super important error occurred."
title = "My Dashboard"

printer.print_content_error(
model=model,
explore=explore,
message=message,
content_type=content_type,
space=space,
title=title,
url="https://spectacles.looker.com",
)
assert model in caplog.text
assert explore in caplog.text
assert content_type.title() in caplog.text
assert message in caplog.text
assert space in caplog.text
assert title in caplog.text


def test_data_test_error_prints_with_relevant_info(sql_error, caplog):
model = "model_a"
explore = "explore_a"
test_name = "assert_metric_is_positive"
message = "A super important error occurred."
lookml_url = "https://spectacles.looker.com"

printer.print_data_test_error(
model=model,
explore=explore,
test_name=test_name,
message=message,
lookml_url=lookml_url,
)
assert model in caplog.text
assert explore in caplog.text
assert test_name in caplog.text
assert message in caplog.text
assert lookml_url in caplog.text

0 comments on commit 07a80ab

Please sign in to comment.