def _render_table(cls, validation_results, content_blocks): content = ValidationResultsTableContentBlockRenderer.render( validation_results, include_column_name=False ) content_blocks.append(content) return [], content_blocks
def test_ValidationResultsTableContentBlockRenderer_render(titanic_profiled_name_column_evrs): validation_results_table = ValidationResultsTableContentBlockRenderer.render(titanic_profiled_name_column_evrs) assert isinstance(validation_results_table, RenderedComponentContent) assert validation_results_table.content_block_type == "table" assert len(validation_results_table.table) == 6 assert validation_results_table.header_row == ["Status", "Expectation", "Observed Value"] assert validation_results_table.styling == { 'body': {'classes': ['table']}, 'classes': ['ml-2', 'mr-2', 'mt-0', 'mb-0', 'table-responsive'] } assert json.dumps(validation_results_table.to_json_dict()).count("$icon") == 6
def test_ValidationResultsTableContentBlockRenderer_generate_expectation_row_happy_path(): evr = ExpectationValidationResult( success=True, result={ 'observed_value': True, 'element_count': 162, 'missing_count': 153, 'missing_percent': 94.44444444444444 }, exception_info={ 'raised_exception': False, 'exception_message': None, 'exception_traceback': None }, expectation_config=ExpectationConfiguration( expectation_type='expect_column_min_to_be_between', kwargs={ 'column': 'live', 'min_value': None, 'max_value': None, 'result_format': 'SUMMARY' }, meta={'BasicDatasetProfiler': {'confidence': 'very low'}} ) ) result = ValidationResultsTableContentBlockRenderer.render([evr]).to_json_dict() print(result) # Note: A better approach to testing would separate out styling into a separate test. assert result == { 'content_block_type': 'table', 'styling': { 'body': {'classes': ['table']}, 'classes': ['ml-2', 'mr-2', 'mt-0', 'mb-0', 'table-responsive', 'hide-succeeded-validations-column-section-target-child']}, 'table': [[{'content_block_type': 'string_template', 'styling': {'parent': {'classes': ['hide-succeeded-validation-target-child']}}, 'string_template': {'template': '$icon', 'params': {'icon': ''}, 'styling': { 'params': {'icon': {'classes': ['fas', 'fa-check-circle', 'text-success'], 'tag': 'i'}}}}}, {'content_block_type': 'string_template', 'string_template': { 'template': '$column minimum value may have any numerical value.', 'params': {"column": "live", "min_value": None, "max_value": None, "result_format": "SUMMARY", "parse_strings_as_datetimes": None}, 'styling': {'default': { 'classes': ['badge', 'badge-secondary']}, 'params': {'column': { 'classes': ['badge', 'badge-primary']}}}}}, 'True']], 'header_row': ['Status', 'Expectation', 'Observed Value']}
def test_ValidationResultsTableContentBlockRenderer_render( titanic_profiled_name_column_evrs): validation_results_table = ValidationResultsTableContentBlockRenderer.render( titanic_profiled_name_column_evrs) print(json.dumps(validation_results_table, indent=2)) assert type(validation_results_table) is RenderedComponentContent assert validation_results_table["content_block_type"] == "table" assert len(validation_results_table["table"]) == 6 assert validation_results_table["header_row"] == [ "Status", "Expectation", "Observed Value" ] assert validation_results_table["styling"] == { "body": { "classes": ["table"] }, "classes": ["m-3", "table-responsive"] } assert json.dumps(validation_results_table).count("$icon") == 6
def test_ValidationResultsTableContentBlockRenderer_render( titanic_profiled_name_column_evrs, ): validation_results_table = ValidationResultsTableContentBlockRenderer.render( titanic_profiled_name_column_evrs ) assert isinstance(validation_results_table, RenderedComponentContent) assert validation_results_table.content_block_type == "table" assert len(validation_results_table.table) == 6 assert validation_results_table.header_row == [ "Status", "Expectation", "Observed Value", ] assert validation_results_table.styling == { "body": {"classes": ["table"]}, "classes": ["ml-2", "mr-2", "mt-0", "mb-0", "table-responsive"], } assert json.dumps(validation_results_table.to_json_dict()).count("$icon") == 6
def test_ValidationResultsTableContentBlockRenderer_generate_expectation_row_with_errored_expectation( evr_failed_with_exception): result = ValidationResultsTableContentBlockRenderer.render( [evr_failed_with_exception]) print(json.dumps(result, indent=2)) assert result == { "content_block_type": "table", "table": [[{ "content_block_type": "string_template", "string_template": { "template": "$icon", "params": { "icon": "" }, "styling": { "params": { "icon": { "classes": ["fas", "fa-exclamation-triangle", "text-warning"], "tag": "i" } } } } }, [{ "content_block_type": "string_template", "string_template": { "template": "$column Column can match any distribution.", "params": { "column": "live", "partition_object": None, "threshold": None, "result_format": "SUMMARY" } } }, { "content_block_type": "string_template", "string_template": { "template": "\n\n$expectation_type raised an exception:\n$exception_message", "params": { "expectation_type": "expect_column_kl_divergence_to_be_less_than", "exception_message": "Invalid partition object." }, "tag": "strong", "styling": { "classes": ["text-danger"], "params": { "exception_message": { "tag": "code" }, "expectation_type": { "classes": ["badge", "badge-danger", "mb-2"] } } } } }, None], "--"]], "styling": { "body": { "classes": ["table"] }, "classes": ["m-3", "table-responsive"] }, "header_row": ["Status", "Expectation", "Observed Value"] }
def test_ValidationResultsTableContentBlockRenderer_generate_expectation_row_happy_path( ): evr = { 'success': True, 'result': { 'observed_value': True, 'element_count': 162, 'missing_count': 153, 'missing_percent': 0.9444444444444444 }, 'exception_info': { 'raised_exception': False, 'exception_message': None, 'exception_traceback': None }, 'expectation_config': { 'expectation_type': 'expect_column_min_to_be_between', 'kwargs': { 'column': 'live', 'min_value': None, 'max_value': None, 'result_format': 'SUMMARY' }, 'meta': { 'BasicDatasetProfiler': { 'confidence': 'very low' } } } } result = ValidationResultsTableContentBlockRenderer.render([evr]) # print(json.dumps(result, indent=2)) #Note: A better approach to testing would separate out styling into a separate test. assert result == { "content_block_type": "table", "table": [[{ "content_block_type": "string_template", "string_template": { "template": "$icon", "params": { "icon": "" }, "styling": { "params": { "icon": { "classes": ["fas", "fa-check-circle", "text-success"], "tag": "i" } } } } }, { "content_block_type": "string_template", "string_template": { "template": "$column minimum value may have any numerical value.", "params": { "column": "live", "min_value": None, "max_value": None, "result_format": "SUMMARY", "parse_strings_as_datetimes": None }, "styling": { "default": { "classes": ["badge", "badge-secondary"] }, "params": { "column": { "classes": ["badge", "badge-primary"] } } } } }, "True"]], "styling": { "body": { "classes": ["table"] }, "classes": ["m-3", "table-responsive"] }, "header_row": ["Status", "Expectation", "Observed Value"] }
def test_ValidationResultsTableContentBlockRenderer_generate_expectation_row_with_errored_expectation( evr_failed_with_exception, ): result = ValidationResultsTableContentBlockRenderer.render( [evr_failed_with_exception]).to_json_dict() print(result) expected_result = { "content_block_type": "table", "styling": { "body": { "classes": ["table"] }, "classes": ["ml-2", "mr-2", "mt-0", "mb-0", "table-responsive"], }, "table": [[ { "content_block_type": "string_template", "string_template": { "template": "$icon", "params": { "icon": "", "markdown_status_icon": "❗" }, "styling": { "params": { "icon": { "classes": [ "fas", "fa-exclamation-triangle", "text-warning", ], "tag": "i", } } }, }, }, [ { "content_block_type": "string_template", "string_template": { "template": "$column can match any distribution.", "params": { "column": "live", "partition_object": None, "threshold": None, "result_format": "SUMMARY", "row_condition": None, "condition_parser": None, }, }, }, { "content_block_type": "string_template", "string_template": { "template": "\n\n$expectation_type raised an exception:\n$exception_message", "params": { "expectation_type": "expect_column_kl_divergence_to_be_less_than", "exception_message": "Invalid partition object.", }, "tag": "strong", "styling": { "classes": ["text-danger"], "params": { "exception_message": { "tag": "code" }, "expectation_type": { "classes": ["badge", "badge-danger", "mb-2"] }, }, }, }, }, { "content_block_type": "collapse", "collapse_toggle_link": "Show exception traceback...", "collapse": [{ "content_block_type": "string_template", "string_template": { "template": 'Traceback (most recent call last):\n File "/great_expectations/great_expectations/data_asset/data_asset.py", line 216, in wrapper\n return_obj = func(self, **evaluation_args)\n File "/great_expectations/great_expectations/dataset/dataset.py", line 106, in inner_wrapper\n evaluation_result = func(self, column, *args, **kwargs)\n File "/great_expectations/great_expectations/dataset/dataset.py", line 3381, in expect_column_kl_divergence_to_be_less_than\n raise ValueError("Invalid partition object.")\nValueError: Invalid partition object.\n', "tag": "code", }, }], "inline_link": False, }, ], "--", ]], "header_row": ["Status", "Expectation", "Observed Value"], "header_row_options": { "Status": { "sortable": True } }, "table_options": { "search": True, "icon-size": "sm" }, } assert result == expected_result
def test_ValidationResultsTableContentBlockRenderer_generate_expectation_row_with_errored_expectation(evr_failed_with_exception): result = ValidationResultsTableContentBlockRenderer.render([evr_failed_with_exception]) print(json.dumps(result, indent=2)) assert result == { "content_block_type": "table", "table": [ [ { "content_block_type": "string_template", "string_template": { "template": "$icon", "params": { "icon": "" }, "styling": { "params": { "icon": { "classes": [ "fas", "fa-exclamation-triangle", "text-warning" ], "tag": "i" } } } } }, [ { "content_block_type": "string_template", "string_template": { "template": "$column Kullback-Leibler (KL) divergence with respect to a given distribution must be lower than a provided threshold but no distribution was specified.", "params": { "column": "live", "partition_object": None, "threshold": None, "result_format": "SUMMARY" }, "styling": { "default": { "classes": [ "badge", "badge-secondary" ] }, "params": { "sparklines_histogram": { "styles": { "font-family": "serif !important" } } } } } }, { "content_block_type": "string_template", "string_template": { "template": "Expectation failed to execute.", "params": {}, "tag": "strong", "styling": { "classes": [ "text-warning" ] } } }, None ], "--" ] ], "styling": { "body": { "classes": [ "table" ] }, "classes": [ "m-3", "table-responsive" ] }, "header_row": [ "Status", "Expectation", "Observed Value" ] }
def test_ValidationResultsTableContentBlockRenderer_generate_expectation_row_with_errored_expectation(evr_failed_with_exception): result = ValidationResultsTableContentBlockRenderer.render([evr_failed_with_exception]).to_json_dict() print(result) expected_result = { 'content_block_type': 'table', 'styling': { 'body': {'classes': ['table']}, 'classes': ['ml-2', 'mr-2', 'mt-0', 'mb-0', 'table-responsive']}, 'table': [[{ 'content_block_type': 'string_template', 'string_template': { 'template': '$icon', 'params': { 'icon': ''}, 'styling': { 'params': { 'icon': { 'classes': [ 'fas', 'fa-exclamation-triangle', 'text-warning'], 'tag': 'i'}}}}}, [{ 'content_block_type': 'string_template', 'string_template': { 'template': '$column can match any distribution.', 'params': { "column": "live", "partition_object": None, "threshold": None, "result_format": "SUMMARY"}}}, { 'content_block_type': 'string_template', 'string_template': { 'template': '\n\n$expectation_type raised an exception:\n$exception_message', 'params': { 'expectation_type': 'expect_column_kl_divergence_to_be_less_than', 'exception_message': 'Invalid partition object.'}, 'tag': 'strong', 'styling': { 'classes': [ 'text-danger'], 'params': { 'exception_message': { 'tag': 'code'}, 'expectation_type': { 'classes': [ 'badge', 'badge-danger', 'mb-2']}}}}}, { 'content_block_type': 'collapse', 'collapse_toggle_link': 'Show exception traceback...', 'collapse': [ { 'content_block_type': 'string_template', 'string_template': { 'template': 'Traceback (most recent call last):\n File "/great_expectations/great_expectations/data_asset/data_asset.py", line 216, in wrapper\n return_obj = func(self, **evaluation_args)\n File "/great_expectations/great_expectations/dataset/dataset.py", line 106, in inner_wrapper\n evaluation_result = func(self, column, *args, **kwargs)\n File "/great_expectations/great_expectations/dataset/dataset.py", line 3381, in expect_column_kl_divergence_to_be_less_than\n raise ValueError("Invalid partition object.")\nValueError: Invalid partition object.\n', 'tag': 'code'}}], 'inline_link': False}], '--']], 'header_row': ['Status', 'Expectation', 'Observed Value']} assert result == expected_result
def test_ValidationResultsTableContentBlockRenderer_generate_expectation_row_with_errored_expectation( ): evr = { 'success': False, 'exception_info': { 'raised_exception': True, 'exception_message': 'Invalid partition object.', 'exception_traceback': 'Traceback (most recent call last):\n File "/Users/abe/Documents/superconductive/tools/great_expectations/great_expectations/data_asset/data_asset.py", line 216, in wrapper\n return_obj = func(self, **evaluation_args)\n File "/Users/abe/Documents/superconductive/tools/great_expectations/great_expectations/dataset/dataset.py", line 106, in inner_wrapper\n evaluation_result = func(self, column, *args, **kwargs)\n File "/Users/abe/Documents/superconductive/tools/great_expectations/great_expectations/dataset/dataset.py", line 3381, in expect_column_kl_divergence_to_be_less_than\n raise ValueError("Invalid partition object.")\nValueError: Invalid partition object.\n' }, 'expectation_config': { 'expectation_type': 'expect_column_kl_divergence_to_be_less_than', 'kwargs': { 'column': 'live', 'partition_object': None, 'threshold': None, 'result_format': 'SUMMARY' }, 'meta': { 'BasicDatasetProfiler': { 'confidence': 'very low' } } } } result = ValidationResultsTableContentBlockRenderer.render([evr]) print(json.dumps(result, indent=2)) assert result == { "content_block_type": "table", "table": [[{ "content_block_type": "string_template", "string_template": { "template": "$icon", "params": { "icon": "" }, "styling": { "params": { "icon": { "classes": ["fas", "fa-exclamation-triangle", "text-warning"], "tag": "i" } } } } }, [{ "content_block_type": "string_template", "string_template": { "template": "$column Kullback-Leibler (KL) divergence with respect to a given distribution must be lower than a provided threshold but no distribution was specified.", "params": { "column": "live", "partition_object": None, "threshold": None, "result_format": "SUMMARY" }, "styling": { "default": { "classes": ["badge", "badge-secondary"] }, "params": { "sparklines_histogram": { "styles": { "font-family": "serif !important" } } } } } }, { "content_block_type": "string_template", "string_template": { "template": "Expectation failed to execute.", "params": {}, "tag": "strong", "styling": { "classes": ["text-warning"] } } }, None], "--"]], "styling": { "body": { "classes": ["table"] }, "classes": ["m-3", "table-responsive"] }, "header_row": ["Status", "Expectation", "Observed Value"] }