Skip to content

Commit

Permalink
Handle additional severity levels
Browse files Browse the repository at this point in the history
  • Loading branch information
joshtemple committed Mar 2, 2022
1 parent 303098b commit bd014cb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion spectacles/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ def _build_lookml_subparser(
)
subparser.add_argument(
"--severity",
choices=["info", "warning", "error"],
choices=["success", "info", "warning", "error", "fatal"],
default="warning",
help=(
"Specify a level of validation error severity to trigger test failure. "
Expand Down
4 changes: 2 additions & 2 deletions spectacles/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ def print_lookml_error(
) -> None:
if file_path is None:
file_path = "[File name not given by Looker]"
header_color = yellow if severity == "warning" else red
header_color = red if severity in ("fatal", "error") else yellow
print_header(
header_color(f"{file_path}:{line_number}"), LINE_WIDTH + COLOR_CODE_LENGTH
)
wrapped = textwrap.fill(f"{severity.title()}: {message}", LINE_WIDTH)
wrapped = textwrap.fill(f"[{severity.title()}] {message}", LINE_WIDTH)
logger.info(wrapped)
if lookml_url:
logger.info("\n" + f"LookML: {lookml_url}")
Expand Down
13 changes: 11 additions & 2 deletions spectacles/validators/lookml.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
from spectacles.exceptions import LookMLError

# Define constants for severity levels
SUCCESS = 0
INFO = 10
WARNING = 20
ERROR = 30
NAME_TO_LEVEL = {"info": INFO, "warning": WARNING, "error": ERROR}
FATAL = 40

NAME_TO_LEVEL = {
"success": SUCCESS,
"info": INFO,
"warning": WARNING,
"error": ERROR,
"fatal": FATAL,
}


class LookMLValidator:
Expand All @@ -22,7 +31,7 @@ def __init__(self, client: LookerClient):
self.client = client

def validate(self, project: str, severity: str = "warning") -> Dict[str, Any]:
severity_level = NAME_TO_LEVEL[severity]
severity_level: int = NAME_TO_LEVEL[severity]
validation_results = self.client.lookml_validation(project)
errors = []
lookml_url: Optional[str] = None
Expand Down

0 comments on commit bd014cb

Please sign in to comment.