Exemplo n.º 1
0
def display_column_evrs_as_section(
    evrs,
    column,
    include_styling=True,
    return_without_displaying=False,
):
    """
    Display validation results for a single column as a section.

    WARNING: This method is experimental.
    """

    #TODO: replace this with a generic utility function, preferably a method on an ExpectationSuite class
    column_evr_list = [
        e for e in evrs.results if "column" in e.expectation_config.kwargs
        and e.expectation_config.kwargs["column"] == column
    ]

    #TODO: Handle the case where zero evrs match the column name

    document = ValidationResultsColumnSectionRenderer().render(
        column_evr_list).to_json_dict()
    view = DefaultJinjaSectionView().render({
        "section": document,
        "section_loop": {
            "index": 1
        },
    })

    return _render_for_jupyter(
        view,
        include_styling,
        return_without_displaying,
    )
Exemplo n.º 2
0
def test_render_validation_results_column_section_renderer(
        titanic_profiler_evrs):
    # Group EVRs by column
    evrs = {}
    for evr in titanic_profiler_evrs.results:
        try:
            column = evr.expectation_config.kwargs["column"]
            if column not in evrs:
                evrs[column] = []
            evrs[column].append(evr)
        except KeyError:
            pass

    for column in evrs.keys():
        with open(
                file_relative_path(
                    __file__,
                    "./output/test_render_validation_results_column_section_renderer__"
                    + column + ".json",
                ),
                "w",
        ) as outfile:
            json.dump(
                ValidationResultsColumnSectionRenderer().render(
                    evrs[column]).to_json_dict(),
                outfile,
                indent=2,
            )
def test_ValidationResultsColumnSectionRenderer_render_header_evr_with_unescaped_dollar_sign(
        titanic_profiled_name_column_evrs):
    evr_with_unescaped_dollar_sign = ExpectationValidationResult(
        success=True,
        result={
            'element_count': 1313,
            'missing_count': 0,
            'missing_percent': 0.0,
            'unexpected_count': 0,
            'unexpected_percent': 0.0,
            'unexpected_percent_nonmissing': 0.0,
            'partial_unexpected_list': [],
            'partial_unexpected_index_list': [],
            'partial_unexpected_counts': []
        },
        exception_info={
            'raised_exception': False,
            'exception_message': None,
            'exception_traceback': None
        },
        expectation_config=ExpectationConfiguration(
            expectation_type='expect_column_values_to_be_in_type_list',
            kwargs={
                'column':
                'Name ($)',
                'type_list':
                ['CHAR', 'StringType', 'TEXT', 'VARCHAR', 'str', 'string'],
                'result_format':
                'SUMMARY'
            }))

    remaining_evrs, content_block = ValidationResultsColumnSectionRenderer._render_header(
        validation_results=[evr_with_unescaped_dollar_sign], )

    print(content_block.to_json_dict())

    assert content_block.to_json_dict() == {
        'content_block_type': 'header',
        'styling': {
            'classes': ['col-12', 'p-0'],
            'header': {
                'classes': ['alert', 'alert-secondary']
            }
        },
        'header': {
            'content_block_type': 'string_template',
            'string_template': {
                'template': 'Name ($$)',
                'tag': 'h5',
                'styling': {
                    'classes': ['m-0']
                }
            }
        }
    }
Exemplo n.º 4
0
def test_ValidationResultsColumnSectionRenderer_render_header(titanic_profiled_name_column_evrs):
    remaining_evrs, content_block = ValidationResultsColumnSectionRenderer._render_header(
        validation_results=titanic_profiled_name_column_evrs,
    )
    print(content_block.to_json_dict())
    assert content_block.to_json_dict() == {
        'content_block_type': 'header', 'styling': {'classes': ['col-12', 'p-0'],
                                                    'header': {'classes': ['alert',
                                                                           'alert-secondary']}},
        'header': {'content_block_type': 'string_template',
                   'string_template': {'template': 'Name', 'tag': 'h5',
                                       'styling': {'classes': ['m-0']}}}}
def test_ValidationResultsColumnSectionRenderer_render_header(
        titanic_profiled_name_column_evrs):
    remaining_evrs, content_block = ValidationResultsColumnSectionRenderer._render_header(
        validation_results=titanic_profiled_name_column_evrs, )

    assert content_block == {
        'content_block_type': 'header',
        'header': 'Name',
        'styling': {
            'classes': ['col-12'],
            'header': {
                'classes': ['alert', 'alert-secondary']
            }
        }
    }
Exemplo n.º 6
0
def test_render_validation_results_column_section_renderer(titanic_profiler_evrs):
    # Group EVRs by column
    evrs = {}
    for evr in titanic_profiler_evrs["results"]:
        try:
            column = evr["expectation_config"]["kwargs"]["column"]
            if column not in evrs:
                evrs[column] = []
            evrs[column].append(evr)
        except KeyError:
            pass

    for column in evrs.keys():
        with open('./tests/render/output/test_render_validation_results_column_section_renderer__' + column + '.json', 'w') \
                as outfile:
            json.dump(ValidationResultsColumnSectionRenderer().render(evrs[column]), outfile, indent=2)
Exemplo n.º 7
0
def test_ValidationResultsColumnSectionRenderer_render_table(titanic_profiled_name_column_evrs):
    remaining_evrs, content_block = ValidationResultsColumnSectionRenderer()._render_table(
        validation_results=titanic_profiled_name_column_evrs,
    )

    content_block_stringified = json.dumps(content_block.to_json_dict())

    assert content_block.content_block_type == "table"
    assert len(content_block.table) == 6
    assert content_block_stringified.count("$icon") == 6
    assert "value types must belong to this set: $v__0 $v__1 $v__2 $v__3 $v__4 $v__5." in content_block_stringified
    assert "may have any number of unique values." in content_block_stringified
    assert "may have any fraction of unique values." in content_block_stringified
    assert "values must not be null, at least $mostly_pct % of the time." in content_block_stringified
    assert "values must belong to this set: [ ]." in content_block_stringified
    assert "\\n\\n$unexpected_count unexpected values found. $unexpected_percent of $element_count total rows." in content_block_stringified
    assert "values must not match this regular expression: $regex." in content_block_stringified
    assert "\\n\\n$unexpected_count unexpected values found. $unexpected_percent of $element_count total rows." in content_block_stringified
def test_ValidationResultsColumnSectionRenderer_render_header(
        titanic_profiled_name_column_evrs):
    remaining_evrs, content_blocks = ValidationResultsColumnSectionRenderer._render_header(
        validation_results=titanic_profiled_name_column_evrs,
        content_blocks=[])

    print(json.dumps(content_blocks, indent=2))

    assert content_blocks == [{
        'content_block_type': 'header',
        'header': 'Name',
        'styling': {
            'classes': ['col-12'],
            'header': {
                'classes': ['alert', 'alert-secondary']
            }
        }
    }]

    evr_with_unescaped_dollar_sign = {
        'success': True,
        'result': {
            'element_count': 1313,
            'missing_count': 0,
            'missing_percent': 0.0,
            'unexpected_count': 0,
            'unexpected_percent': 0.0,
            'unexpected_percent_nonmissing': 0.0,
            'partial_unexpected_list': [],
            'partial_unexpected_index_list': [],
            'partial_unexpected_counts': []
        },
        'exception_info': {
            'raised_exception': False,
            'exception_message': None,
            'exception_traceback': None
        },
        'expectation_config': {
            'expectation_type': 'expect_column_values_to_be_in_type_list',
            'kwargs': {
                'column':
                'Name ($)',
                'type_list':
                ['CHAR', 'StringType', 'TEXT', 'VARCHAR', 'str', 'string'],
                'result_format':
                'SUMMARY'
            }
        }
    }

    remaining_evrs, content_blocks = ValidationResultsColumnSectionRenderer._render_header(
        validation_results=[evr_with_unescaped_dollar_sign], content_blocks=[])

    print(json.dumps(content_blocks, indent=2))

    assert content_blocks == [{
        'content_block_type': 'header',
        'header': 'Name ($$)',
        'styling': {
            'classes': ['col-12'],
            'header': {
                'classes': ['alert', 'alert-secondary']
            }
        }
    }]