Source code for openpyxl.chart.tests.test_pie_chart

# Copyright (c) 2010-2023 openpyxl
import pytest

from openpyxl.xml.functions import fromstring, tostring
from openpyxl.tests.helper import compare_xml

[docs] @pytest.fixture def PieChart(): from ..pie_chart import PieChart return PieChart
[docs] class TestPieChart:
[docs] def test_ctor(self, PieChart): chart = PieChart() xml = tostring(chart.to_tree()) expected = """ <pieChart> <varyColors val="1" /> <firstSliceAng val="0" /> </pieChart> """ diff = compare_xml(xml, expected) assert diff is None, diff
[docs] def test_from_xml(self, PieChart): src = """ <pieChart> <varyColors val="1" /> <explosion val="5"/> <firstSliceAng val="60"/> </pieChart> """ node = fromstring(src) chart = PieChart.from_tree(node) assert dict(chart) == {} assert chart.varyColors is True assert chart.firstSliceAng == 60
[docs] @pytest.fixture def PieChart3D(): from ..pie_chart import PieChart3D return PieChart3D
[docs] class TestPieChart3D:
[docs] def test_ctor(self, PieChart3D): chart = PieChart3D() xml = tostring(chart.to_tree()) expected = """ <pie3DChart> <varyColors val="1" /> </pie3DChart> """ diff = compare_xml(xml, expected) assert diff is None, diff
[docs] @pytest.fixture def DoughnutChart(): from ..pie_chart import DoughnutChart return DoughnutChart
[docs] class TestDoughnutChart:
[docs] def test_ctor(self, DoughnutChart): chart = DoughnutChart() xml = tostring(chart.to_tree()) expected = """ <doughnutChart> <varyColors val="1" /> <firstSliceAng val="0" /> <holeSize val="10" /> </doughnutChart> """ diff = compare_xml(xml, expected) assert diff is None, diff
[docs] def test_from_xml(self, DoughnutChart): src = """ <doughnutChart> <firstSliceAng val="0"/> <holeSize val="50"/> </doughnutChart> """ node = fromstring(src) chart = DoughnutChart.from_tree(node) assert dict(chart) == {} assert chart.firstSliceAng == 0 assert chart.holeSize == 50
[docs] @pytest.fixture def ProjectedPieChart(): from ..pie_chart import ProjectedPieChart return ProjectedPieChart
[docs] class TestProjectedPieChart:
[docs] def test_ctor(self, ProjectedPieChart): chart = ProjectedPieChart() xml = tostring(chart.to_tree()) expected = """ <ofPieChart> <varyColors val="1" /> <ofPieType val="pie"/> <splitType val="auto"/> <secondPieSize val="75"/> <serLines/> </ofPieChart> """ diff = compare_xml(xml, expected) assert diff is None, diff
[docs] def test_from_xml(self, ProjectedPieChart): src = """ <ofPieChart> <varyColors val="1"/> <ofPieType val="pie"/> <splitType val="auto"/> <dLbls> <showLegendKey val="0"/> <showVal val="0"/> <showCatName val="0"/> <showSerName val="0"/> <showPercent val="0"/> <showBubbleSize val="0"/> <showLeaderLines val="1"/> </dLbls> <gapWidth val="150"/> <secondPieSize val="75"/> <serLines/> </ofPieChart> """ node = fromstring(src) chart = ProjectedPieChart.from_tree(node) assert dict(chart) == {} assert chart.gapWidth == 150 assert chart.secondPieSize == 75
[docs] @pytest.fixture def CustomSplit(): from ..pie_chart import CustomSplit return CustomSplit
[docs] class TestCustomSplit:
[docs] def test_ctor(self, CustomSplit): pie_chart = CustomSplit([1, 2, 3]) xml = tostring(pie_chart.to_tree()) expected = """ <custSplit> <secondPiePt val="1" /> <secondPiePt val="2" /> <secondPiePt val="3" /> </custSplit> """ diff = compare_xml(xml, expected) assert diff is None, diff
[docs] def test_from_xml(self, CustomSplit): src = """ <custSplit> <secondPiePt val="1" /> <secondPiePt val="2" /> </custSplit> """ node = fromstring(src) pie_chart = CustomSplit.from_tree(node) assert pie_chart == CustomSplit([1, 2])