forked from python-openxml/python-opc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunitdata.py
More file actions
101 lines (81 loc) · 2.9 KB
/
unitdata.py
File metadata and controls
101 lines (81 loc) · 2.9 KB
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
# -*- coding: utf-8 -*-
#
# unitdata.py
#
# Copyright (C) 2013 Steve Canny scanny@cisco.com
#
# This module is part of python-pptx and is released under the MIT License:
# http://www.opensource.org/licenses/mit-license.php
"""Test data builders for unit tests"""
from opc.constants import NAMESPACE as NS
from opc.oxml import oxml_fromstring
class BaseBuilder(object):
"""
Provides common behavior for all data builders.
"""
@property
def element(self):
"""Return element based on XML generated by builder"""
return oxml_fromstring(self.xml)
class CT_DefaultBuilder(BaseBuilder):
"""
Test data builder for CT_Default (Default) XML element that appears in
`[Content_Types].xml`.
"""
def __init__(self):
"""Establish instance variables with default values"""
self._content_type = 'application/xml'
self._extension = 'xml'
self._namespace = ' xmlns="%s"' % NS.OPC_CONTENT_TYPES
@property
def xml(self):
"""Return Default element"""
tmpl = '<Default%s Extension="%s" ContentType="%s"/>\n'
return tmpl % (self._namespace, self._extension, self._content_type)
class CT_OverrideBuilder(BaseBuilder):
"""
Test data builder for CT_Override (Override) XML element that appears in
`[Content_Types].xml`.
"""
def __init__(self):
"""Establish instance variables with default values"""
self._content_type = 'app/vnd.type'
self._namespace = ' xmlns="%s"' % NS.OPC_CONTENT_TYPES
self._partname = '/part/name.xml'
@property
def xml(self):
"""Return Override element"""
tmpl = '<Override%s PartName="%s" ContentType="%s"/>\n'
return tmpl % (self._namespace, self._partname, self._content_type)
class CT_RelationshipBuilder(BaseBuilder):
"""
Test data builder for CT_Relationship (Relationship) XML element that
appears in .rels files
"""
def __init__(self):
"""Establish instance variables with default values"""
self._rId = 'rId9'
self._reltype = 'ReLtYpE'
self._target = 'docProps/core.xml'
self._target_mode = None
self._namespace = ' xmlns="%s"' % NS.OPC_RELATIONSHIPS
@property
def target_mode(self):
if self._target_mode is None:
return ''
return ' TargetMode="%s"' % self._target_mode
@property
def xml(self):
"""Return Relationship element"""
tmpl = '<Relationship%s Id="%s" Type="%s" Target="%s"%s/>\n'
return tmpl % (self._namespace, self._rId, self._reltype,
self._target, self.target_mode)
def a_Default():
"""Return a CT_DefaultBuilder instance"""
return CT_DefaultBuilder()
def an_Override():
"""Return a CT_OverrideBuilder instance"""
return CT_OverrideBuilder()
def a_Relationship():
"""Return a CT_RelationshipBuilder instance"""
return CT_RelationshipBuilder()