test_reader.py 1.06 KB
Newer Older
1
from __future__ import absolute_import
CharlieC's avatar
CharlieC committed
2
# Copyright (c) 2010-2017 openpyxl
3

4
5
from zipfile import ZipFile

6
7
from openpyxl.xml.functions import fromstring

8
9
from .. line_chart import LineChart
from .. axis import NumericAxis, DateAxis
10
from .. chartspace import ChartSpace
11
12
13
14


def test_read(datadir):
    datadir.chdir()
15
    from .. reader import read_chart
16
17
18

    with open("chart1.xml") as src:
        xml = src.read()
19
20
21
    tree = fromstring(xml)
    cs = ChartSpace.from_tree(tree)
    chart = read_chart(cs)
22
23
24
25
26
27
28
29
30
31
32

    assert isinstance(chart, LineChart)
    assert chart.title.tx.rich.p[0].r.t == "Website Performance"

    assert isinstance(chart.y_axis, NumericAxis)
    assert chart.y_axis.title.tx.rich.p[0].r.t == "Time in seconds"

    assert isinstance(chart.x_axis, DateAxis)
    assert chart.x_axis.title is None

    assert len(chart.series) == 10
33
34
35
36
37
38
39
40
41
42
43


def test_read_drawing(datadir):
    datadir.chdir()

    archive = ZipFile("sample.xlsx")
    path = "xl/drawings/drawing1.xml"

    from ..reader import find_charts
    charts = find_charts(archive, path)
    assert len(charts) == 6