Skip to content

Commit 9bb9e5f

Browse files
author
Steve Canny
committed
add PhysPkgWriter.__new__() factory method
1 parent eb9c314 commit 9bb9e5f

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

opc/phys_pkg.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class PhysPkgWriter(object):
2626
"""
2727
Factory for physical package writer objects.
2828
"""
29+
def __new__(cls, pkg_file):
30+
return ZipPkgWriter(pkg_file)
2931

3032

3133
class ZipPkgReader(object):
@@ -68,3 +70,9 @@ def rels_xml_for(self, source_uri):
6870
except KeyError:
6971
rels_xml = None
7072
return rels_xml
73+
74+
75+
class ZipPkgWriter(object):
76+
"""
77+
Implements |PhysPkgWriter| interface for a zip file OPC package.
78+
"""

tests/test_phys_pkg.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import hashlib
1313

1414
from opc.packuri import PACKAGE_URI, PackURI
15-
from opc.phys_pkg import PhysPkgReader, ZipPkgReader
15+
from opc.phys_pkg import PhysPkgReader, PhysPkgWriter, ZipPkgReader
1616

1717
import pytest
1818

@@ -45,6 +45,22 @@ def it_constructs_a_pkg_reader_instance(self, ZipPkgReader_):
4545
assert phys_pkg_reader == ZipPkgReader_.return_value
4646

4747

48+
class DescribePhysPkgWriter(object):
49+
50+
@pytest.fixture
51+
def ZipPkgWriter_(self, request):
52+
return class_mock('opc.phys_pkg.ZipPkgWriter', request)
53+
54+
def it_constructs_a_pkg_writer_instance(self, ZipPkgWriter_):
55+
# mockery ----------------------
56+
pkg_file = Mock(name='pkg_file')
57+
# exercise ---------------------
58+
phys_pkg_writer = PhysPkgWriter(pkg_file)
59+
# verify -----------------------
60+
ZipPkgWriter_.assert_called_once_with(pkg_file)
61+
assert phys_pkg_writer == ZipPkgWriter_.return_value
62+
63+
4864
class DescribeZipPkgReader(object):
4965

5066
@pytest.fixture(scope='class')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy