def read(path): """ Factory method to construct a new |Package| instance from package at *path*. The package can be either a zip archive (e.g. .docx file) or a directory containing an extracted package. """ phys_pkg = PhysPkg.read(path) pkg_items = {} for uri, blob in phys_pkg: pkg_items[uri] = PkgItem(phys_pkg.root_uri, uri, blob) return Package(pkg_items)
def it_should_construct_the_appropriate_subclass(self): pkg = PhysPkg.read(MINI_ZIP_PKG_PATH) assert isinstance(pkg, ZipPhysPkg) pkg = PhysPkg.read(MINI_DIR_PKG_PATH) assert isinstance(pkg, DirPhysPkg)
def it_should_close_zip_file_after_use(self, ZipFile_, zip_file_): # exercise --------------------- PhysPkg.read(MINI_ZIP_PKG_PATH) # verify ----------------------- ZipFile_.assert_called_once_with(MINI_ZIP_PKG_PATH, "r") zip_file_.close.assert_called_with()