Skip to content

Commit 0b3798d

Browse files
author
Steve Canny
committed
add CT_Relationships.new()
1 parent b3a4b5f commit 0b3798d

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

opc/oxml.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ def new():
199199
"""
200200
Return a new ``<Relationships>`` element.
201201
"""
202+
xml = '<Relationships xmlns="%s"/>' % nsmap['pr']
203+
relationships = oxml_fromstring(xml)
204+
objectify.deannotate(relationships, cleanup_namespaces=True)
205+
return relationships
202206

203207

204208
class CT_Types(OxmlBaseElement):

tests/test_oxml.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
"""Test suite for opc.oxml module."""
1111

1212
from opc.constants import RELATIONSHIP_TARGET_MODE as RTM
13-
from opc.oxml import CT_Default, CT_Override, CT_Relationship, CT_Types
13+
from opc.oxml import (
14+
CT_Default, CT_Override, CT_Relationship, CT_Relationships, CT_Types,
15+
oxml_tostring
16+
)
1417

1518
from .unitdata import a_Default, an_Override, a_Relationship, a_Types
1619

@@ -68,6 +71,19 @@ def it_can_construct_from_attribute_values(self):
6871
assert rel.xml == expected_rel_xml
6972

7073

74+
class DescribeCT_Relationships(object):
75+
76+
def it_can_construct_a_new_relationships_element(self):
77+
rels = CT_Relationships.new()
78+
actual_xml = oxml_tostring(rels, encoding='unicode',
79+
pretty_print=True)
80+
expected_xml = (
81+
'<Relationships xmlns="http://schemas.openxmlformats.org/package'
82+
'/2006/relationships"/>\n'
83+
)
84+
assert actual_xml == expected_xml
85+
86+
7187
class DescribeCT_Types(object):
7288

7389
def it_provides_access_to_default_child_elements(self):

0 commit comments

Comments
 (0)