/usr/lib/python2.7/dist-packages/openpyxl/comments/tests/test_shape_writer.py is in python-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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | from __future__ import absolute_import
# Copyright (c) 2010-2017 openpyxl
from openpyxl.workbook import Workbook
from openpyxl.tests.helper import compare_xml
from openpyxl.xml.functions import (
fromstring,
tostring,
Element,
)
from ..comments import Comment
from ..comment_sheet import CommentRecord
from ..shape_writer import (
ShapeWriter,
vmlns,
excelns,
)
def create_comments():
wb = Workbook()
ws = wb.active
comment1 = Comment("text", "author")
comment2 = Comment("text2", "author2")
comment3 = Comment("text3", "author3")
ws["B2"].comment = comment1
ws["C7"].comment = comment2
ws["D9"].comment = comment3
comments = []
for coord, cell in sorted(ws._cells.items()):
if cell._comment is not None:
comment = CommentRecord.from_cell(cell)
comments.append((cell.coordinate, comment))
return comments
def test_merge_comments_vml(datadir):
datadir.chdir()
cw = ShapeWriter(create_comments())
with open('control+comments.vml') as existing:
content = fromstring(cw.write(fromstring(existing.read())))
assert len(content.findall('{%s}shape' % vmlns)) == 5
assert len(content.findall('{%s}shapetype' % vmlns)) == 2
def test_write_comments_vml(datadir):
datadir.chdir()
cw = ShapeWriter(create_comments())
content = cw.write(Element("xml"))
with open('commentsDrawing1.vml') as expected:
correct = fromstring(expected.read())
check = fromstring(content)
correct_ids = []
correct_coords = []
check_ids = []
check_coords = []
for i in correct.findall("{%s}shape" % vmlns):
correct_ids.append(i.attrib["id"])
row = i.find("{%s}ClientData" % excelns).find("{%s}Row" % excelns).text
col = i.find("{%s}ClientData" % excelns).find("{%s}Column" % excelns).text
correct_coords.append((row,col))
# blank the data we are checking separately
i.attrib["id"] = "0"
i.find("{%s}ClientData" % excelns).find("{%s}Row" % excelns).text="0"
i.find("{%s}ClientData" % excelns).find("{%s}Column" % excelns).text="0"
for i in check.findall("{%s}shape" % vmlns):
check_ids.append(i.attrib["id"])
row = i.find("{%s}ClientData" % excelns).find("{%s}Row" % excelns).text
col = i.find("{%s}ClientData" % excelns).find("{%s}Column" % excelns).text
check_coords.append((row,col))
# blank the data we are checking separately
i.attrib["id"] = "0"
i.find("{%s}ClientData" % excelns).find("{%s}Row" % excelns).text="0"
i.find("{%s}ClientData" % excelns).find("{%s}Column" % excelns).text="0"
assert set(correct_coords) == set(check_coords)
assert set(correct_ids) == set(check_ids)
diff = compare_xml(tostring(correct), tostring(check))
assert diff is None, diff
def test_shape():
from ..shape_writer import _shape_factory
shape = _shape_factory(2,3)
xml = tostring(shape)
expected = """
<v:shape
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:o="urn:schemas-microsoft-com:office:office"
fillcolor="#ffffe1"
style="position:absolute; margin-left:59.25pt;margin-top:1.5pt;width:108pt;height:59.25pt;z-index:1;visibility:hidden"
type="#_x0000_t202"
o:insetmode="auto">
<v:fill color2="#ffffe1"/>
<v:shadow color="black" obscured="t"/>
<v:path o:connecttype="none"/>
<v:textbox style="mso-direction-alt:auto">
<div style="text-align:left"/>
</v:textbox>
<x:ClientData ObjectType="Note">
<x:MoveWithCells/>
<x:SizeWithCells/>
<x:AutoFill>False</x:AutoFill>
<x:Row>2</x:Row>
<x:Column>3</x:Column>
</x:ClientData>
</v:shape>
"""
diff = compare_xml(xml, expected)
assert diff is None, diff
|