예제 #1
0
def test_write_serial(ten_row_sheet, LineChart, Series, Reference, root_xml):
    ws = ten_row_sheet
    chart = LineChart()
    for idx, l in enumerate("ABCDEF"):
        ws.cell(row=idx, column=0).value = l
    ref = Reference(ws, (0, 0), (9, 0))
    series = Series(ref)
    chart.add_serie(series)
    cw = BaseChartWriter(chart)
    cw._write_serial(cw.root, ref)
    xml = get_xml(cw.root)
    expected = """ <c:chartSpace xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart"><c:strRef><c:f>'data'!$A$1:$A$10</c:f><c:strCache><c:ptCount val="10"/><c:pt idx="0"><c:v>A</c:v></c:pt><c:pt idx="1"><c:v>B</c:v></c:pt><c:pt idx="2"><c:v>C</c:v></c:pt><c:pt idx="3"><c:v>D</c:v></c:pt><c:pt idx="4"><c:v>E</c:v></c:pt><c:pt idx="5"><c:v>F</c:v></c:pt><c:pt idx="6"><c:v>6</c:v></c:pt><c:pt idx="7"><c:v>7</c:v></c:pt><c:pt idx="8"><c:v>8</c:v></c:pt><c:pt idx="9"><c:v>9</c:v></c:pt></c:strCache></c:strRef></c:chartSpace>"""
    diff = compare_xml(xml, expected)
    assert diff is None, diff
 def test_write_no_ascii(self, ten_row_sheet, Series, BarChart, Reference,
                         root_xml):
     ws = ten_row_sheet
     ws.append([b"D\xc3\xbcsseldorf"] * 10)
     serie = Series(values=Reference(ws, (1, 1), (1, 10)),
                    title=(ws.cell(row=1, column=1).value))
     c = BarChart()
     c.add_serie(serie)
     cw = BaseChartWriter(c)
     cw._write_series(root_xml)
     xml = tostring(root_xml)
     expected = """<test><c:ser xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart"><c:idx val="0"/><c:order val="0"/><c:val><c:numRef><c:f>'data'!$A$1:$J$1</c:f><c:numCache><c:formatCode>General</c:formatCode><c:ptCount val="10"/><c:pt idx="0"><c:v>0</c:v></c:pt><c:pt idx="1"><c:v></c:v></c:pt><c:pt idx="2"><c:v></c:v></c:pt><c:pt idx="3"><c:v></c:v></c:pt><c:pt idx="4"><c:v></c:v></c:pt><c:pt idx="5"><c:v></c:v></c:pt><c:pt idx="6"><c:v></c:v></c:pt><c:pt idx="7"><c:v></c:v></c:pt><c:pt idx="8"><c:v></c:v></c:pt><c:pt idx="9"><c:v></c:v></c:pt></c:numCache></c:numRef></c:val></c:ser></test>"""
     diff = compare_xml(xml, expected)
     assert diff is None, diff
def test_write_serial(ten_row_sheet, LineChart, Series, Reference, root_xml):
    ws = ten_row_sheet
    chart = LineChart()
    for idx, l in enumerate("ABCDEF", 1):
        ws.cell(row=idx, column=1).value = l
    ref = Reference(ws, (1, 1), (10, 1))
    series = Series(ref)
    chart.add_serie(series)
    cw = BaseChartWriter(chart)
    cw._write_serial(cw.root, ref)
    xml = tostring(cw.root)
    expected = """ <c:chartSpace xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart"><c:strRef><c:f>'data'!$A$1:$A$10</c:f><c:strCache><c:ptCount val="10"/><c:pt idx="0"><c:v>A</c:v></c:pt><c:pt idx="1"><c:v>B</c:v></c:pt><c:pt idx="2"><c:v>C</c:v></c:pt><c:pt idx="3"><c:v>D</c:v></c:pt><c:pt idx="4"><c:v>E</c:v></c:pt><c:pt idx="5"><c:v>F</c:v></c:pt><c:pt idx="6"><c:v>6</c:v></c:pt><c:pt idx="7"><c:v>7</c:v></c:pt><c:pt idx="8"><c:v>8</c:v></c:pt><c:pt idx="9"><c:v>9</c:v></c:pt></c:strCache></c:strRef></c:chartSpace>"""
    diff = compare_xml(xml, expected)
    assert diff is None, diff
 def test_write_no_ascii(self, ten_row_sheet, Series, BarChart, Reference, root_xml):
     ws = ten_row_sheet
     ws.append([b"D\xc3\xbcsseldorf"]*10)
     serie = Series(values=Reference(ws, (1,1), (1,10)),
                   title=(ws.cell(row=1, column=1).value)
                   )
     c = BarChart()
     c.add_serie(serie)
     cw = BaseChartWriter(c)
     cw._write_series(root_xml)
     xml = tostring(root_xml)
     expected = """<test><c:ser xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart"><c:idx val="0"/><c:order val="0"/><c:val><c:numRef><c:f>'data'!$A$1:$J$1</c:f><c:numCache><c:formatCode>General</c:formatCode><c:ptCount val="10"/><c:pt idx="0"><c:v>0</c:v></c:pt><c:pt idx="1"><c:v></c:v></c:pt><c:pt idx="2"><c:v></c:v></c:pt><c:pt idx="3"><c:v></c:v></c:pt><c:pt idx="4"><c:v></c:v></c:pt><c:pt idx="5"><c:v></c:v></c:pt><c:pt idx="6"><c:v></c:v></c:pt><c:pt idx="7"><c:v></c:v></c:pt><c:pt idx="8"><c:v></c:v></c:pt><c:pt idx="9"><c:v></c:v></c:pt></c:numCache></c:numRef></c:val></c:ser></test>"""
     diff = compare_xml(xml, expected)
     assert diff is None, diff