def test_ExpectationSuiteColumnSectionRenderer_render_header( titanic_profiled_name_column_expectations): remaining_expectations, content_blocks = ExpectationSuiteColumnSectionRenderer._render_header( titanic_profiled_name_column_expectations, #["expectations"], [], ) print(json.dumps(content_blocks, indent=2)) assert content_blocks == [ RenderedComponentContent( **{ "content_block_type": "header", "header": "Name", "styling": { "classes": ["col-12"], "header": { "classes": ["alert", "alert-secondary"] } } }) ] expectation_with_unescaped_dollar_sign = { "expectation_type": "expect_column_values_to_be_in_type_list", "kwargs": { "column": "Car Insurance Premiums ($)", "type_list": [ "DOUBLE_PRECISION", "DoubleType", "FLOAT", "FLOAT4", "FLOAT8", "FloatType", "NUMERIC", "float" ], "result_format": "SUMMARY" }, "meta": { "BasicDatasetProfiler": { "confidence": "very low" } } } remaining_expectations, content_blocks = ExpectationSuiteColumnSectionRenderer._render_header( [expectation_with_unescaped_dollar_sign], []) print(content_blocks) assert content_blocks[0] == { 'content_block_type': 'header', 'header': 'Car Insurance Premiums ($$)', 'styling': { 'classes': ['col-12'], 'header': { 'classes': ['alert', 'alert-secondary'] } } }
def test_ExpectationSuiteColumnSectionRenderer_render_header(titanic_profiled_name_column_expectations): remaining_expectations, content_blocks = ExpectationSuiteColumnSectionRenderer._render_header( titanic_profiled_name_column_expectations, ) expected = {'content_block_type': 'header', 'styling': {'classes': ['col-12'], 'header': {'classes': ['alert', 'alert-secondary']}}, 'header': {'content_block_type': 'string_template', 'string_template': {'template': 'Name', 'tag': 'h5', 'styling': {'classes': ['m-0']}}}} print(content_blocks.to_json_dict()) assert content_blocks.to_json_dict() == expected expectation_with_unescaped_dollar_sign = ExpectationConfiguration( expectation_type="expect_column_values_to_be_in_type_list", kwargs={ "column": "Car Insurance Premiums ($)", "type_list": [ "DOUBLE_PRECISION", "DoubleType", "FLOAT", "FLOAT4", "FLOAT8", "FloatType", "NUMERIC", "float" ], "result_format": "SUMMARY" }, meta={ "BasicDatasetProfiler": { "confidence": "very low" } } ) remaining_expectations, content_blocks = ExpectationSuiteColumnSectionRenderer._render_header( [expectation_with_unescaped_dollar_sign], ) print(content_blocks.to_json_dict()) expected = { 'content_block_type': 'header', 'styling': { 'classes': ['col-12'], 'header': { 'classes': [ 'alert', 'alert-secondary']}}, 'header': {'content_block_type': 'string_template', 'string_template': { 'template': 'Car Insurance Premiums ($$)', 'tag': 'h5', 'styling': {'classes': ['m-0']}}}} assert content_blocks.to_json_dict() == expected
def test_render_expectation_suite_column_section_renderer( titanic_profiled_expectations_1, ): # Group expectations by column exp_groups = {} # print(json.dumps(titanic_profiled_expectations_1, indent=2)) for exp in titanic_profiled_expectations_1.expectations: try: column = exp.kwargs["column"] if column not in exp_groups: exp_groups[column] = [] exp_groups[column].append(exp) except KeyError: pass for column in exp_groups.keys(): with open( file_relative_path( __file__, "./output/test_render_expectation_suite_column_section_renderer" + column + ".json", ), "w", ) as outfile: json.dump( ExpectationSuiteColumnSectionRenderer().render( exp_groups[column]).to_json_dict(), outfile, indent=2, )
def test_ExpectationSuiteColumnSectionRenderer_render_bullet_list(titanic_profiled_name_column_expectations): remaining_expectations, content_block = ExpectationSuiteColumnSectionRenderer()._render_bullet_list( titanic_profiled_name_column_expectations,#["expectations"], ) assert content_block["content_block_type"] == "bullet_list" assert len(content_block["bullet_list"]) == 4 assert "value types must belong to this set" in json.dumps(content_block) assert "may have any number of unique values" in json.dumps(content_block) assert "may have any percentage of unique values" in json.dumps(content_block) assert "values must not be null, at least $mostly_pct % of the time." in json.dumps(content_block)
def test_ExpectationSuiteColumnSectionRenderer_render_bullet_list(titanic_profiled_name_column_expectations): remaining_expectations, content_block = ExpectationSuiteColumnSectionRenderer()._render_bullet_list( titanic_profiled_name_column_expectations, ) stringified_dump = json.dumps(content_block.to_json_dict()) assert content_block.content_block_type == "bullet_list" assert len(content_block.bullet_list) == 8 assert "value types must belong to this set" in stringified_dump assert "may have any number of unique values" in stringified_dump assert "may have any fraction of unique values" in stringified_dump assert "values must not be null, at least $mostly_pct % of the time." in stringified_dump
def test_render_expectation_suite_column_section_renderer(titanic_profiled_expectations_1): # Group expectations by column exp_groups = {} # print(json.dumps(titanic_profiled_expectations_1, indent=2)) for exp in titanic_profiled_expectations_1["expectations"]: try: column = exp["kwargs"]["column"] if column not in exp_groups: exp_groups[column] = [] exp_groups[column].append(exp) except KeyError: pass for column in exp_groups.keys(): with open('./tests/render/output/test_render_expectation_suite_column_section_renderer' + column + '.json', 'w') \ as outfile: json.dump(ExpectationSuiteColumnSectionRenderer().render(exp_groups[column]), outfile, indent=2)
def display_column_expectations_as_section( expectation_suite, column, include_styling=True, return_without_displaying=False, ): """This is a utility function to render all of the Expectations in an ExpectationSuite with the same column name as an HTML block. By default, the HTML block is rendered using ExpectationSuiteColumnSectionRenderer and the view is rendered using DefaultJinjaSectionView. Therefore, it should look exactly the same as the default renderer for build_docs. Example usage: exp = context.get_expectation_suite("notable_works_by_charles_dickens", "BasicDatasetProfiler") display_column_expectations_as_section(exp, "Type") """ #TODO: replace this with a generic utility function, preferably a method on an ExpectationSuite class column_expectation_list = [ e for e in expectation_suite.expectations if "column" in e.kwargs and e.kwargs["column"] == column ] #TODO: Handle the case where zero evrs match the column name document = ExpectationSuiteColumnSectionRenderer().render( column_expectation_list).to_json_dict() view = DefaultJinjaSectionView().render({ "section": document, "section_loop": 1 }) if include_styling: html_to_display = bootstrap_link_element + cooltip_style_element + view else: html_to_display = view if return_without_displaying: return html_to_display else: display(HTML(html_to_display))
def test_ExpectationSuiteColumnSectionRenderer_expectation_with_single_string_meta_note(): expectation_with_single_string_note = ExpectationConfiguration( expectation_type="expect_column_values_to_be_in_type_list", kwargs={ "column": "Car Insurance Premiums ($)", "type_list": [ "DOUBLE_PRECISION", "DoubleType", "FLOAT", "FLOAT4", "FLOAT8", "FloatType", "NUMERIC", "float" ], "result_format": "SUMMARY" }, meta={ "BasicDatasetProfiler": { "confidence": "very low" }, "notes": "This is a single string assigned to the 'notes' key." } ) expectations = [expectation_with_single_string_note] expected_result_json = { 'content_blocks': [ { 'content_block_type': 'header', 'styling': {'classes': ['col-12'], 'header': { 'classes': ['alert', 'alert-secondary']}}, 'header': {'content_block_type': 'string_template', 'string_template': { 'template': 'Car Insurance Premiums ($$)', 'tag': 'h5', 'styling': {'classes': ['m-0']}}}}, {'content_block_type': 'bullet_list', 'styling': {'classes': ['col-12']}, 'bullet_list': [[{'content_block_type': 'string_template', 'string_template': { 'template': 'value types must belong to this set: $v__0' ' $v__1 $v__2 $v__3 $v__4 $v__5 $v__6 $v__7.', 'params': {"column": "Car Insurance Premiums ($)", "type_list": ["DOUBLE_PRECISION", "DoubleType", "FLOAT", "FLOAT4", "FLOAT8", "FloatType", "NUMERIC", "float"], "result_format": "SUMMARY", "mostly": None, "v__0": "DOUBLE_PRECISION", "v__1": "DoubleType", "v__2": "FLOAT", "v__3": "FLOAT4", "v__4": "FLOAT8", "v__5": "FloatType", "v__6": "NUMERIC", "v__7": "float"}, 'styling': { 'default': { 'classes': ['badge', 'badge-secondary']}, 'params': {'column': {'classes': ['badge', 'badge-primary']}}}}}, {'content_block_type': 'collapse', 'styling': { 'body': {'classes': ['card', 'card-body', 'p-1']}, 'parent': {'styles': {'list-style-type': 'none'}}}, 'collapse_toggle_link': { 'content_block_type': 'string_template', 'string_template': {'template': '$icon', 'params': {'icon': ''}, 'styling': {'params': { 'icon': { 'classes': ['fas', 'fa-comment', 'text-info'], 'tag': 'i'}}}}}, 'collapse': [{'content_block_type': 'text', 'styling': { 'classes': ['col-12', 'mt-2', 'mb-2'], 'parent': { 'styles': { 'list-style-type': 'none'}}}, 'subheader': 'Notes:', 'text': [ "This is a single string assigned to the 'notes' key."]}], 'inline_link': True}], {'content_block_type': 'string_template', 'styling': { 'parent': {'styles': {'list-style-type': 'none'}}}, 'string_template': {'template': '', 'tag': 'hr', 'styling': {'classes': ['mt-1', 'mb-1']}}}]}], 'section_name': 'Car Insurance Premiums ($)'} result_json = ExpectationSuiteColumnSectionRenderer().render(expectations).to_json_dict() print(result_json) assert result_json == expected_result_json