def test_getstream_raises_on_bad_URI(self): """ZipFileSystem.getstream() raises on bad URI""" # setup ----------------------- fs = FileSystem(zip_pkg_path) # verify ---------------------- with self.assertRaises(LookupError): fs.getstream("!blat/rhumba.xml")
def test_getblob_raises_on_bad_itemuri(self): """BaseFileSystem.getblob(itemURI) raises on bad itemURI""" # setup ----------------------- bad_itemURI = "/spam/eggs/egg1.xml" fs = FileSystem(zip_pkg_path) # verify ---------------------- with self.assertRaises(LookupError): fs.getblob(bad_itemURI)
def test_getblob_correct_length(self): """BaseFileSystem.getblob() returns object of expected length""" # setup ----------------------- partname = "/docProps/thumbnail.jpeg" fs = FileSystem(zip_pkg_path) # exercise -------------------- blob = fs.getblob(partname) # verify ---------------------- self.assertLength(blob, 8147)
def test_write_blob_raises_on_dup_itemuri(self): """ZipFileSystem.write_blob() raises on duplicate itemURI""" # setup ----------------------- partname = "/docProps/thumbnail.jpeg" fs = FileSystem(zip_pkg_path) blob = fs.getblob(partname) test_fs = ZipFileSystem(test_save_pptx_path, "w") test_fs.write_blob(blob, partname) # verify ---------------------- with self.assertRaises(DuplicateKeyError): test_fs.write_blob(blob, partname)
def test_write_blob_round_trips(self): """ZipFileSystem.write_blob() round-trips intact""" # setup ----------------------- partname = "/docProps/thumbnail.jpeg" fs = FileSystem(zip_pkg_path) in_blob = fs.getblob(partname) test_fs = ZipFileSystem(test_save_pptx_path, "w") # exercise -------------------- test_fs.write_blob(in_blob, partname) # verify ---------------------- out_blob = test_fs.getblob(partname) expected = in_blob actual = out_blob msg = "retrived blob (len %d) differs from original (len %d)" % (len(actual), len(expected)) self.assertEqual(expected, actual, msg)
def test_getelement_raises_on_binary(self): """Calling getelement() for binary item raises exception""" # call getelement for thumbnail fs = FileSystem(zip_pkg_path) with self.assertRaises(NotXMLError): fs.getelement("/docProps/thumbnail.jpeg")