Skip to content

Commit ad52d8d

Browse files
author
Steve Canny
committed
add ZipPkgReader.content_types_xml
1 parent 30c69a4 commit ad52d8d

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

opc/phys_pkg.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class ZipPkgReader(object):
2626
"""
2727
Implements |PhysPkgReader| interface for a zip file OPC package.
2828
"""
29+
_CONTENT_TYPES_MEMBERNAME = '[Content_Types].xml'
30+
2931
def __init__(self, pkg_file):
3032
super(ZipPkgReader, self).__init__()
3133
self._zipf = ZipFile(pkg_file, 'r')
@@ -41,3 +43,4 @@ def content_types_xml(self):
4143
"""
4244
Return the `[Content_Types].xml` blob from the zip package.
4345
"""
46+
return self._zipf.read(self._CONTENT_TYPES_MEMBERNAME)

tests/test_phys_pkg.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@
99

1010
"""Test suite for opc.phys_pkg module."""
1111

12+
import hashlib
13+
1214
from opc.phys_pkg import PhysPkgReader, ZipPkgReader
1315

1416
import pytest
1517

1618
from mock import Mock
1719

18-
from .unitutil import class_mock
20+
from .unitutil import abspath, class_mock
21+
22+
23+
test_pptx_path = abspath('test_files/test.pptx')
1924

2025

2126
@pytest.fixture
@@ -41,6 +46,12 @@ def it_constructs_a_pkg_reader_instance(self, ZipPkgReader_):
4146

4247
class DescribeZipPkgReader(object):
4348

49+
@pytest.fixture(scope='class')
50+
def phys_reader(self, request):
51+
phys_reader = ZipPkgReader(test_pptx_path)
52+
request.addfinalizer(phys_reader.close)
53+
return phys_reader
54+
4455
def it_opens_pkg_file_zip_on_construction(self, ZipFile_):
4556
pkg_file = Mock(name='pkg_file')
4657
ZipPkgReader(pkg_file)
@@ -54,3 +65,7 @@ def it_can_be_closed(self, ZipFile_):
5465
zip_pkg_reader.close()
5566
# verify -----------------------
5667
zipf.close.assert_called_once_with()
68+
69+
def it_has_the_content_types_xml(self, phys_reader):
70+
sha1 = hashlib.sha1(phys_reader.content_types_xml).hexdigest()
71+
assert sha1 == '9604a4fb3bf9626f5ad59a4e82029b3a501f106a'

0 commit comments

Comments
 (0)