class TestPieChartWriter(object): def setup(self): """Setup a worksheet with one column of data and a pie chart""" wb = Workbook() ws = wb.get_active_sheet() ws.title = "Pie" for i in range(1, 5): ws.append([i]) self.piechart = PieChart() values = Reference(ws, (0, 0), (9, 0)) series = Serie(values, labels=values) self.piechart.add_serie(series) ws.add_chart(self.piechart) self.cw = PieChartWriter(self.piechart) self.root = Element("test") def test_write_chart(self): """check if some characteristic tags of PieChart are there""" self.cw._write_chart(self.root) tagnames = ["{%s}pieChart" % CHART_NS, "{%s}varyColors" % CHART_NS] root = safe_iterator(self.root) chart_tags = [e.tag for e in root] for tag in tagnames: assert_true(tag in chart_tags, tag) assert_false("c:catAx" in chart_tags) def test_serialised(self): """Check the serialised file against sample""" xml = self.cw.write() expected_file = os.path.join(DATADIR, "writer", "expected", "piechart.xml") with open(expected_file) as expected: diff = compare_xml(xml, expected.read()) assert diff is None, diff
def test_serialised(self, pie_chart): """Check the serialised file against sample""" cw = PieChartWriter(pie_chart) xml = cw.write() tree = fromstring(xml) chart_schema.assertValid(tree) expected_file = os.path.join(DATADIR, "writer", "expected", "piechart.xml") with open(expected_file) as expected: diff = compare_xml(xml, expected.read()) assert diff is None, diff
def test_serialised(self, pie_chart, datadir): """Check the serialised file against sample""" cw = PieChartWriter(pie_chart) xml = cw.write() tree = fromstring(xml) chart_schema.assertValid(tree) datadir.chdir() with open("PieChart.xml") as expected: diff = compare_xml(xml, expected.read()) assert diff is None, diff