Skip to content

Commit b445e0d

Browse files
author
Steve Canny
committed
add Part.__init__()
1 parent fdd9ab2 commit b445e0d

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

opc/package.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,33 @@ class Part(object):
3838
intended to be subclassed in client code to implement specific part
3939
behaviors.
4040
"""
41+
def __init__(self, partname, content_type, blob):
42+
super(Part, self).__init__()
43+
self._partname = partname
44+
self._content_type = content_type
45+
self._blob = blob
46+
47+
@property
48+
def blob(self):
49+
"""
50+
Contents of this package part as a sequence of bytes. May be text or
51+
binary.
52+
"""
53+
return self._blob
54+
55+
@property
56+
def content_type(self):
57+
"""
58+
Content type of this part.
59+
"""
60+
return self._content_type
61+
62+
@property
63+
def partname(self):
64+
"""
65+
|PackURI| instance containing partname for this part.
66+
"""
67+
return self._partname
4168

4269

4370
class PartFactory(object):

tests/test_package.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from mock import call, Mock
1515

16-
from opc.package import OpcPackage, PartFactory, Unmarshaller
16+
from opc.package import OpcPackage, Part, PartFactory, Unmarshaller
1717

1818
from .unitutil import class_mock, method_mock
1919

@@ -46,6 +46,19 @@ def it_can_open_a_pkg_file(self, PackageReader_, PartFactory_,
4646
assert isinstance(pkg, OpcPackage)
4747

4848

49+
class DescribePart(object):
50+
51+
def it_remembers_its_construction_state(self):
52+
partname, content_type, blob = (
53+
Mock(name='partname'), Mock(name='content_type'),
54+
Mock(name='blob')
55+
)
56+
part = Part(partname, content_type, blob)
57+
assert part.blob == blob
58+
assert part.content_type == content_type
59+
assert part.partname == partname
60+
61+
4962
class DescribePartFactory(object):
5063

5164
@pytest.fixture

0 commit comments

Comments
 (0)