Read about our upcoming Code of Conduct on this issue

This instance will be upgraded to Heptapod 0.28.1 on 2022-01-26 at 16:00 UTC+1 (a few minutes of down time)

Commit 7008c992 authored by CharlieC's avatar CharlieC
Browse files

Add some naive tests for reading and writing charts connected to pivot tables.

--HG--
branch : 2.6
parent e79015d356b4
......@@ -51,7 +51,7 @@ class ChartBase(Serialisable):
layout = Typed(expected_type=Layout, allow_none=True)
roundedCorners = Bool(allow_none=True)
axId = ValueSequence(expected_type=int)
visible_cells_only = Bool()
visible_cells_only = Bool(allow_none=True)
display_blanks = Set(values=['span', 'gap', 'zero'])
_series_type = ""
......@@ -83,6 +83,7 @@ class ChartBase(Serialisable):
self.display_blanks = 'gap'
self.pivotSource = None
self.pivotFormats = ()
self.visible_cells_only = True
def __hash__(self):
......
......@@ -35,5 +35,6 @@ def read_chart(chartspace):
chart.backWall = cs.chart.backWall
chart.pivotSource = cs.pivotSource
chart.pivotFormats = cs.chart.pivotFmts
chart.idx_base
return chart
<?xml version="1.0" standalone="yes"?>
<c:chartSpace xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
<c:date1904 val="0"/>
<c:lang />
<c:lang/>
<c:roundedCorners val="0"/>
<mc:AlternateContent xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
<mc:Choice xmlns:c14="http://schemas.microsoft.com/office/drawing/2007/8/2/chart" Requires="c14">
<c14:style val="102"/>
</mc:Choice>
<mc:Fallback>
<c:style val="2"/>
</mc:Fallback>
</mc:AlternateContent>
<c:pivotSource>
<c:name>[files.xlsx]PIVOT!PivotTable1</c:name>
<c:fmtId val="0"/>
</c:pivotSource>
<c:chart>
<c:pivotFmts>
<c:pivotFmt>
<c:idx val="0"/>
</c:pivotFmt>
</c:pivotFmts>
<c:title>
<c:tx>
<c:rich>
......@@ -19,7 +20,7 @@
<a:lstStyle/>
<a:p>
<a:r>
<a:rPr />
<a:rPr/>
<a:t>Website Performance</a:t>
</a:r>
</a:p>
......
......@@ -5,10 +5,12 @@ import pytest
from openpyxl.xml.functions import tostring
from openpyxl.tests.helper import compare_xml
from ..chartspace import PlotArea
from ..chartspace import PlotArea
from ..pivot import PivotSource, PivotFormat
from ..series import Series
@pytest.fixture
def ChartBase():
from .._chart import ChartBase
......@@ -132,3 +134,59 @@ class TestChartBase:
xml = tostring(tree)
diff = compare_xml(xml, expected)
assert diff is None, diff
def test_pivot_source(self, ChartBase):
chart = ChartBase()
chart.pivotSource = PivotSource(name="some pivot", fmtId=5)
expected = """
<chartSpace xmlns="http://schemas.openxmlformats.org/drawingml/2006/chart">
<pivotSource>
<name>some pivot</name>
<fmtId val="5" />
</pivotSource>
<chart>
<plotArea>
<DummyChart visible_cells_only="1" display_blanks="gap" />
</plotArea>
<legend>
<legendPos val="r"></legendPos>
</legend>
<plotVisOnly val="1"></plotVisOnly>
<dispBlanksAs val="gap"></dispBlanksAs>
</chart>
</chartSpace>
"""
tree = chart._write()
xml = tostring(tree)
diff = compare_xml(xml, expected)
assert diff is None, diff
def test_pivot_format(self, ChartBase):
chart = ChartBase()
fmt = PivotFormat()
chart.pivotFormats = [fmt]
expected = """
<chartSpace xmlns="http://schemas.openxmlformats.org/drawingml/2006/chart">
<chart>
<pivotFmts>
<pivotFmt>
<idx val="0" />
</pivotFmt>
</pivotFmts>
<plotArea>
<DummyChart visible_cells_only="1" display_blanks="gap" />
</plotArea>
<legend>
<legendPos val="r"></legendPos>
</legend>
<plotVisOnly val="1"></plotVisOnly>
<dispBlanksAs val="gap"></dispBlanksAs>
</chart>
</chartSpace>
"""
tree = chart._write()
xml = tostring(tree)
diff = compare_xml(xml, expected)
assert diff is None, diff
......@@ -31,3 +31,6 @@ def test_read(datadir):
assert chart.x_axis.title is None
assert len(chart.series) == 10
assert chart.pivotSource.name == "[files.xlsx]PIVOT!PivotTable1"
assert len(chart.pivotFormats) == 1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment