Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The test fails when running test_properties.py #108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docxcompose/composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ def add_numberings(self, doc, element):
num_element.numId = next_num_id

self.num_id_mapping[num_id] = next_num_id
# Update next_num_id for the next loop
next_num_id += 1

anum_id = num_element.xpath('//w:abstractNumId')[0]
if anum_id.val not in self.anum_id_mapping:
Expand All @@ -382,6 +384,8 @@ def add_numberings(self, doc, element):
anum_id.val = next_anum_id
# anum_element.abstractNumId = next_anum_id
anum_element.set('{%s}abstractNumId' % NS['w'], str(next_anum_id))
# Update next_anum_id for the next loop
next_anum_id += 1

# Make sure we have a unique nsid so numberings restart properly
nsid = anum_element.find('.//w:nsid', NS)
Expand Down
16 changes: 8 additions & 8 deletions tests/test_properties.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone
from docx import Document
from docx.opc.constants import RELATIONSHIP_TYPE as RT
from docx.oxml import parse_xml
Expand Down Expand Up @@ -763,12 +763,12 @@ def test_get_doc_properties():
assert props['Text Property'] == 'Foo Bar'
assert props['Number Property'] == 123
assert props['Boolean Property'] is True
assert props['Date Property'] == datetime(2019, 6, 11, 10, 0)
assert props['Date Property'] == datetime(2019, 6, 11, 10, 0, tzinfo=timezone.utc)

assert props.get('Text Property') == 'Foo Bar'
assert props.get('Number Property') == 123
assert props.get('Boolean Property') is True
assert props.get('Date Property') == datetime(2019, 6, 11, 10, 0)
assert props.get('Date Property') == datetime(2019, 6, 11, 10, 0, tzinfo=timezone.utc)


def test_get_doc_property_is_case_insensitive():
Expand All @@ -793,7 +793,7 @@ def test_add_doc_properties():
assert props.get('My Number Property') == 123

props.add('My Date Property', datetime(2019, 10, 23, 15, 44, 50))
assert props.get('My Date Property') == datetime(2019, 10, 23, 15, 44, 50)
assert props.get('My Date Property') == datetime(2019, 10, 23, 15, 44, 50, tzinfo=timezone.utc)


def test_add_utf8_property():
Expand All @@ -818,7 +818,7 @@ def test_set_doc_properties():
assert props['Number Property'] == 456

props['Date Property'] = datetime(2019, 10, 20, 12, 0)
assert props['Date Property'] == datetime(2019, 10, 20, 12, 0)
assert props['Date Property'] == datetime(2019, 10, 20, 12, 0, tzinfo=timezone.utc)


def test_set_doc_property_is_case_insensitive():
Expand Down Expand Up @@ -913,7 +913,7 @@ def test_doc_properties_values():
props = CustomProperties(document)

assert props.values() == [
'Foo Bar', 123, True, datetime(2019, 6, 11, 10, 0), 1.1]
'Foo Bar', 123, True, datetime(2019, 6, 11, 10, 0, tzinfo=timezone.utc), 1.1]


def test_doc_properties_items():
Expand All @@ -924,7 +924,7 @@ def test_doc_properties_items():
('Text Property', 'Foo Bar'),
('Number Property', 123),
('Boolean Property', True),
('Date Property', datetime(2019, 6, 11, 10, 0)),
('Date Property', datetime(2019, 6, 11, 10, 0, tzinfo=timezone.utc)),
('Float Property', 1.1),
]

Expand All @@ -933,7 +933,7 @@ def test_vt2value_value2vt_roundtrip():
assert vt2value(value2vt(42)) == 42
assert vt2value(value2vt(True)) is True
assert vt2value(value2vt(1.1)) == pytest.approx(1.1)
dt = datetime(2019, 6, 11, 10, 0)
dt = datetime(2019, 6, 11, 10, 0, tzinfo=timezone.utc)
assert vt2value(value2vt(dt)) == dt
assert vt2value(value2vt(u'foo')) == u'foo'
assert vt2value(value2vt(u'')) == u''
Expand Down