def _render_unrecognized(cls, evrs, content_blocks): unrendered_blocks = [] new_block = None for evr in evrs: if evr.expectation_config.expectation_type not in [ "expect_column_to_exist", "expect_column_values_to_be_of_type", "expect_column_values_to_be_in_set", "expect_column_unique_value_count_to_be_between", "expect_column_proportion_of_unique_values_to_be_between", "expect_column_values_to_not_be_null", "expect_column_max_to_be_between", "expect_column_mean_to_be_between", "expect_column_min_to_be_between" ]: new_block = TextContent(**{ "content_block_type": "text", "text": [] }) new_block["content"].append(""" <div class="alert alert-primary" role="alert"> Warning! Unrendered EVR:<br/> <pre>""" + json.dumps(evr, indent=2) + """</pre> </div> """) if new_block is not None: unrendered_blocks.append(new_block) # print(unrendered_blocks) content_blocks += unrendered_blocks
def _render_expectation_suite_notes(cls, expectations): content = [] total_expectations = len(expectations.expectations) columns = [] for exp in expectations.expectations: if "column" in exp.kwargs: columns.append(exp.kwargs["column"]) total_columns = len(set(columns)) content += [ # TODO: Leaving these two paragraphs as placeholders for later development. # "This Expectation suite was first generated by {BasicDatasetProfiler} on {date}, using version {xxx} of Great Expectations.", # "{name}, {name}, and {name} have also contributed additions and revisions.", "This Expectation suite currently contains %d total Expectations across %d columns." % ( total_expectations, total_columns, ), ] if "notes" in expectations.meta: notes = expectations.meta["notes"] note_content = None if isinstance(notes, str): note_content = [notes] elif isinstance(notes, list): note_content = notes elif isinstance(notes, dict): if "format" in notes: if notes["format"] == "string": if isinstance(notes["content"], str): note_content = [notes["content"]] elif isinstance(notes["content"], list): note_content = notes["content"] else: logger.warning( "Unrecognized Expectation suite notes format. Skipping rendering." ) elif notes["format"] == "markdown": if isinstance(notes["content"], str): note_content = [ RenderedMarkdownContent( **{ "content_block_type": "markdown", "markdown": notes["content"], "styling": { "parent": {} }, }) ] elif isinstance(notes["content"], list): note_content = [ RenderedMarkdownContent( **{ "content_block_type": "markdown", "markdown": note, "styling": { "parent": {} }, }) for note in notes["content"] ] else: logger.warning( "Unrecognized Expectation suite notes format. Skipping rendering." ) else: logger.warning( "Unrecognized Expectation suite notes format. Skipping rendering." ) if note_content is not None: content += note_content return TextContent( **{ "content_block_type": "text", "header": RenderedStringTemplateContent( **{ "content_block_type": "string_template", "string_template": { "template": "Notes", "tag": "h6", "styling": { "classes": ["m-0"] }, }, }), "text": content, "styling": { "classes": ["col-12", "table-responsive", "mt-1"], "body": { "classes": ["table", "table-sm"] }, }, })
def test_render_text(): text_component_content = TextContent( **{ "content_block_type": "text", "header": "Histogram", "text": ["hello"], "styling": { "classes": ["col-4"] }, }).to_json_dict() rendered_doc = ge.render.view.view.DefaultJinjaComponentView().render({ "content_block": text_component_content, "section_loop": { "index": 1 }, "content_block_loop": { "index": 2 }, }) print(rendered_doc) rendered_doc = rendered_doc.replace(" ", "").replace("\t", "").replace("\n", "") assert (rendered_doc == """ <div id="section-1-content-block-2" class="col-4" > <div id="section-1-content-block-2-body" class="col-4" > <div id="section-1-content-block-2-header" > <h5> Histogram </h5> </div> <p >hello</p> </div> </div> """.replace(" ", "").replace("\t", "").replace("\n", "")) text_component_content = TextContent( **{ "content_block_type": "text", "header": "Histogram", "text": ["hello", "goodbye"], "styling": { "classes": ["col-4"] }, }).to_json_dict() rendered_doc = ge.render.view.view.DefaultJinjaComponentView().render({ "content_block": text_component_content, "section_loop": { "index": 1 }, "content_block_loop": { "index": 2 }, }) print(rendered_doc) rendered_doc = rendered_doc.replace(" ", "").replace("\t", "").replace("\n", "") assert (rendered_doc == """ <div id="section-1-content-block-2" class="col-4" > <div id="section-1-content-block-2-body" class="col-4" > <div id="section-1-content-block-2-header" > <h5> Histogram </h5> </div> <p >hello</p> <p >goodbye</p> </div> </div> """.replace(" ", "").replace("\t", "").replace("\n", ""))
def _render_expectation_meta_notes(cls, expectation): if not expectation.meta.get("notes"): return None else: collapse_link = RenderedStringTemplateContent( **{ "content_block_type": "string_template", "string_template": { "template": "$icon", "params": { "icon": "" }, "styling": { "params": { "icon": { "classes": ["fas", "fa-comment", "text-info"], "tag": "i", } } }, }, }) notes = expectation.meta["notes"] note_content = None if isinstance(notes, str): note_content = [notes] elif isinstance(notes, list): note_content = notes elif isinstance(notes, dict): if "format" in notes: if notes["format"] == "string": if isinstance(notes["content"], str): note_content = [notes["content"]] elif isinstance(notes["content"], list): note_content = notes["content"] else: logger.warning( "Unrecognized Expectation suite notes format. Skipping rendering." ) elif notes["format"] == "markdown": if isinstance(notes["content"], str): note_content = [ RenderedMarkdownContent( **{ "content_block_type": "markdown", "markdown": notes["content"], "styling": { "parent": { "styles": { "color": "red" } } }, }) ] elif isinstance(notes["content"], list): note_content = [ RenderedMarkdownContent( **{ "content_block_type": "markdown", "markdown": note, "styling": { "parent": {} }, }) for note in notes["content"] ] else: logger.warning( "Unrecognized Expectation suite notes format. Skipping rendering." ) else: logger.warning( "Unrecognized Expectation suite notes format. Skipping rendering." ) notes_block = TextContent( **{ "content_block_type": "text", "subheader": "Notes:", "text": note_content, "styling": { "classes": ["col-12", "mt-2", "mb-2"], "parent": { "styles": { "list-style-type": "none" } }, }, }) return CollapseContent( **{ "collapse_toggle_link": collapse_link, "collapse": [notes_block], "inline_link": True, "styling": { "body": { "classes": ["card", "card-body", "p-1"] }, "parent": { "styles": { "list-style-type": "none" } }, }, })