def _generate_collapse_content_block(
        self,
        collapse_content_blocks: List[RenderedTableContent],
        validation_results: ExpectationSuiteValidationResult,
    ) -> CollapseContent:

        attrs = [
            ("batch_markers", "Batch Markers"),
            ("batch_kwargs", "Batch Kwargs"),
            ("batch_parameters", "Batch Parameters"),
            ("batch_spec", "Batch Spec"),
            ("batch_request", "Batch Definition"),
        ]

        for attr, header in attrs:
            if validation_results.meta.get(attr):
                table = self._render_nested_table_from_dict(
                    input_dict=validation_results.meta.get(attr),
                    header=header,
                )
                collapse_content_blocks.append(table)

        collapse_content_block = CollapseContent(
            **{
                "collapse_toggle_link": "Show more info...",
                "collapse": collapse_content_blocks,
                "styling": {
                    "body": {
                        "classes": ["card", "card-body"]
                    },
                    "classes": ["col-12", "p-1"],
                },
            })

        return collapse_content_block
Beispiel #2
0
    def _get_unexpected_statement(cls, evr):
        success = evr.success
        result = evr.result

        if evr.exception_info["raised_exception"]:
            exception_message_template_str = (
                "\n\n$expectation_type raised an exception:\n$exception_message"
            )

            exception_message = RenderedStringTemplateContent(
                **{
                    "content_block_type": "string_template",
                    "string_template": {
                        "template": exception_message_template_str,
                        "params": {
                            "expectation_type":
                            evr.expectation_config.expectation_type,
                            "exception_message":
                            evr.exception_info["exception_message"],
                        },
                        "tag": "strong",
                        "styling": {
                            "classes": ["text-danger"],
                            "params": {
                                "exception_message": {
                                    "tag": "code"
                                },
                                "expectation_type": {
                                    "classes":
                                    ["badge", "badge-danger", "mb-2"]
                                },
                            },
                        },
                    },
                })

            exception_traceback_collapse = CollapseContent(
                **{
                    "collapse_toggle_link":
                    "Show exception traceback...",
                    "collapse": [
                        RenderedStringTemplateContent(
                            **{
                                "content_block_type": "string_template",
                                "string_template": {
                                    "template":
                                    evr.exception_info["exception_traceback"],
                                    "tag":
                                    "code",
                                },
                            })
                    ],
                })

            return [exception_message, exception_traceback_collapse]

        if success or not result.get("unexpected_count"):
            return []
        else:
            unexpected_count = num_to_str(result["unexpected_count"],
                                          use_locale=True,
                                          precision=20)
            unexpected_percent = (
                num_to_str(result["unexpected_percent"], precision=4) + "%")
            element_count = num_to_str(result["element_count"],
                                       use_locale=True,
                                       precision=20)

            template_str = (
                "\n\n$unexpected_count unexpected values found. "
                "$unexpected_percent of $element_count total rows.")

            return [
                RenderedStringTemplateContent(
                    **{
                        "content_block_type": "string_template",
                        "string_template": {
                            "template": template_str,
                            "params": {
                                "unexpected_count": unexpected_count,
                                "unexpected_percent": unexpected_percent,
                                "element_count": element_count,
                            },
                            "tag": "strong",
                            "styling": {
                                "classes": ["text-danger"]
                            },
                        },
                    })
            ]
Beispiel #3
0
    def _render_expectation_meta_notes(cls, expectation):
        if not expectation.meta.get("notes"):
            return None
        else:
            collapse_link = RenderedStringTemplateContent(
                **{
                    "content_block_type": "string_template",
                    "string_template": {
                        "template": "$icon",
                        "params": {
                            "icon": ""
                        },
                        "styling": {
                            "params": {
                                "icon": {
                                    "classes":
                                    ["fas", "fa-comment", "text-info"],
                                    "tag": "i",
                                }
                            }
                        },
                    },
                })
            notes = expectation.meta["notes"]
            note_content = None

            if isinstance(notes, str):
                note_content = [notes]

            elif isinstance(notes, list):
                note_content = notes

            elif isinstance(notes, dict):
                if "format" in notes:
                    if notes["format"] == "string":
                        if isinstance(notes["content"], str):
                            note_content = [notes["content"]]
                        elif isinstance(notes["content"], list):
                            note_content = notes["content"]
                        else:
                            logger.warning(
                                "Unrecognized Expectation suite notes format. Skipping rendering."
                            )

                    elif notes["format"] == "markdown":
                        if isinstance(notes["content"], str):
                            note_content = [
                                RenderedMarkdownContent(
                                    **{
                                        "content_block_type": "markdown",
                                        "markdown": notes["content"],
                                        "styling": {
                                            "parent": {
                                                "styles": {
                                                    "color": "red"
                                                }
                                            }
                                        },
                                    })
                            ]
                        elif isinstance(notes["content"], list):
                            note_content = [
                                RenderedMarkdownContent(
                                    **{
                                        "content_block_type": "markdown",
                                        "markdown": note,
                                        "styling": {
                                            "parent": {}
                                        },
                                    }) for note in notes["content"]
                            ]
                        else:
                            logger.warning(
                                "Unrecognized Expectation suite notes format. Skipping rendering."
                            )
                else:
                    logger.warning(
                        "Unrecognized Expectation suite notes format. Skipping rendering."
                    )

            notes_block = TextContent(
                **{
                    "content_block_type": "text",
                    "subheader": "Notes:",
                    "text": note_content,
                    "styling": {
                        "classes": ["col-12", "mt-2", "mb-2"],
                        "parent": {
                            "styles": {
                                "list-style-type": "none"
                            }
                        },
                    },
                })

            return CollapseContent(
                **{
                    "collapse_toggle_link": collapse_link,
                    "collapse": [notes_block],
                    "inline_link": True,
                    "styling": {
                        "body": {
                            "classes": ["card", "card-body", "p-1"]
                        },
                        "parent": {
                            "styles": {
                                "list-style-type": "none"
                            }
                        },
                    },
                })
    def _render_expectation_types(cls, evrs, content_blocks) -> None:

        type_counts = defaultdict(int)

        for evr in evrs.results:
            type_counts[evr.expectation_config.expectation_type] += 1

        bullet_list_items = sorted(type_counts.items(),
                                   key=lambda kv: -1 * kv[1])

        bullet_list_items = [
            RenderedStringTemplateContent(
                **{
                    "content_block_type": "string_template",
                    "string_template": {
                        "template": "$expectation_type $expectation_count",
                        "params": {
                            "expectation_type": tr[0],
                            "expectation_count": tr[1],
                        },
                        "styling": {
                            "classes": [
                                "list-group-item",
                                "d-flex",
                                "justify-content-between",
                                "align-items-center",
                            ],
                            "params": {
                                "expectation_count": {
                                    "classes": [
                                        "badge",
                                        "badge-secondary",
                                        "badge-pill",
                                    ],
                                }
                            },
                        },
                    },
                    "styling": {
                        "parent": {
                            "styles": {
                                "list-style-type": "none"
                            }
                        }
                    },
                }) for tr in bullet_list_items
        ]

        bullet_list = RenderedBulletListContent(
            **{
                "content_block_type": "bullet_list",
                "bullet_list": bullet_list_items,
                "styling": {
                    "classes": ["col-12", "mt-1"],
                    "body": {
                        "classes": ["list-group"],
                    },
                },
            })

        bullet_list_collapse = CollapseContent(
            **{
                "collapse_toggle_link": "Show Expectation Types...",
                "collapse": [bullet_list],
                "styling": {
                    "classes": ["col-12", "p-1"]
                },
            })

        content_blocks.append(bullet_list_collapse)
    def _diagnostic_unexpected_statement_renderer(
        cls,
        configuration: ExpectationConfiguration = None,
        result: ExpectationValidationResult = None,
        language: str = None,
        runtime_configuration: dict = None,
        **kwargs,
    ):
        assert result, "Must provide a result object."

        success = result.success
        result = result.result

        if result.exception_info["raised_exception"]:
            exception_message_template_str = (
                "\n\n$expectation_type raised an exception:\n$exception_message"
            )

            exception_message = RenderedStringTemplateContent(
                **{
                    "content_block_type": "string_template",
                    "string_template": {
                        "template": exception_message_template_str,
                        "params": {
                            "expectation_type":
                            result.expectation_config.expectation_type,
                            "exception_message":
                            result.exception_info["exception_message"],
                        },
                        "tag": "strong",
                        "styling": {
                            "classes": ["text-danger"],
                            "params": {
                                "exception_message": {
                                    "tag": "code"
                                },
                                "expectation_type": {
                                    "classes":
                                    ["badge", "badge-danger", "mb-2"]
                                },
                            },
                        },
                    },
                })

            exception_traceback_collapse = CollapseContent(
                **{
                    "collapse_toggle_link":
                    "Show exception traceback...",
                    "collapse": [
                        RenderedStringTemplateContent(
                            **{
                                "content_block_type": "string_template",
                                "string_template": {
                                    "template":
                                    result.
                                    exception_info["exception_traceback"],
                                    "tag":
                                    "code",
                                },
                            })
                    ],
                })

            return [exception_message, exception_traceback_collapse]

        if success or not result_dict.get("unexpected_count"):
            return []
        else:
            unexpected_count = num_to_str(result_dict["unexpected_count"],
                                          use_locale=True,
                                          precision=20)
            unexpected_percent = (
                num_to_str(result_dict["unexpected_percent"], precision=4) +
                "%")
            element_count = num_to_str(result_dict["element_count"],
                                       use_locale=True,
                                       precision=20)

            template_str = (
                "\n\n$unexpected_count unexpected values found. "
                "$unexpected_percent of $element_count total rows.")

            return [
                RenderedStringTemplateContent(
                    **{
                        "content_block_type": "string_template",
                        "string_template": {
                            "template": template_str,
                            "params": {
                                "unexpected_count": unexpected_count,
                                "unexpected_percent": unexpected_percent,
                                "element_count": element_count,
                            },
                            "tag": "strong",
                            "styling": {
                                "classes": ["text-danger"]
                            },
                        },
                    })
            ]