/usr/lib/python3/dist-packages/openpyxl/chartsheet/tests/test_chartsheet.py is in python3-openpyxl 2.4.9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | from __future__ import absolute_import
# Copyright (c) 2010-2017 openpyxl
from openpyxl.worksheet.drawing import Drawing
from openpyxl.worksheet.page import PageMargins
from ..views import ChartsheetView, ChartsheetViewList
from openpyxl.xml.functions import fromstring, tostring
from openpyxl.tests.helper import compare_xml
import pytest
class DummyWorkbook:
def __init__(self):
self.sheetnames = []
self._charts = []
@pytest.fixture
def Chartsheet():
from ..chartsheet import Chartsheet
return Chartsheet
class TestChartsheet:
def test_ctor(self, Chartsheet):
cs = Chartsheet(parent=DummyWorkbook())
assert cs.title == "Chart"
def test_read(self, Chartsheet):
src = """
<chartsheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
<sheetPr/>
<sheetViews>
<sheetView tabSelected="1" zoomScale="80" workbookViewId="0" zoomToFit="1"/>
</sheetViews>
<pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/>
<drawing r:id="rId1"/>
</chartsheet>
"""
xml = fromstring(src)
chart = Chartsheet.from_tree(xml)
assert chart.pageMargins.left == 0.7
assert chart.sheetViews.sheetView[0].tabSelected == True
def test_write(self, Chartsheet):
sheetview = ChartsheetView(tabSelected=True, zoomScale=80, workbookViewId=0, zoomToFit=True)
chartsheetViews = ChartsheetViewList(sheetView=[sheetview])
pageMargins = PageMargins(left=0.7, right=0.7, top=0.75, bottom=0.75, header=0.3, footer=0.3)
drawing = Drawing("rId1")
item = Chartsheet(sheetViews=chartsheetViews, pageMargins=pageMargins, drawing=drawing)
expected = """
<chartsheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
<sheetViews>
<sheetView tabSelected="1" zoomScale="80" workbookViewId="0" zoomToFit="1"/>
</sheetViews>
<pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/>
<drawing r:id="rId1"/>
</chartsheet>
"""
xml = tostring(item.to_tree())
diff = compare_xml(xml, expected)
assert diff is None, diff
def test_write_charts(self, Chartsheet):
class DummyChart:
pass
cs = Chartsheet(parent=DummyWorkbook())
cs.add_chart(DummyChart())
expected = """
<chartsheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
<sheetViews>
<sheetView workbookViewId="0"></sheetView>
</sheetViews>
<drawing r:id="rId1" />
</chartsheet>
"""
xml = tostring(cs.to_tree())
diff = compare_xml(xml, expected)
assert diff is None, diff
|