Beispiel #1
0
 def test_add_chart_from_dataframe_no_rows(self):
     tc = Thinkcell()
     template = "example.pptx"
     dataframe = pd.DataFrame(
         columns=["Company", "Employees", "Revenue", "Other"], )
     tc.add_template(template)
     with pytest.raises(DataFrameError) as e_info:
         tc.add_chart_from_dataframe(
             template_name=template,
             chart_name="Cool Chart",
             dataframe=dataframe,
         )
Beispiel #2
0
 def test_add_chart_from_dataframe_invalid_dataframe(self):
     tc = Thinkcell()
     template = "example.pptx"
     dataframe = [["Apple", 200, 1.5, 10], ["Amazon", 100, 1.0, 12],
                  ["Slack", 50, 0.5, 16]]
     tc.add_template(template)
     with pytest.raises(DataFrameError) as e_info:
         tc.add_chart_from_dataframe(
             template_name=template,
             chart_name="Cool Chart",
             dataframe=dataframe,
         )
Beispiel #3
0
 def test_add_chart_from_dataframe_no_data(self):
     tc = Thinkcell()
     template = "example.pptx"
     dataframe = pd.DataFrame(
         columns=["Company"],
         data=[["Apple"], ["Amazon"], ["Slack"]],
     )
     tc.add_template(template)
     with pytest.raises(DataFrameError) as e_info:
         tc.add_chart_from_dataframe(
             template_name=template,
             chart_name="Cool Chart",
             dataframe=dataframe,
         )
Beispiel #4
0
 def test_add_chart_from_dataframe(self):
     tc = Thinkcell()
     template = "example.pptx"
     dataframe = pd.DataFrame(
         columns=["Company", "Employees", "Revenue", "Other"],
         data=[["Apple", 200, 1.5, 10], ["Amazon", 100, 1.0, 12],
               ["Slack", 50, 0.5, 16]],
     )
     tc.add_template(template)
     tc.add_chart_from_dataframe(
         template_name=template,
         chart_name="Cool Chart",
         dataframe=dataframe,
     )
     assert tc.charts == [
         {
             "template":
             "example.pptx",
             "data": [
                 {
                     "name":
                     "Cool Chart",
                     "table": [
                         [
                             None, {
                                 "string": "Employees"
                             }, {
                                 "string": "Revenue"
                             }, {
                                 "string": "Other"
                             }
                         ],
                         [],
                         [
                             {
                                 "string": "Apple"
                             },
                             {
                                 "number": 200
                             },
                             {
                                 "number": 1.5
                             },
                             {
                                 "number": 10
                             },
                         ],
                         [
                             {
                                 "string": "Amazon"
                             },
                             {
                                 "number": 100
                             },
                             {
                                 "number": 1.0
                             },
                             {
                                 "number": 12
                             },
                         ],
                         [
                             {
                                 "string": "Slack"
                             },
                             {
                                 "number": 50
                             },
                             {
                                 "number": 0.5
                             },
                             {
                                 "number": 16
                             },
                         ],
                     ],
                 },
             ],
         },
     ]
Beispiel #5
0
        columns=["Metric", 2017, 2018, 2019],
        data=[["Expenses", 10, 10, 50], ["Revenues", 1, 1, 40]],
    ),
}

charts = [chart_1, chart_2, chart_3]

template_name = "complex-template-text-field.pptx"
filename = "complex-example-with-multiple-slides.ppttc"
tc = Thinkcell()
tc.add_template(template_name)

for chart in charts:
    tc.add_chart_from_dataframe(
        template_name=template_name,
        chart_name=chart["chart_name"],
        dataframe=chart["dataframe"],
    )
tc.add_textfield(template_name=template_name,
                 field_name="chart_text",
                 text="First instance")

charts = [chart_1, chart_2, chart_4]
tc.add_template(template_name)

for chart in charts:
    tc.add_chart_from_dataframe(
        template_name=template_name,
        chart_name=chart["chart_name"],
        dataframe=chart["dataframe"],
    )