def render_multiple_validation_result_pages_markdown(
    validation_operator_result: ValidationOperatorResult,
    run_info_at_end: bool = True,
):
    """
    Loop through and render multiple validation results to markdown.
    Args:
        validation_operator_result: (ValidationOperatorResult) Result of validation operator run
        run_info_at_end: move run info below expectation results

    Returns:
        string containing formatted markdown validation results

    """

    md_str = ""
    validation_results_page_renderer = ValidationResultsPageRenderer(
        run_info_at_end=run_info_at_end)
    for validation_result in validation_operator_result.list_validation_results(
    ):
        rendered_document_content = validation_results_page_renderer.render(
            validation_result)
        md_str += DefaultMarkdownPageView().render(
            rendered_document_content) + " "

    return md_str
Exemple #2
0
    def _ge_validation_fn(context, dataset):
        data_context = context.resources.ge_data_context
        validator_kwargs = {
            "datasource_name": datasource_name,
            "data_connector_name": data_connector_name,
            "data_asset_name": datasource_name or data_asset_name,
            "runtime_parameters": {
                runtime_method_type: dataset
            },
            "batch_identifiers": batch_identifiers,
            "expectation_suite_name": suite_name,
            **extra_kwargs,
        }
        validator = data_context.get_validator(**validator_kwargs)

        run_id = {
            "run_name": datasource_name + " run",
            "run_time": datetime.datetime.utcnow(),
        }
        results = validator.validate(run_id=run_id)

        validation_results_page_renderer = ValidationResultsPageRenderer(
            run_info_at_end=True)
        rendered_document_content_list = validation_results_page_renderer.render(
            validation_results=results)
        md_str = "".join(
            DefaultMarkdownPageView().render(rendered_document_content_list))

        meta_stats = MetadataEntry("Expectation Results",
                                   value=MetadataValue.md(md_str))
        yield ExpectationResult(
            success=bool(results["success"]),
            metadata_entries=[meta_stats],
        )
        yield Output(results.to_json_dict())
Exemple #3
0
def test_smoke_render_validation_results_page_renderer(titanic_profiler_evrs):
    rendered = ValidationResultsPageRenderer().render(titanic_profiler_evrs)
    with open(
            file_relative_path(
                __file__,
                "./output/test_render_validation_results_page_renderer.json"),
            "w",
    ) as outfile:
        json.dump(rendered.to_json_dict(), outfile, indent=2)
    assert len(rendered.sections) > 5
def test_snapshot_ValidationResultsPageRenderer_render_with_run_info_at_start(
    titanic_profiled_evrs_1,
    ValidationResultsPageRenderer_render_with_run_info_at_start,
):
    validation_results_page_renderer = ValidationResultsPageRenderer(
        run_info_at_end=False)
    rendered_validation_results = validation_results_page_renderer.render(
        titanic_profiled_evrs_1).to_json_dict()
    print(rendered_validation_results)
    # with open(file_relative_path(__file__, "./fixtures/ValidationResultsPageRenderer_render_with_run_info_at_start_nc.json"), "w") as f:
    #     json.dump(rendered_validation_results, f, indent=2)

    assert (rendered_validation_results ==
            ValidationResultsPageRenderer_render_with_run_info_at_start)
Exemple #5
0
def test_ValidationResultsPageRenderer_render_validation_info(
        titanic_profiled_evrs_1):
    validation_info = ValidationResultsPageRenderer._render_validation_info(
        titanic_profiled_evrs_1)
    print(json.dumps(validation_info, indent=2))

    expected_validation_info = {
        "content_block_type":
        "table",
        "header":
        "Info",
        "table": [["Full Data Asset Identifier", ""],
                  ["Expectation Suite Name", "default"],
                  ["Great Expectations Version", "0.7.3__develop"],
                  ["Run ID", "2019-07-26T205021.975202Z"],
                  ["Validation Succeeded", False]],
        "styling": {
            "classes": ["col-12", "table-responsive"],
            "styles": {
                "margin-top": "20px"
            },
            "body": {
                "classes": ["table", "table-sm"]
            }
        }
    }

    assert validation_info == expected_validation_info
def test_smoke_render_validation_results_page_renderer(titanic_profiler_evrs):
    rendered = ValidationResultsPageRenderer().render(titanic_profiler_evrs)
    with open(
            './tests/render/output/test_render_validation_results_page_renderer.json',
            'w') as outfile:
        json.dump(rendered, outfile, indent=2)
    assert len(rendered["sections"]) > 5
def test_ValidationResultsPageRenderer_render_validation_statistics(
    titanic_profiled_evrs_1, ):
    validation_statistics = ValidationResultsPageRenderer._render_validation_statistics(
        titanic_profiled_evrs_1).to_json_dict()
    # print(validation_statistics)
    expected_validation_statistics = {
        "content_block_type":
        "table",
        "styling": {
            "classes": ["col-6", "table-responsive", "mt-1", "p-1"],
            "body": {
                "classes": ["table", "table-sm"]
            },
        },
        "header": {
            "content_block_type": "string_template",
            "string_template": {
                "template": "Statistics",
                "tag": "h6",
                "styling": {
                    "classes": ["m-0"]
                },
            },
        },
        "table": [
            ["Evaluated Expectations", 51],
            ["Successful Expectations", 43],
            ["Unsuccessful Expectations", 8],
            ["Success Percent", "≈84.31%"],
        ],
    }

    assert validation_statistics == expected_validation_statistics
def test_ValidationResultsPageRenderer_render_validation_info(
        titanic_profiled_evrs_1):
    validation_info = ValidationResultsPageRenderer._render_validation_info(
        titanic_profiled_evrs_1).to_json_dict()
    print(validation_info)

    expected_validation_info = {
        'content_block_type':
        'table',
        'styling': {
            'classes': ['col-12', 'table-responsive', 'mt-1'],
            'body': {
                'classes': ['table', 'table-sm']
            }
        },
        'header': {
            'content_block_type': 'string_template',
            'string_template': {
                'template': 'Info',
                'tag': 'h6',
                'styling': {
                    'classes': ['m-0']
                }
            }
        },
        'table':
        [['Great Expectations Version', "0.9.0b1+310.g05637d48.dirty"],
         ['Run ID', "20200130T171315.316592Z"]]
    }

    assert validation_info == expected_validation_info
def test_ValidationResultsPageRenderer_render_validation_info(titanic_profiled_evrs_1):
    validation_info = ValidationResultsPageRenderer._render_validation_info(
        titanic_profiled_evrs_1
    ).to_json_dict()
    print(validation_info)

    expected_validation_info = {
        "content_block_type": "table",
        "styling": {
            "classes": ["col-12", "table-responsive", "mt-1"],
            "body": {
                "classes": ["table", "table-sm"],
                "styles": {
                    "margin-bottom": "0.5rem !important",
                    "margin-top": "0.5rem !important",
                },
            },
        },
        "header": {
            "content_block_type": "string_template",
            "string_template": {
                "template": "Info",
                "tag": "h6",
                "styling": {"classes": ["m-0"]},
            },
        },
        "table": [
            ["Great Expectations Version", "0.9.7+17.g02805059.dirty"],
            ["Run Name", "20200322T170247.671855Z"],
            ["Run Time", "2020-03-22T17:02:47.671855Z"],
        ],
    }

    assert validation_info == expected_validation_info
def test_snapshot_ValidationResultsPageRenderer_render_with_run_info_at_end(
    titanic_profiled_evrs_1,
    ValidationResultsPageRenderer_render_with_run_info_at_end,
):
    validation_results_page_renderer = ValidationResultsPageRenderer(
        run_info_at_end=True)
    rendered_validation_results = validation_results_page_renderer.render(
        titanic_profiled_evrs_1).to_json_dict()

    # replace version of vega-lite in res to match snapshot test
    content_block = rendered_validation_results["sections"][5][
        "content_blocks"][1]["table"][10][2]["content_blocks"][1]
    content_block["graph"]["$schema"] = re.sub(
        r"v\d*\.\d*\.\d*", "v4.8.1", content_block["graph"]["$schema"])
    assert (rendered_validation_results ==
            ValidationResultsPageRenderer_render_with_run_info_at_end)
def test_snapshot_ValidationResultsPageRenderer_render_with_run_info_at_end(
    titanic_profiled_evrs_1,
    ValidationResultsPageRenderer_render_with_run_info_at_end,
):
    validation_results_page_renderer = ValidationResultsPageRenderer(
        run_info_at_end=True)
    rendered_validation_results = validation_results_page_renderer.render(
        titanic_profiled_evrs_1).to_json_dict()
    import pprint

    pprint.pprint(rendered_validation_results["sections"])
    # with open(file_relative_path(__file__, "./fixtures/ValidationResultsPageRenderer_render_with_run_info_at_end_nc.json"), "w") as f:
    #     json.dump(rendered_validation_results, f, indent=2)
    pprint.pprint(ValidationResultsPageRenderer_render_with_run_info_at_end)
    assert (rendered_validation_results ==
            ValidationResultsPageRenderer_render_with_run_info_at_end)
def test_ValidationResultsPageRenderer_render_validation_info(
        titanic_profiled_evrs_1):
    validation_info = ValidationResultsPageRenderer._render_validation_info(
        titanic_profiled_evrs_1)
    print(json.dumps(validation_info, indent=2))

    expected_validation_info = {
        "content_block_type":
        "table",
        "header":
        "Info",
        "table":
        [[
            "Full Data Asset Identifier",
            "my_datasource/my_generator/titanic_data"
        ], ["Expectation Suite Name", "default"],
         ["Great Expectations Version", "__fixture__"],
         ["Run ID", "__run_id_fixture__"],
         [
             "Validation Status",
             "<i class=\"fas fa-times text-danger\" aria-hidden=\"true\"></i> Failed"
         ]],
        "styling": {
            "classes": ["col-12", "table-responsive"],
            "styles": {
                "margin-top": "20px"
            },
            "body": {
                "classes": ["table", "table-sm"]
            }
        }
    }

    assert validation_info == expected_validation_info
def test_ValidationResultsPageRenderer_render_validation_statistics(
        titanic_profiled_evrs_1):
    validation_statistics = ValidationResultsPageRenderer._render_validation_statistics(
        titanic_profiled_evrs_1).to_json_dict()
    # print(validation_statistics)
    expected_validation_statistics = {
        'content_block_type':
        'table',
        'styling': {
            'classes': ['col-6', 'table-responsive', 'mt-1', 'p-1'],
            'body': {
                'classes': ['table', 'table-sm']
            }
        },
        'header': {
            'content_block_type': 'string_template',
            'string_template': {
                'template': 'Statistics',
                'tag': 'h6',
                'styling': {
                    'classes': ['m-0']
                }
            }
        },
        'table': [['Evaluated Expectations', 51],
                  ['Successful Expectations', 43],
                  ['Unsuccessful Expectations', 8],
                  ['Success Percent', '≈84.31%']]
    }

    assert validation_statistics == expected_validation_statistics
def test_ValidationResultsPageRenderer_render_validation_statistics(
        titanic_profiled_evrs_1):
    validation_statistics = ValidationResultsPageRenderer._render_validation_statistics(
        titanic_profiled_evrs_1)
    print(json.dumps(validation_statistics, indent=2))

    expected_validation_statistics = {
        "content_block_type":
        "table",
        "header":
        "Statistics",
        "table": [["Evaluated Expectations", 51],
                  ["Successful Expectations", 43],
                  ["Unsuccessful Expectations", 8],
                  ["Success Percent", "≈84.31%"]],
        "styling": {
            "classes": ["col-6", "table-responsive"],
            "styles": {
                "margin-top": "20px"
            },
            "body": {
                "classes": ["table", "table-sm"]
            }
        }
    }

    assert validation_statistics == expected_validation_statistics
Exemple #15
0
def test_ValidationResultsPageRenderer_render_validation_header(titanic_profiled_evrs_1):
    validation_header = ValidationResultsPageRenderer._render_validation_header(titanic_profiled_evrs_1).to_json_dict()

    expected_validation_header = {
        'content_block_type': 'header',
        'styling': {
            'classes': ['col-12', 'p-0'], 'header': {
                'classes': ['alert', 'alert-secondary']}}, 'header': {'content_block_type': 'string_template',
                                                                      'string_template': {'template': 'Overview',
                                                                                          'tag': 'h5',
                                                                                          'styling': {
                                                                                              'classes': ['m-0']}}},
        'subheader': {'content_block_type': 'string_template', 'string_template': {
            'template': '${suite_title} ${expectation_suite_name}\n${status_title} ${success}',
            'params': {'suite_title': 'Expectation Suite:', 'status_title': 'Status:',
                       'expectation_suite_name': 'default',
                       'success': '<i class="fas fa-times text-danger" aria-hidden="true"></i> Failed'},
            'styling': {'params': {'suite_title': {'classes': ['h6']},
                                   'status_title': {'classes': ['h6']},
                                   'expectation_suite_name': {'tag': 'a', 'attributes': {
                                       'href': '../../../expectations/default.html'}}},
                        'classes': ['mb-0', 'mt-1']}}}}

    # print(validation_header)
    assert validation_header == expected_validation_header
Exemple #16
0
    def _ge_validation_fn(context, dataset):
        data_context = context.resources.ge_data_context
        if validation_operator_name is not None:
            validation_operator = validation_operator_name
        else:
            data_context.add_validation_operator(
                "ephemeral_validation",
                {
                    "class_name": "ActionListValidationOperator",
                    "action_list": []
                },
            )
            validation_operator = "ephemeral_validation"
        suite = data_context.get_expectation_suite(suite_name)
        final_batch_kwargs = batch_kwargs or {"dataset": dataset}
        if "datasource" in batch_kwargs:
            context.log.warning(
                "`datasource` field of `batch_kwargs` will be ignored; use the `datasource_name` "
                f"parameter of the {decorator_name} factory instead.")
        final_batch_kwargs["datasource"] = datasource_name
        batch = data_context.get_batch(final_batch_kwargs, suite)
        run_id = {
            "run_name": datasource_name + " run",
            "run_time": datetime.datetime.utcnow(),
        }
        results = data_context.run_validation_operator(
            validation_operator, assets_to_validate=[batch], run_id=run_id)
        res = convert_to_json_serializable(
            results.list_validation_results())[0]
        validation_results_page_renderer = ValidationResultsPageRenderer(
            run_info_at_end=True)
        rendered_document_content_list = (
            validation_results_page_renderer.render_validation_operator_result(
                results))
        md_str = " ".join(
            DefaultMarkdownPageView().render(rendered_document_content_list))

        meta_stats = MetadataEntry("Expectation Results",
                                   value=MetadataValue.md(md_str))
        yield ExpectationResult(
            success=res["success"],
            metadata_entries=[
                meta_stats,
            ],
        )
        yield Output(res)
def test_snapshot_ValidationResultsPageRenderer_render_with_run_info_at_start(
    titanic_profiled_evrs_1,
    ValidationResultsPageRenderer_render_with_run_info_at_start,
):
    validation_results_page_renderer = ValidationResultsPageRenderer(
        run_info_at_end=False)
    rendered_validation_results = validation_results_page_renderer.render(
        titanic_profiled_evrs_1).to_json_dict()

    # replace version of vega-lite in res to match snapshot test
    content_block = rendered_validation_results["sections"][5][
        "content_blocks"][1]["table"][10][2]["content_blocks"][1]
    content_block["graph"]["$schema"] = re.sub(
        r"v\d*\.\d*\.\d*", "v4.8.1", content_block["graph"]["$schema"])

    # with open(file_relative_path(__file__, "./fixtures/ValidationResultsPageRenderer_render_with_run_info_at_start_nc.json"), "w") as f:
    #     json.dump(rendered_validation_results, f, indent=2)

    assert (rendered_validation_results ==
            ValidationResultsPageRenderer_render_with_run_info_at_start)
Exemple #18
0
def test_render_validation_results(titanic_profiled_evrs_1):
    rendered_json = ValidationResultsPageRenderer.render(
        titanic_profiled_evrs_1)
    rendered_page = DefaultJinjaPageView.render(rendered_json)

    with open('./tests/render/output/test_render_validation_results.html',
              'w') as f:
        f.write(rendered_page)

    assert rendered_page[:15] == "<!DOCTYPE html>"
    assert rendered_page[-7:] == "</html>"
Exemple #19
0
def test_render_validation_results(titanic_profiled_evrs_1):
    rendered_content = ValidationResultsPageRenderer().render(titanic_profiled_evrs_1)
    rendered_page = DefaultJinjaPageView().render(rendered_content)

    with open(file_relative_path(__file__, './output/test_render_validation_results.html'), 'wb') as f:
        f.write(rendered_page.encode("utf-8"))

    assert rendered_page[:15] == "<!DOCTYPE html>"
    assert rendered_page[-7:] == "</html>"
    assert "Table-Level Expectations" in rendered_page
    assert 'Must have more than <span class="badge badge-secondary" >0</span> rows.' in rendered_page
Exemple #20
0
def test_ValidationResultsPageRenderer_render_validation_header():
    validation_header = {
        "content_block_type": "header",
        "header": "Validation Overview",
        "styling": {
            "classes": ["col-12"],
            "header": {
                "classes": ["alert", "alert-secondary"]
            }
        }
    }
    assert ValidationResultsPageRenderer._render_validation_header() == validation_header
Exemple #21
0
def test_render_validation_results(titanic_profiled_evrs_1):
    rendered_json = ValidationResultsPageRenderer().render(titanic_profiled_evrs_1)
    rendered_page = DefaultJinjaPageView().render(rendered_json)

    with open('./tests/render/output/test_render_validation_results.html', 'wb') as f:
        f.write(rendered_page.encode("utf-8"))

    assert rendered_page[:15] == "<!DOCTYPE html>"
    assert rendered_page[-7:] == "</html>"
    assert "Table-Level Expectations" in rendered_page
    assert 'Must have more than <span class="badge badge-secondary" >0</span> rows.' in rendered_page
    assert 'Must have between <span class="badge badge-secondary" >0</span> and <span class="badge badge-secondary" >23</span> columns.' in rendered_page
def test_ValidationResultsPageRenderer_render_validation_header(
    titanic_profiled_evrs_1,
):
    validation_header = ValidationResultsPageRenderer._render_validation_header(
        titanic_profiled_evrs_1
    ).to_json_dict()

    expected_validation_header = {
        "content_block_type": "header",
        "styling": {
            "classes": ["col-12", "p-0"],
            "header": {"classes": ["alert", "alert-secondary"]},
        },
        "header": {
            "content_block_type": "string_template",
            "string_template": {
                "template": "Overview",
                "tag": "h5",
                "styling": {"classes": ["m-0"]},
            },
        },
        "subheader": {
            "content_block_type": "string_template",
            "string_template": {
                "template": "${suite_title} ${expectation_suite_name}\n${status_title} ${html_success_icon} ${success}",
                "params": {
                    "suite_title": "Expectation Suite:",
                    "status_title": "Status:",
                    "expectation_suite_name": "default",
                    "success": "Failed",
                    "html_success_icon": '<i class="fas fa-times text-danger" aria-hidden="true"></i>',
                },
                "styling": {
                    "params": {
                        "suite_title": {"classes": ["h6"]},
                        "status_title": {"classes": ["h6"]},
                        "expectation_suite_name": {
                            "tag": "a",
                            "attributes": {
                                "href": "../../../../expectations/default.html"
                            },
                        },
                    },
                    "classes": ["mb-0", "mt-1"],
                },
            },
        },
    }

    # print(validation_header)
    assert validation_header == expected_validation_header
def render_multiple_validation_result_pages_markdown(
    validation_operator_result: ValidationOperatorResult,
    run_info_at_end: bool = True,
) -> str:
    """
    Loop through and render multiple validation results to markdown.
    Args:
        validation_operator_result: (ValidationOperatorResult) Result of validation operator run
        run_info_at_end: move run info below expectation results
    Returns:
        string containing formatted markdown validation results
    """

    # deprecated-v0.12.1
    warnings.warn(
        "This 'render_multiple_validation_result_pages_markdown' function is deprecated as of v0.12.1 and will be removed in v0.16."
        "Please use ValidationResultsPageRenderer.render_validation_operator_result() instead."
        "E.g. to replicate the functionality of rendering a ValidationOperatorResult to markdown:"
        "validation_results_page_renderer = ValidationResultsPageRenderer("
        "    run_info_at_end=run_info_at_end"
        ")"
        "rendered_document_content_list = validation_results_page_renderer.render_validation_operator_result("
        "   validation_operator_result=validation_operator_result"
        ")"
        'return " ".join(DefaultMarkdownPageView().render(rendered_document_content_list))',
        DeprecationWarning,
    )

    validation_results_page_renderer = ValidationResultsPageRenderer(
        run_info_at_end=run_info_at_end
    )
    rendered_document_content_list = (
        validation_results_page_renderer.render_validation_operator_result(
            validation_operator_result=validation_operator_result
        )
    )

    return " ".join(DefaultMarkdownPageView().render(rendered_document_content_list))
Exemple #24
0
def validate_csv_using_greatexpectations(
        csv_path: InputPath(),
        expectation_suite_path: InputPath(),
        data_doc_path: OutputPath(),
):
    """Validate a CSV dataset against a Great Expectations suite and create
    Data Doc (a validation report). This component fails if validation is not
    successful.

    Annotations:
        authors: Yaroslav Beshta <*****@*****.**>, Anton Kiselev <*****@*****.**>

    Args:
        csv_path: Path to the CSV file with the dataset.
        expectation_suite_path: Path to Great Expectations expectation suite (in JSON format)
    """
    import json
    import os
    import sys

    import great_expectations as ge
    from great_expectations.render import DefaultJinjaPageView
    from great_expectations.render.renderer import ValidationResultsPageRenderer

    with open(expectation_suite_path, 'r') as json_file:
        expectation_suite = json.load(json_file)
    df = ge.read_csv(csv_path, expectation_suite=expectation_suite)
    result = df.validate()

    document_model = ValidationResultsPageRenderer().render(result)
    os.makedirs(os.path.dirname(data_doc_path), exist_ok=True)
    with open(data_doc_path, 'w') as writer:
        writer.write(DefaultJinjaPageView().render(document_model))

    print(f'Saved: {data_doc_path}')

    if not result.success:
        sys.exit(1)
def test_ValidationResultsPageRenderer_render_nested_table_from_dict():
    batch_kwargs = {
        "path": "project_dir/project_path/data/titanic/Titanic.csv",
        "datasource": "Titanic",
        "reader_options": {"sep": None, "engine": "python"},
    }
    batch_kwargs_table = ValidationResultsPageRenderer._render_nested_table_from_dict(
        batch_kwargs, header="Batch Kwargs"
    ).to_json_dict()
    print(batch_kwargs_table)

    expected_batch_kwarg_table = {
        "content_block_type": "table",
        "styling": {
            "body": {
                "classes": ["table", "table-sm"],
                "styles": {
                    "margin-bottom": "0.5rem !important",
                    "margin-top": "0.5rem !important",
                },
            }
        },
        "header": {
            "content_block_type": "string_template",
            "string_template": {
                "template": "Batch Kwargs",
                "tag": "h6",
                "styling": {"classes": ["m-0"]},
            },
        },
        "table": [
            [
                {
                    "content_block_type": "string_template",
                    "styling": {"parent": {"classes": ["pr-3"]}},
                    "string_template": {
                        "template": "$value",
                        "params": {"value": "datasource"},
                        "styling": {"default": {"styles": {"word-break": "break-all"}}},
                    },
                },
                {
                    "content_block_type": "string_template",
                    "styling": {"parent": {"classes": []}},
                    "string_template": {
                        "template": "$value",
                        "params": {"value": "Titanic"},
                        "styling": {"default": {"styles": {"word-break": "break-all"}}},
                    },
                },
            ],
            [
                {
                    "content_block_type": "string_template",
                    "styling": {"parent": {"classes": ["pr-3"]}},
                    "string_template": {
                        "template": "$value",
                        "params": {"value": "path"},
                        "styling": {"default": {"styles": {"word-break": "break-all"}}},
                    },
                },
                {
                    "content_block_type": "string_template",
                    "styling": {"parent": {"classes": []}},
                    "string_template": {
                        "template": "$value",
                        "params": {
                            "value": "project_dir/project_path/data/titanic/Titanic.csv"
                        },
                        "styling": {"default": {"styles": {"word-break": "break-all"}}},
                    },
                },
            ],
            [
                {
                    "content_block_type": "string_template",
                    "styling": {"parent": {"classes": ["pr-3"]}},
                    "string_template": {
                        "template": "$value",
                        "params": {"value": "reader_options"},
                        "styling": {"default": {"styles": {"word-break": "break-all"}}},
                    },
                },
                {
                    "content_block_type": "table",
                    "styling": {
                        "classes": ["col-6", "table-responsive"],
                        "body": {"classes": ["table", "table-sm", "m-0"]},
                        "parent": {"classes": ["pt-0", "pl-0", "border-top-0"]},
                    },
                    "table": [
                        [
                            {
                                "content_block_type": "string_template",
                                "styling": {"parent": {"classes": ["pr-3"]}},
                                "string_template": {
                                    "template": "$value",
                                    "params": {"value": "engine"},
                                    "styling": {
                                        "default": {
                                            "styles": {"word-break": "break-all"}
                                        }
                                    },
                                },
                            },
                            {
                                "content_block_type": "string_template",
                                "styling": {"parent": {"classes": []}},
                                "string_template": {
                                    "template": "$value",
                                    "params": {"value": "python"},
                                    "styling": {
                                        "default": {
                                            "styles": {"word-break": "break-all"}
                                        }
                                    },
                                },
                            },
                        ],
                        [
                            {
                                "content_block_type": "string_template",
                                "styling": {"parent": {"classes": ["pr-3"]}},
                                "string_template": {
                                    "template": "$value",
                                    "params": {"value": "sep"},
                                    "styling": {
                                        "default": {
                                            "styles": {"word-break": "break-all"}
                                        }
                                    },
                                },
                            },
                            {
                                "content_block_type": "string_template",
                                "styling": {"parent": {"classes": []}},
                                "string_template": {
                                    "template": "$value",
                                    "params": {"value": "None"},
                                    "styling": {
                                        "default": {
                                            "styles": {"word-break": "break-all"}
                                        }
                                    },
                                },
                            },
                        ],
                    ],
                },
            ],
        ],
    }

    assert batch_kwargs_table == expected_batch_kwarg_table
Exemple #26
0
def test_ValidationResultsPageRenderer_render_nested_table_from_dict():
    batch_kwargs = {
        "path": "project_dir/project_path/data/titanic/Titanic.csv",
        "datasource": "Titanic",
        "reader_options": {
            "sep": None,
            "engine": "python"
        }
    }
    batch_kwargs_table = ValidationResultsPageRenderer._render_nested_table_from_dict(
        batch_kwargs, header="Batch Kwargs").to_json_dict()
    print(batch_kwargs_table)

    expected_batch_kwarg_table = {
        'content_block_type': 'table',
        'styling': {'classes': ['col-6', 'table-responsive', 'mt-1'],
                    'body': {'classes': ['table', 'table-sm']}},
        'header': {'content_block_type': 'string_template',
                   'string_template': {'template': 'Batch Kwargs', 'tag': 'h6',
                                       'styling': {'classes': ['m-0']}}}, 'table': [[{
            'content_block_type': 'string_template',
            'styling': {
                'parent': {
                    'classes': [
                        'pr-3']}},
            'string_template': {
                'template': '$value',
                'params': {
                    'value': 'datasource'},
                'styling': {
                    'default': {
                        'styles': {
                            'word-break': 'break-all'}}}}},
            {
                'content_block_type': 'string_template',
                'styling': {
                    'parent': {
                        'classes': []}},
                'string_template': {
                    'template': '$value',
                    'params': {
                        'value': 'Titanic'},
                    'styling': {
                        'default': {
                            'styles': {
                                'word-break': 'break-all'}}}}}],
            [{
                'content_block_type': 'string_template',
                'styling': {
                    'parent': {
                        'classes': [
                            'pr-3']}},
                'string_template': {
                    'template': '$value',
                    'params': {
                        'value': 'path'},
                    'styling': {
                        'default': {
                            'styles': {
                                'word-break': 'break-all'}}}}},
                {
                    'content_block_type': 'string_template',
                    'styling': {
                        'parent': {
                            'classes': []}},
                    'string_template': {
                        'template': '$value',
                        'params': {
                            'value': 'project_dir/project_path/data/titanic/Titanic.csv'},
                        'styling': {
                            'default': {
                                'styles': {
                                    'word-break': 'break-all'}}}}}],
            [{
                'content_block_type': 'string_template',
                'styling': {
                    'parent': {
                        'classes': [
                            'pr-3']}},
                'string_template': {
                    'template': '$value',
                    'params': {
                        'value': 'reader_options'},
                    'styling': {
                        'default': {
                            'styles': {
                                'word-break': 'break-all'}}}}},
                {
                    'content_block_type': 'table',
                    'styling': {
                        'classes': [
                            'col-6',
                            'table-responsive'],
                        'body': {
                            'classes': [
                                'table',
                                'table-sm',
                                'm-0']},
                        'parent': {
                            'classes': [
                                'pt-0',
                                'pl-0',
                                'border-top-0']}},
                    'table': [
                        [
                            {
                                'content_block_type': 'string_template',
                                'styling': {
                                    'parent': {
                                        'classes': [
                                            'pr-3']}},
                                'string_template': {
                                    'template': '$value',
                                    'params': {
                                        'value': 'engine'},
                                    'styling': {
                                        'default': {
                                            'styles': {
                                                'word-break': 'break-all'}}}}},
                            {
                                'content_block_type': 'string_template',
                                'styling': {
                                    'parent': {
                                        'classes': []}},
                                'string_template': {
                                    'template': '$value',
                                    'params': {
                                        'value': 'python'},
                                    'styling': {
                                        'default': {
                                            'styles': {
                                                'word-break': 'break-all'}}}}}],
                        [
                            {
                                'content_block_type': 'string_template',
                                'styling': {
                                    'parent': {
                                        'classes': [
                                            'pr-3']}},
                                'string_template': {
                                    'template': '$value',
                                    'params': {
                                        'value': 'sep'},
                                    'styling': {
                                        'default': {
                                            'styles': {
                                                'word-break': 'break-all'}}}}},
                            {
                                'content_block_type': 'string_template',
                                'styling': {
                                    'parent': {
                                        'classes': []}},
                                'string_template': {
                                    'template': '$value',
                                    'params': {
                                        'value': 'None'},
                                    'styling': {
                                        'default': {
                                            'styles': {
                                                'word-break': 'break-all'}}}}}]]}]]}

    assert batch_kwargs_table == expected_batch_kwarg_table
def test_ValidationResultsPageRenderer_render_nested_table_from_dict(
        titanic_profiled_evrs_1):
    batch_kwargs_table = ValidationResultsPageRenderer._render_nested_table_from_dict(
        titanic_profiled_evrs_1["meta"]["batch_kwargs"], header="Batch Kwargs")
    print(json.dumps(batch_kwargs_table, indent=2))

    expected_batch_kwarg_table = {
        "content_block_type":
        "table",
        "header":
        "Batch Kwargs",
        "table":
        [[{
            "content_block_type": "string_template",
            "string_template": {
                "template": "$value",
                "params": {
                    "value": "partition_id"
                },
                "styling": {
                    "default": {
                        "styles": {
                            "word-break": "break-all"
                        }
                    }
                }
            },
            "styling": {
                "parent": {
                    "classes": ["pr-3"]
                }
            }
        },
          {
              "content_block_type": "string_template",
              "string_template": {
                  "template": "$value",
                  "params": {
                      "value": "Titanic"
                  },
                  "styling": {
                      "default": {
                          "styles": {
                              "word-break": "break-all"
                          }
                      }
                  }
              },
              "styling": {
                  "parent": {
                      "classes": []
                  }
              }
          }],
         [{
             "content_block_type": "string_template",
             "string_template": {
                 "template": "$value",
                 "params": {
                     "value":
                     "path"
                 },
                 "styling": {
                     "default": {
                         "styles": {
                             "word-break": "break-all"
                         }
                     }
                 }
             },
             "styling": {
                 "parent": {
                     "classes": ["pr-3"]
                 }
             }
         }, {
             "content_block_type": "string_template",
             "string_template": {
                 "template": "$value",
                 "params":
                 {
                     "value":
                     "project_dir/project_path/data/titanic/Titanic.csv"
                 },
                 "styling": {
                     "default": {
                         "styles": {
                             "word-break": "break-all"
                         }
                     }
                 }
             },
             "styling": {
                 "parent": {
                     "classes": []
                 }
             }
         }],
         [{
             "content_block_type": "string_template",
             "string_template": {
                 "template": "$value",
                 "params": {
                     "value": "reader_options"
                 },
                 "styling": {
                     "default": {
                         "styles": {
                             "word-break": "break-all"
                         }
                     }
                 }
             },
             "styling": {
                 "parent": {
                     "classes": ["pr-3"]
                 }
             }
         }, {
             "content_block_type":
             "table",
             "table": [[{
                 "content_block_type": "string_template",
                 "string_template": {
                     "template": "$value",
                     "params": {
                         "value": "engine"
                     },
                     "styling": {
                         "default": {
                             "styles": {
                                 "word-break": "break-all"
                             }
                         }
                     }
                 },
                 "styling": {
                     "parent": {
                         "classes": ["pr-3"]
                     }
                 }
             }, {
                 "content_block_type": "string_template",
                 "string_template": {
                     "template": "$value",
                     "params": {
                         "value": "python"
                     },
                     "styling": {
                         "default": {
                             "styles": {
                                 "word-break": "break-all"
                             }
                         }
                     }
                 },
                 "styling": {
                     "parent": {
                         "classes": []
                     }
                 }
             }],
                       [{
                           "content_block_type": "string_template",
                           "string_template": {
                               "template": "$value",
                               "params": {
                                   "value": "sep"
                               },
                               "styling": {
                                   "default": {
                                       "styles": {
                                           "word-break": "break-all"
                                       }
                                   }
                               }
                           },
                           "styling": {
                               "parent": {
                                   "classes": ["pr-3"]
                               }
                           }
                       }, {
                           "content_block_type": "string_template",
                           "string_template": {
                               "template": "$value",
                               "params": {
                                   "value": "None"
                               },
                               "styling": {
                                   "default": {
                                       "styles": {
                                           "word-break": "break-all"
                                       }
                                   }
                               }
                           },
                           "styling": {
                               "parent": {
                                   "classes": []
                               }
                           }
                       }]],
             "styling": {
                 "classes": ["col-12", "table-responsive"],
                 "body": {
                     "classes": ["table", "table-sm", "m-0"]
                 },
                 "parent": {
                     "classes": ["pt-0", "pl-0", "border-top-0"]
                 }
             }
         }]],
        "styling": {
            "classes": ["col-12", "table-responsive"],
            "styles": {
                "margin-top": "20px"
            },
            "body": {
                "classes": ["table", "table-sm"]
            }
        }
    }

    assert batch_kwargs_table == expected_batch_kwarg_table
def test_snapshot_render_section_page_with_fixture_data(
        validation_operator_result):
    """
    Make sure the appropriate markdown rendering is done for the applied fixture.
    Args:
        validation_operator_result: test fixture

    Returns: None

    """

    validation_operator_result = ValidationOperatorResult(
        **validation_operator_result)

    validation_results_page_renderer = ValidationResultsPageRenderer(
        run_info_at_end=True)

    rendered_document_content_list = validation_results_page_renderer.render_validation_operator_result(
        validation_operator_result=validation_operator_result)

    md_str_list = DefaultMarkdownPageView().render(
        rendered_document_content_list)

    md_str = " ".join(md_str_list)

    md_str = md_str.replace(" ", "").replace("\t", "").replace("\n", "")

    print(md_str)

    assert (md_str == """
# Validation Results




## Overview
### **Expectation Suite:** **basic.warning**
**Data asset:** **None**
**Status:**  **Failed**





### Statistics






 |  |  |
 | ------------  | ------------ |
Evaluated Expectations  | 11
Successful Expectations  | 9
Unsuccessful Expectations  | 2
Success Percent  | ≈81.82%





## Table-Level Expectations








 | Status | Expectation | Observed Value |
 | ------------  | ------------  | ------------ |
❌  | Must have greater than or equal to **27000** and less than or equal to **33000** rows.  | 30
✅  | Must have exactly **3** columns.  | 3
✅  | Must have these columns in this order: **Team**, ** "Payroll (millions)"**, ** "Wins"**  | ['Team', ' "Payroll (millions)"', ' "Wins"']





##  "Payroll (millions)"








 | Status | Expectation | Observed Value |
 | ------------  | ------------  | ------------ |
✅  | values must never be null.  | 100% not null
✅  | minimum value must be greater than or equal to **54.24** and less than or equal to **56.24**.  | 55.24
✅  | maximum value must be greater than or equal to **196.96** and less than or equal to **198.96**.  | 197.96
✅  | mean must be greater than or equal to **97.01899999999998** and less than or equal to **99.01899999999998**.  | ≈98.019
❌  | median must be greater than or equal to **84000.75** and less than or equal to **86000.75**.  | 85.75
✅  | quantiles must be within the following value ranges.




 | Quantile | Min Value | Max Value |
 | ------------  | ------------  | ------------ |
0.05  | 54.37  | 56.37
Q1  | 74.48  | 76.48
Median  | 82.31  | 84.31
Q3  | 116.62  | 118.62
0.95  | 173.54  | 175.54
  |




 | Quantile | Value |
 | ------------  | ------------ |
0.05  | 55.37
Q1  | 75.48
Median  | 83.31
Q3  | 117.62
0.95  | 174.54






## Team








 | Status | Expectation | Observed Value |
 | ------------  | ------------  | ------------ |
✅  | values must never be null.  | 100% not null
✅  | values must always be greater than or equal to **1** characters long.  | 0% unexpected







### Info






 |  |  |
 | ------------  | ------------ |
Great Expectations Version  | 0.11.8+4.g4ab34df3.dirty
Run Name  | getest run
Run Time  | 2020-07-27T17:19:32.959193+00:00





### Batch Markers






 |  |  |
 | ------------  | ------------ |
**ge_load_time**  | **20200727T171932.954810Z**
**pandas_data_fingerprint**  | **8c46fdaf0bd356fd58b7bcd9b2e6012d**





### Batch Kwargs






 |  |  |
 | ------------  | ------------ |
**PandasInMemoryDF**  | **True**
**datasource**  | **getest**
**ge_batch_id**  | **56615f40-d02d-11ea-b6ea-acde48001122**




-----------------------------------------------------------
Powered by [Great Expectations](https://greatexpectations.io/)
# Validation Results




## Overview
### **Expectation Suite:** **basic.warning**
**Data asset:** **None**
**Status:**  **Failed**





### Statistics






 |  |  |
 | ------------  | ------------ |
Evaluated Expectations  | 11
Successful Expectations  | 9
Unsuccessful Expectations  | 2
Success Percent  | ≈81.82%





## Table-Level Expectations








 | Status | Expectation | Observed Value |
 | ------------  | ------------  | ------------ |
❌  | Must have greater than or equal to **27000** and less than or equal to **33000** rows.  | 30
✅  | Must have exactly **3** columns.  | 3
✅  | Must have these columns in this order: **Team**, ** "Payroll (millions)"**, ** "Wins"**  | ['Team', ' "Payroll (millions)"', ' "Wins"']





##  "Payroll (millions)"








 | Status | Expectation | Observed Value |
 | ------------  | ------------  | ------------ |
✅  | values must never be null.  | 100% not null
✅  | minimum value must be greater than or equal to **54.24** and less than or equal to **56.24**.  | 55.24
✅  | maximum value must be greater than or equal to **196.96** and less than or equal to **198.96**.  | 197.96
✅  | mean must be greater than or equal to **97.01899999999998** and less than or equal to **99.01899999999998**.  | ≈98.019
❌  | median must be greater than or equal to **84000.75** and less than or equal to **86000.75**.  | 85.75
✅  | quantiles must be within the following value ranges.




 | Quantile | Min Value | Max Value |
 | ------------  | ------------  | ------------ |
0.05  | 54.37  | 56.37
Q1  | 74.48  | 76.48
Median  | 82.31  | 84.31
Q3  | 116.62  | 118.62
0.95  | 173.54  | 175.54
  |




 | Quantile | Value |
 | ------------  | ------------ |
0.05  | 55.37
Q1  | 75.48
Median  | 83.31
Q3  | 117.62
0.95  | 174.54






## Team








 | Status | Expectation | Observed Value |
 | ------------  | ------------  | ------------ |
✅  | values must never be null.  | 100% not null
✅  | values must always be greater than or equal to **1** characters long.  | 0% unexpected







### Info






 |  |  |
 | ------------  | ------------ |
Great Expectations Version  | 0.11.8+4.g4ab34df3.dirty
Run Name  | getest run
Run Time  | 2020-07-27T17:19:32.959193+00:00





### Batch Markers






 |  |  |
 | ------------  | ------------ |
**ge_load_time**  | **20200727T171932.954810Z**
**pandas_data_fingerprint**  | **8c46fdaf0bd356fd58b7bcd9b2e6012d**





### Batch Kwargs






 |  |  |
 | ------------  | ------------ |
**PandasInMemoryDF**  | **True**
**datasource**  | **getest**
**ge_batch_id**  | **56615f40-d02d-11ea-b6ea-acde48001122**




-----------------------------------------------------------
Powered by [Great Expectations](https://greatexpectations.io/)
""".replace(" ", "").replace("\t", "").replace("\n", ""))