Skip to content

Commit

Permalink
Merge 2.2.6 into default.
Browse files Browse the repository at this point in the history
  • Loading branch information
Themanwithoutaplan committed Aug 16, 2015
2 parents 0f11c6d + de42460 commit ae99b35
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 19 deletions.
13 changes: 13 additions & 0 deletions doc/source/changes.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
2.2.6 (unreleased)
==================


Bug fixes
---------

* `#502 <https://bitbucket.org/openpyxl/openpyxl/issue/502>`_ Unexpected keyword "mergeCell"
* `#503 <https://bitbucket.org/openpyxl/openpyxl/issue/503>`_ tostring missing in dump_worksheet
* `#506 <https://bitbucket.org/openpyxl/openpyxl/issues/506>`_ Non-ASCII formulae cannot be parsed
* `#508 <https://bitbucket.org/openpyxl/openpyxl/issues/508>`_ Cannot save files with coloured tabs


2.2.5 (2015-06-29)
==================

Expand Down
2 changes: 1 addition & 1 deletion openpyxl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


# constants
__version__ = '2.2.4'
__version__ = '2.2.6'

__author__ = 'Eric Gazoni'
__license__ = 'MIT/Expat'
Expand Down
5 changes: 3 additions & 2 deletions openpyxl/formatting/rule.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import absolute_import
# copyright openpyxl 2010-2015

#Autogenerated schema
from openpyxl.compat import basestring

from openpyxl.descriptors.serialisable import Serialisable
from openpyxl.descriptors import (
Typed,
Expand Down Expand Up @@ -150,7 +151,7 @@ class Rule(Serialisable):
rank = Integer(allow_none=True)
stdDev = Integer(allow_none=True)
equalAverage = Bool(allow_none=True)
formula = Sequence(expected_type=str)
formula = Sequence(expected_type=basestring)
colorScale = Typed(expected_type=ColorScale, allow_none=True)
dataBar = Typed(expected_type=DataBar, allow_none=True)
iconSet = Typed(expected_type=IconSet, allow_none=True)
Expand Down
17 changes: 17 additions & 0 deletions openpyxl/formatting/tests/test_rule.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# coding=utf8
from __future__ import absolute_import
# copyright 2010-2015 openpyxl


import pytest

from openpyxl.xml.functions import fromstring, tostring
Expand Down Expand Up @@ -202,3 +204,18 @@ def test_serialise(self, Rule):
assert diff is None, diff


def test_non_ascii_formula(self, Rule):

rule = Rule(type="cellIs", priority=10, formula=[b"D\xc3\xbcsseldorf".decode("utf-8")])

xml = tostring(rule.to_tree())
expected = """
<cfRule priority="10" type="cellIs">
<formula>Düsseldorf</formula>
</cfRule>
"""
diff = compare_xml(xml, expected)

assert diff is None, diff


5 changes: 3 additions & 2 deletions openpyxl/worksheet/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ def write_sheetPr(props):
el = Element(props.tag, attributes)

tab_color = props.tabColor
if tab_color:
el.append(Element('{%s}tabColor' % SHEET_MAIN_NS, rgb=tab_color.value))
if tab_color is not None:
node = tab_color.to_tree("{%s}tabColor" % SHEET_MAIN_NS)
el.append(node)

outline = props.outlinePr
if outline:
Expand Down
34 changes: 23 additions & 11 deletions openpyxl/worksheet/tests/test_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@
# Copyright (c) 2010-2015 openpyxl

import pytest
from lxml.etree import fromstring

from openpyxl.xml.constants import SHEET_MAIN_NS
from openpyxl.xml.functions import fromstring
from openpyxl.styles.colors import Color
from openpyxl.tests.schema import sheet_schema
from openpyxl.tests.helper import compare_xml
from _pytest.main import Node

from openpyxl.xml.functions import safe_iterator, tostring

def test_ctor():

@pytest.mark.parametrize("value, expected",
[
(Color("00F0F0F0"), {'rgb':"00F0F0F0"}),
(Color(theme=4, tint="0.5"), {'theme': '4', 'tint': '0.5'} )
]
)
def test_ctor(value, expected):
from .. properties import WorksheetProperties, Outline
color_test = 'F0F0F0'
color_test = value
outline_pr = Outline(summaryBelow=True, summaryRight=True)
wsprops = WorksheetProperties(tabColor=color_test, outlinePr=outline_pr)
assert dict(wsprops) == {}
assert dict(wsprops.outlinePr) == {'summaryBelow': '1', 'summaryRight': '1'}
assert dict(wsprops.tabColor) == {'rgb': '00F0F0F0'}
assert dict(wsprops.tabColor) == expected


@pytest.fixture
Expand All @@ -30,15 +38,19 @@ def SimpleTestProps():
return wsp


def test_write_properties(SimpleTestProps):
@pytest.mark.parametrize("value, expected",
[
(Color("00F0F0F0"), """<tabColor xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" rgb="00F0F0F0" />"""),
(Color(theme=4, tint="0.5"), """<tabColor xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" theme="4" tint="0.5" />""")
]
)
def test_write_properties(SimpleTestProps, value, expected):
from .. properties import write_sheetPr
SimpleTestProps.tabColor = value

content = write_sheetPr(SimpleTestProps)
expected = """ <s:sheetPr xmlns:s="http://schemas.openxmlformats.org/spreadsheetml/2006/main" filterMode="0">
<s:tabColor rgb="FF123456" />
<s:pageSetUpPr fitToPage="0" />
</s:sheetPr>"""
diff = compare_xml(tostring(content), expected)
node = content.find("{%s}tabColor" % SHEET_MAIN_NS)
diff = compare_xml(tostring(node), expected)
assert diff is None, diff


Expand Down
10 changes: 7 additions & 3 deletions openpyxl/writer/dump_worksheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@
MAX_ROW,
PACKAGE_XL
)
from openpyxl.xml.functions import xmlfile, Element, SubElement

from openpyxl.xml.functions import (
xmlfile,
Element,
SubElement,
tostring,
)

DESCRIPTORS_CACHE_SIZE = 50
ALL_TEMP_FILES = []
Expand Down Expand Up @@ -249,7 +253,7 @@ def _write_worksheets(self, archive):

# write comments
if sheet._comments:
rels = write_rels(sheet, drawing_id, comments_id)
rels = write_rels(sheet, drawing_id, comments_id, False)
archive.writestr( PACKAGE_WORKSHEETS +
'/_rels/sheet%d.xml.rels' % i, tostring(rels) )

Expand Down
18 changes: 18 additions & 0 deletions openpyxl/writer/tests/test_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import datetime
import decimal
from io import BytesIO
from zipfile import ZipFile
from tempfile import TemporaryFile

from openpyxl.xml.functions import tostring, xmlfile

Expand Down Expand Up @@ -204,6 +206,22 @@ def test_cell_comment(DumpWorksheet):
assert diff is None, diff


def test_rels(DumpWorksheet):
from .. dump_worksheet import ExcelDumpWriter, WriteOnlyCell
from openpyxl.comments import Comment

archive = ZipFile(TemporaryFile(), "w")
ws = DumpWorksheet
cell = WriteOnlyCell(ws)
cell.comment = Comment("blah", "shakespeare")

ws._comments = [cell.comment]
wb = DummyWorkbook()
wb.worksheets = [ws]
writer = ExcelDumpWriter(wb)
writer._write_worksheets(archive)


@pytest.mark.lxml_required
def test_cannot_save_twice(DumpWorksheet):
from .. dump_worksheet import WorkbookAlreadySaved
Expand Down

0 comments on commit ae99b35

Please # to comment.