def test_new_from_otg(self): templatename = getdatafile('template.otg') filename = getdatafile('newfromtemplate.odg') doc = _new_doc_from_template(filename, templatename) doc.save() self.assertTrue(check_zipfile_for_oasis_validity(filename, b"application/vnd.oasis.opendocument.graphics")) os.remove(filename)
def open_and_saveas(self, filename, msg=""): infile = getdatafile(filename) names1 = get_zip_names(infile) outfile = getdatafile('new.'+filename) odt = document.opendoc(infile) odt.saveas(outfile) names2 = get_zip_names(outfile) remove(outfile) self.assertSequenceEqual(sorted(names1), sorted(names2), msg)
def open_and_saveas(self, filename, msg=""): infile = getdatafile(filename) names1 = get_zip_names(infile) outfile = getdatafile('new.' + filename) odt = document.opendoc(infile) odt.saveas(outfile) names2 = get_zip_names(outfile) remove(outfile) self.assertSequenceEqual(sorted(names1), sorted(names2), msg)
def test_new_from_otg(self): templatename = getdatafile('template.otg') filename = getdatafile('newfromtemplate.odg') doc = _new_doc_from_template(filename, templatename) doc.save() self.assertTrue( check_zipfile_for_oasis_validity( filename, b"application/vnd.oasis.opendocument.graphics")) os.remove(filename)
def open_and_saveas_in_memory(self, filename, msg=""): infile = getdatafile(filename) names1 = get_zip_names(infile) outfile = getdatafile('new.'+filename) odt = document.opendoc(infile) io = StringIO() odt.saveas(io) names2 = get_zip_names(io) #no need to remove(outfile) self.assertSequenceEqual(sorted(names1), sorted(names2), msg)
def open_and_saveas_in_memory(self, filename, msg=""): infile = getdatafile(filename) names1 = get_zip_names(infile) outfile = getdatafile('new.' + filename) odt = document.opendoc(infile) io = StringIO() odt.saveas(io) names2 = get_zip_names(io) #no need to remove(outfile) self.assertSequenceEqual(sorted(names1), sorted(names2), msg)
def open_in_memory_and_saveas(self, filename, msg=""): infile = getdatafile(filename) names1 = get_zip_names(infile) outfile = getdatafile('new.' + filename) with open(os.path.join("tests", "data", filename), "rb") as f: content = f.read() odt = document.opendoc(self.stream_class_or_callable(content)) odt.saveas(outfile) names2 = get_zip_names(outfile) remove(outfile) self.assertSequenceEqual(sorted(names1), sorted(names2), msg)
def new_from_in_memory_template_and_saveas(self, filename, msg=""): infile = getdatafile(filename) names1 = get_zip_names(infile) outfile = getdatafile('new.'+filename) with open(os.path.join("tests", "data", filename), "rb") as f: content = f.read() odt = document.newdoc(template=self.stream_class_or_callable(content)) odt.saveas(outfile) names2 = get_zip_names(outfile) remove(outfile) self.assertSequenceEqual(sorted(names1), sorted(names2), msg)
def open_in_memory_and_saveas(self, filename, msg=""): infile = getdatafile(filename) names1 = get_zip_names(infile) outfile = getdatafile('new.'+filename) with open(os.path.join("tests", "data", filename), "rb") as f: content = f.read() odt = document.opendoc(StringIO(content)) odt.saveas(outfile) names2 = get_zip_names(outfile) remove(outfile) self.assertSequenceEqual(sorted(names1), sorted(names2), msg)
def new_from_in_memory_template_and_saveas(self, filename, msg=""): infile = getdatafile(filename) names1 = get_zip_names(infile) outfile = getdatafile('new.'+filename) with open(os.path.join("tests", "data", filename), "rb") as f: content = f.read() odt = document.newdoc(template=StringIO(content)) odt.saveas(outfile) names2 = get_zip_names(outfile) remove(outfile) self.assertSequenceEqual(sorted(names1), sorted(names2), msg)
def test_save(self): SAVENAME = getdatafile('specs.save.odt') fm = filemanager.FileManager(SPECFILE) # to use save you have to register at least the mimetype file mimetype = fm.get_bytes('mimetype') fm.register('mimetype', mimetype) fm.save(SAVENAME, backup=False) self.assertTrue(check_zipfile_for_oasis_validity(SAVENAME, mimetype)) os.remove(SAVENAME)
def open_and_saveas_in_memory(self, filename, msg=""): infile = getdatafile(filename) names1 = get_zip_names(infile) odt = document.opendoc(infile) io = self.stream_class_or_callable() odt.saveas(io) names2 = get_zip_names(io) #no need to remove(outfile) self.assertSequenceEqual(sorted(names1), sorted(names2), msg)
def test_new_odp(self): docname = getdatafile('new.odp') doc = document.newdoc(doctype='odp', filename=docname) self.assertEqual(doc.mimetype, const.MIMETYPES['odp']) self.assertEqual(doc.docname, docname) self.assertIsNotNone(doc.meta) self.assertIsNotNone(doc.styles) self.assertIsNotNone(doc.content) self.assertIsNotNone(doc.body) doc.backup=False doc.save() self.assertTrue(os.path.exists(docname)) self.assertTrue(check_zipfile_for_oasis_validity(docname, b"application/vnd.oasis.opendocument.presentation")) remove(docname)
def test_copy_zip_to(self): def copy_file(from_, to_): fm = filemanager.FileManager(from_) zf = zipfile.ZipFile(to_, 'w', compression=zipfile.ZIP_DEFLATED) fm._copy_zip_to(zf) zf.close() NEWSPEC = getdatafile('newspecs.odt') specs = zipfile.ZipFile(SPECFILE) expectednames = specs.namelist() specs.close() copy_file(SPECFILE, NEWSPEC) newspecs = zipfile.ZipFile(NEWSPEC) resultnames = newspecs.namelist() newspecs.close() self.assertSequenceEqual(expectednames, resultnames) self.assertTrue(check_zipfile_for_oasis_validity(NEWSPEC, b"application/vnd.oasis.opendocument.text")) os.remove(NEWSPEC)
def get_empty_odt(self): with open(getdatafile('empty.odt'), 'rb') as fp: return fp.read()