def test_ValidationResultsTableContentBlockRenderer_get_unexpected_statement( evr_success, evr_failed): evr_no_result = ExpectationValidationResult( success=True, exception_info={ "raised_exception": False, "exception_message": None, "exception_traceback": None, }, expectation_config=ExpectationConfiguration( expectation_type="expect_table_row_count_to_be_between", kwargs={ "min_value": 0, "max_value": None, "result_format": "SUMMARY" }, ), ) evr_failed_no_unexpected_count = ExpectationValidationResult( success=False, result={ "element_count": 1313, "missing_count": 0, "missing_percent": 0.0, "unexpected_percent": 0.2284843869002285, "unexpected_percent_nonmissing": 0.2284843869002285, "partial_unexpected_list": [ "Daly, Mr Peter Denis ", "Barber, Ms ", "Geiger, Miss Emily ", ], "partial_unexpected_index_list": [77, 289, 303], "partial_unexpected_counts": [ { "value": "Barber, Ms ", "count": 1 }, { "value": "Daly, Mr Peter Denis ", "count": 1 }, { "value": "Geiger, Miss Emily ", "count": 1 }, ], }, exception_info={ "raised_exception": False, "exception_message": None, "exception_traceback": None, }, expectation_config=ExpectationConfiguration( expectation_type="expect_column_values_to_not_match_regex", kwargs={ "column": "Name", "regex": "^\\s+|\\s+$", "result_format": "SUMMARY", }, ), ) # test for succeeded evr output_1 = ValidationResultsTableContentBlockRenderer._get_unexpected_statement( evr_success) assert output_1 == [] # test for failed evr output_2 = ValidationResultsTableContentBlockRenderer._get_unexpected_statement( evr_failed) assert output_2 == [ RenderedStringTemplateContent( **{ "content_block_type": "string_template", "string_template": { "template": "\n\n$unexpected_count unexpected values found. $unexpected_percent of $element_count total rows.", "params": { "unexpected_count": "3", "unexpected_percent": "≈0.2285%", "element_count": "1,313", }, "tag": "strong", "styling": { "classes": ["text-danger"] }, }, }) ] # test for evr with no "result" key output_3 = ValidationResultsTableContentBlockRenderer._get_unexpected_statement( evr_no_result) print(json.dumps(output_3, indent=2)) assert output_3 == [] # test for evr with no unexpected count output_4 = ValidationResultsTableContentBlockRenderer._get_unexpected_statement( evr_failed_no_unexpected_count) print(output_4) assert output_4 == [] # test for evr with exception evr_failed_exception = ExpectationValidationResult( success=False, exception_info={ "raised_exception": True, "exception_message": "Unrecognized column: not_a_real_column", "exception_traceback": "Traceback (most recent call last):\n...more_traceback...", }, expectation_config=ExpectationConfiguration( expectation_type="expect_column_values_to_not_match_regex", kwargs={ "column": "Name", "regex": "^\\s+|\\s+$", "result_format": "SUMMARY", }, ), ) output_5 = ValidationResultsTableContentBlockRenderer._get_unexpected_statement( evr_failed_exception) output_5 = [content.to_json_dict() for content in output_5] expected_output_5 = [ { "content_block_type": "string_template", "string_template": { "template": "\n\n$expectation_type raised an exception:\n$exception_message", "params": { "expectation_type": "expect_column_values_to_not_match_regex", "exception_message": "Unrecognized column: not_a_real_column", }, "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...more_traceback...", "tag": "code", }, }], "inline_link": False, }, ] assert output_5 == expected_output_5
def test_ValidationResultsTableContentBlockRenderer_get_unexpected_statement( evr_success, evr_failed): evr_no_result = { "success": True, "exception_info": { "raised_exception": False, "exception_message": None, "exception_traceback": None }, "expectation_config": { "expectation_type": "expect_table_row_count_to_be_between", "kwargs": { "min_value": 0, "max_value": None, "result_format": "SUMMARY" } } } evr_failed_no_unexpected_count = { "success": False, "result": { "element_count": 1313, "missing_count": 0, "missing_percent": 0.0, "unexpected_percent": 0.2284843869002285, "unexpected_percent_nonmissing": 0.2284843869002285, "partial_unexpected_list": ["Daly, Mr Peter Denis ", "Barber, Ms ", "Geiger, Miss Emily "], "partial_unexpected_index_list": [77, 289, 303], "partial_unexpected_counts": [{ "value": "Barber, Ms ", "count": 1 }, { "value": "Daly, Mr Peter Denis ", "count": 1 }, { "value": "Geiger, Miss Emily ", "count": 1 }] }, "exception_info": { "raised_exception": False, "exception_message": None, "exception_traceback": None }, "expectation_config": { "expectation_type": "expect_column_values_to_not_match_regex", "kwargs": { "column": "Name", "regex": "^\\s+|\\s+$", "result_format": "SUMMARY" } } } # test for succeeded evr output_1 = ValidationResultsTableContentBlockRenderer._get_unexpected_statement( evr_success) assert output_1 is None # test for failed evr output_2 = ValidationResultsTableContentBlockRenderer._get_unexpected_statement( evr_failed) assert output_2 == { "content_block_type": "string_template", "string_template": { "template": "\n\n$unexpected_count unexpected values found. $unexpected_percent of $element_count total rows.", "params": { "unexpected_count": '3', "unexpected_percent": "≈0.2285%", "element_count": '1,313' }, "tag": "strong", "styling": { "classes": ["text-danger"] } } } # test for evr with no "result" key output_3 = ValidationResultsTableContentBlockRenderer._get_unexpected_statement( evr_no_result) print(json.dumps(output_3, indent=2)) assert output_3 == None # test for evr with no unexpected count output_4 = ValidationResultsTableContentBlockRenderer._get_unexpected_statement( evr_failed_no_unexpected_count) print(output_4) assert output_4 is None # test for evr with exception evr_failed_exception = { "success": False, "exception_info": { "raised_exception": True, "exception_message": "Unrecognized column: not_a_real_column", "exception_traceback": "Traceback (most recent call last):\n...more_traceback..." }, "expectation_config": { "expectation_type": "expect_column_values_to_not_match_regex", "kwargs": { "column": "Name", "regex": "^\\s+|\\s+$", "result_format": "SUMMARY" } } } output_5 = ValidationResultsTableContentBlockRenderer._get_unexpected_statement( evr_failed_exception) assert output_5 == { 'content_block_type': 'string_template', 'string_template': { 'template': '\n\n$expectation_type raised an exception:\n$exception_message', 'params': { 'expectation_type': 'expect_column_values_to_not_match_regex', 'exception_message': 'Unrecognized column: not_a_real_column' }, 'tag': 'strong', 'styling': { 'classes': ['text-danger'], 'params': { 'exception_message': { 'tag': 'code' }, 'expectation_type': { 'classes': ['badge', 'badge-danger', 'mb-2'] } } } } }
def test_ValidationResultsTableContentBlockRenderer_get_unexpected_statement(evr_success, evr_failed): evr_no_result = { "success": True, "exception_info": { "raised_exception": False, "exception_message": None, "exception_traceback": None }, "expectation_config": { "expectation_type": "expect_table_row_count_to_be_between", "kwargs": { "min_value": 0, "max_value": None, "result_format": "SUMMARY" } } } evr_failed_no_unexpected_count = { "success": False, "result": { "element_count": 1313, "missing_count": 0, "missing_percent": 0.0, "unexpected_percent": 0.002284843869002285, "unexpected_percent_nonmissing": 0.002284843869002285, "partial_unexpected_list": [ "Daly, Mr Peter Denis ", "Barber, Ms ", "Geiger, Miss Emily " ], "partial_unexpected_index_list": [ 77, 289, 303 ], "partial_unexpected_counts": [ { "value": "Barber, Ms ", "count": 1 }, { "value": "Daly, Mr Peter Denis ", "count": 1 }, { "value": "Geiger, Miss Emily ", "count": 1 } ] }, "exception_info": { "raised_exception": False, "exception_message": None, "exception_traceback": None }, "expectation_config": { "expectation_type": "expect_column_values_to_not_match_regex", "kwargs": { "column": "Name", "regex": "^\\s+|\\s+$", "result_format": "SUMMARY" } } } # test for succeeded evr output_1 = ValidationResultsTableContentBlockRenderer._get_unexpected_statement(evr_success) print(output_1) assert output_1 is None # test for failed evr output_2 = ValidationResultsTableContentBlockRenderer._get_unexpected_statement(evr_failed) print(json.dumps(output_2, indent=2)) assert output_2 == { "content_block_type": "string_template", "string_template": { "template": "\n\n$unexpected_count unexpected values found. $unexpected_percent of $element_count total rows.", "params": { "unexpected_count": 3, "unexpected_percent": "0.23%", "element_count": 1313 }, "tag": "strong", "styling": { "classes": [ "text-danger" ] } } } # test for evr with no "result" key output_3 = ValidationResultsTableContentBlockRenderer._get_unexpected_statement(evr_no_result) print(json.dumps(output_3, indent=2)) assert output_3 == { "content_block_type": "string_template", "string_template": { "template": "Expectation failed to execute.", "params": {}, "tag": "strong", "styling": { "classes": [ "text-warning" ] } } } # test for evr with no unexpected count output_4 = ValidationResultsTableContentBlockRenderer._get_unexpected_statement(evr_failed_no_unexpected_count) print(output_4) assert output_4 is None