def gen_report_complex_no_files() -> dp.Report: """Generate a complex layout report with simple elements""" select = dp.Select(blocks=[md_block, md_block], type=dp.SelectType.TABS) group = dp.Group(md_block, md_block, columns=2) return dp.Report( dp.Page( blocks=[ dp.Group(md_block, md_block, columns=2), dp.Select(blocks=[md_block, group], type=dp.SelectType.DROPDOWN), ], title="Page Uno", ), dp.Page( blocks=[ dp.Group(select, select, columns=2), dp.Select(blocks=[md_block, md_block, md_block], type=dp.SelectType.TABS), ], title="Page Duo", ), dp.Page( blocks=[ dp.Group(group, group, columns=2), dp.Select(blocks=[select, select], type=dp.SelectType.TABS), ], title="Page Tres", ), )
def test_gen_failing_reports(): # local reports with unsupported elements with pytest.raises(DPError): r = dp.Report(dp.DataTable(gen_df())) r._gen_report(embedded=True, title="TITLE", description="DESCRIPTION") # nested pages with pytest.raises((DocumentInvalid, DPError)): r = dp.Report(dp.Page(dp.Page(md_block))) r._gen_report(embedded=False, title="TITLE", description="DESCRIPTION") with pytest.raises((DocumentInvalid, DPError)): r = dp.Report(dp.Group(dp.Page(md_block))) r._gen_report(embedded=False, title="TITLE", description="DESCRIPTION") # group with 0 object with pytest.raises((DocumentInvalid, DPError)): r = dp.Report(dp.Page(dp.Group(blocks=[]))) r._gen_report(embedded=False, title="TITLE", description="DESCRIPTION") # select with 1 object with pytest.raises((DocumentInvalid, DPError)): r = dp.Report(dp.Page(dp.Select(blocks=[md_block]))) r._gen_report(embedded=False, title="TITLE", description="DESCRIPTION") # empty text block with pytest.raises((AssertionError, DocumentInvalid, DPError)): r = dp.Report(dp.Text(" ")) r._gen_report(embedded=False, title="TITLE", description="DESCRIPTION")
def gen_report_complex_with_files(datadir: Path, single_file: bool = False, local_report: bool = False) -> dp.Report: # Asset tests lis = [1, 2, 3] small_df = gen_df() big_df = gen_df(10000) # text # md_block html_block = dp.HTML(html="<h1>Hello World</h1>") html_block_1 = dp.HTML(html=h2("Hello World")) code_block = dp.Code(code="print('hello')", language="python") formula_block = dp.Formula(formula=r"\frac{1}{\sqrt{x^2 + 1}}") big_number = dp.BigNumber(heading="Tests written", value=1234) big_number_1 = dp.BigNumber(heading="Real Tests written :)", value=11, change=2, is_upward_change=True) embed_block = dp.Embed(url="https://www.youtube.com/watch?v=JDe14ulcfLA") # assets plot_asset = dp.Plot(data=gen_plot(), caption="Plot Asset") list_asset = dp.File(data=lis, filename="List Asset", is_json=True) img_asset = dp.File(file=datadir / "datapane-logo.png") # tables table_asset = dp.Table(data=small_df, caption="Test Basic Table") # local reports don't support DataTable dt_asset = table_asset if local_report else dp.DataTable( df=big_df, caption="Test DataTable") if single_file: return dp.Report(dp.Group(blocks=[md_block, dt_asset])) else: return dp.Report( dp.Page( dp.Select(md_block, html_block, html_block_1, code_block, formula_block, embed_block, type=dp.SelectType.TABS), dp.Group(big_number, big_number_1, columns=2), ), dp.Page( plot_asset, list_asset, img_asset, table_asset, dt_asset, ), )
def test_add_footer(): text = "FOOTER" r = dp.Report(blocks=[dp.Page(md_block, md_block) for _ in range(3)]) r1 = dp.templates.add_footer(r, footer=text, all_pages=True) assert_report(r1, 0, 18) assert glom(r1, ("pages", ["blocks.0.blocks.-1.content"])) == [text, text, text] r1 = dp.templates.add_footer(r, footer=text, all_pages=False) assert_report(r1, 0, 14) assert glom(r1, ("pages", ["blocks.0.blocks.-1.content"])) == [text, md_block.content, md_block.content]
def test_gen_failing_reports(): # nested pages with pytest.raises((DocumentInvalid, DPError)): r = dp.Report(dp.Page(dp.Page(md_block))) r._gen_report(embedded=False, title="TITLE", description="DESCRIPTION") with pytest.raises((DocumentInvalid, DPError)): r = dp.Report(dp.Group(dp.Page(md_block))) r._gen_report(embedded=False, title="TITLE", description="DESCRIPTION") # group with 0 object with pytest.raises((DocumentInvalid, DPError)): r = dp.Report(dp.Page(dp.Group(blocks=[]))) r._gen_report(embedded=False, title="TITLE", description="DESCRIPTION") # select with 1 object with pytest.raises((DocumentInvalid, DPError)): r = dp.Report(dp.Page(dp.Select(blocks=[md_block]))) r._gen_report(embedded=False, title="TITLE", description="DESCRIPTION") # empty text block with pytest.raises((AssertionError, DocumentInvalid, DPError)): r = dp.Report(dp.Text(" ")) r._gen_report(embedded=False, title="TITLE", description="DESCRIPTION") # empty df with pytest.raises((AssertionError, DocumentInvalid, DPError)): r = dp.Report(dp.DataTable(pd.DataFrame())) r._gen_report(embedded=False, title="TITLE", description="DESCRIPTION") # invalid names with pytest.raises(DocumentInvalid): r = dp.Report(dp.Text("a", name="my-name"), dp.Text("a", name="my-name")) r._gen_report(embedded=False, title="TITLE", description="DESCRIPTION") with pytest.raises(DPError): dp.Report(dp.Text("a", name="3-invalid-name"))
yaxis_title='average', legend_title='Race', legend_bordercolor='black', legend_borderwidth=2, barmode='group', bargap=.3) # Create report r = dp.Report( dp.Page( label='Introduction', blocks=[ dp.HTML(html), "The data has been compiled over 3 semesters, for the introductory computer science class CSE 1223.", dp.Group(dp.BigNumber(heading="Number of Students", value=num_students), dp.BigNumber(heading="Class Average", value=str(class_average) + "%", change="2%", is_upward_change=True), columns=2), dp.BigNumber(heading="Pass Rate", value=str(pass_rate) + "%"), ]), dp.Page(label='Deliverables', blocks=[ f'### Labs', dp.Plot(lab_bar), f'### Homeworks', dp.Plot(hw_bar), f'### Projects', dp.Plot(project_bar) ]), dp.Page(label='Exam Grades', blocks=[f'### Kernel Density Plot ',
blocks=["#### Vagas - Engenheiro de Dados", dp.DataTable(df_ED[colunas], label = "Engenheiro de Dados")] ) pagina5 = dp.Page( title ="Engenheiro de Machine Learning", blocks=["#### Vagas - Engenheiro de Machine Learning", dp.DataTable(df_EML[colunas], label = "Engenheiro de Machine Learning")] ) """ r = dp.Report( dp.Page(title="Dashes", blocks=[ "#### Heatmap de Vagas pelo Brasil", dp.Plot(mapa), "#### Total Vagas", dp.Plot(fig3), "#### Total Vagas por Estado", dp.Plot(fig1), "#### Total Vagas por Nível", dp.Plot(fig2) ]), dp.Page(title="Cientista de Dados", blocks=[ "#### Vagas - Cientista de Dados", dp.DataTable(df_CD[colunas], label="Cientista de Dados") ]), dp.Page(title="Analista de Dados", blocks=[ "#### Vagas Analista de Dados", dp.DataTable(df_AD[colunas], label="Analista de Dados") ]), dp.Page(title="Engenheiro de Dados", blocks=[