def test_getstream_correct_length(self): """ [Content_Types].xml retrieved as stream has correct element count """ fs = ZipFileSystem(zip_pkg_path) stream = fs.getstream("/[Content_Types].xml") content_types_elm = etree.parse(stream).getroot() assert_that(len(content_types_elm), is_(24))
def test_write_element_raises_on_dup_itemuri(self): """ZipFileSystem.write_element() raises on duplicate itemURI""" # setup ----------------------- elm = etree.fromstring(self.xml_in) itemURI = "/ppt/test.xml" zipfs = ZipFileSystem(test_save_pptx_path, "w") # exercise -------------------- zipfs.write_element(elm, itemURI) # verify ---------------------- with self.assertRaises(DuplicateKeyError): zipfs.write_element(elm, itemURI)
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_write_element_round_trips(self): """ZipFileSystem.write_element() round-trips intact""" # setup ----------------------- elm = etree.fromstring(self.xml_in) itemURI = "/ppt/test.xml" zipfs = ZipFileSystem(test_save_pptx_path, "w") # exercise -------------------- zipfs.write_element(elm, itemURI) # verify ---------------------- stream = zipfs.getstream(itemURI) xml_out = stream.read() stream.close() expected = self.xml_out actual = xml_out msg = "expected \n%s\n, got\n%s" % (expected, actual) self.assertEqual(expected, actual, msg)