def test_add_chart_bad_template(self): tc = Thinkcell() template = "example.pptx" with pytest.raises(ValueError) as e_info: tc.add_chart( template_name="example2.pptx", chart_name="Cool Name bro", categories=["Alpha", "bravo"], data=[[3, 4, datetime(2012, 9, 16, 0, 0)], [2, "adokf", 6]], )
def test_add_chart_warning(self): tc = Thinkcell() template_name = "template.pptx" tc.add_template(template_name) with pytest.warns(UserWarning) as record: tc.add_chart( template_name=template_name, chart_name=234, categories=["Alpha", "bravo"], data=[[3, 4, datetime(2012, 9, 16, 0, 0)], [2, "adokf", 6]], )
def test_save_ppttc(self): tc = Thinkcell() tc.add_template("example.pptx") tc.add_chart( template_name="example.pptx", chart_name="Chart name", categories=["alpha", "bravo"], data=[["today", 1, 2], ["tomorrow", 3, 4]], ) assert tc.save_ppttc(filename="test.ppttc") == True os.remove("test.ppttc")
def test_save_ppttc_bad_file(self, input, output): tc = Thinkcell() tc.add_template("example.pptx") tc.add_chart( template_name="example.pptx", chart_name="Chart name", categories=["alpha", "bravo"], data=[["today", 1, 2], ["tomorrow", 3, 4]], ) with pytest.raises(output) as e_info: tc.save_ppttc(filename=input)
def test_add_chart(self): tc = Thinkcell() template = "example.pptx" tc.add_template(template) tc.add_chart( template_name=template, chart_name="Cool Name bro", categories=["Alpha", "bravo"], data=[[3, 4, datetime(2012, 9, 16, 0, 0)], [2, "adokf", 4]], ) assert tc.charts == [{ "template": "example.pptx", "data": [{ "name": "Cool Name bro", "table": [ [None, { "string": "Alpha" }, { "string": "bravo" }], [], [ { "number": 3 }, { "number": 4 }, { "date": "2012-09-16" }, ], [ { "number": 2 }, { "string": "adokf" }, { "number": 4 }, ], ], }], }]
from thinkcell import Thinkcell template_name = "simple-template.pptx" categories = ["Ads", "iPhones", "Other"] chart_name = "Chart1" filename = "simple-example.ppttc" data = [["Apple", 1, 11, 14], ["Google", 8, 2, 15], ["Microsoft", 1, 2, 12]] tc = Thinkcell() tc.add_template(template_name) tc.add_chart( template_name=template_name, chart_name=chart_name, categories=categories, data=data, ) tc.save_ppttc(filename=filename)
"Chart2", "data": [ ["Manchester", 34, 20, 14], ["Chelsea", 40, 13, 20], ["Arsenal", 34, 30, 4], ], } chart_3 = { "categories": [2017, 2018, 2019], "chart_name": "Chart3", "data": [["Revenue", 45, 24, 0], ["Employees", 10, 14, 0]], } charts = [chart_1, chart_2, chart_3] template_name = "complex-template.pptx" filename = "complex-example.ppttc" tc = Thinkcell() tc.add_template(template_name) for chart in charts: tc.add_chart( template_name=template_name, chart_name=chart["chart_name"], categories=chart["categories"], data=chart["data"], ) tc.save_ppttc(filename=filename)