Пример #1
0
 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)
Пример #2
0
 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)
Пример #3
0
 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)
Пример #4
0
 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)
Пример #5
0
 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)
Пример #6
0
 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)
Пример #7
0
 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)
Пример #8
0
 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)
Пример #9
0
 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)
Пример #10
0
 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)
Пример #11
0
 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)
Пример #12
0
 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)
Пример #13
0
 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)
Пример #14
0
 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)
Пример #15
0
    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)
Пример #16
0
    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)
Пример #17
0
    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)
Пример #18
0
    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)
Пример #19
0
 def get_empty_odt(self):
     with open(getdatafile('empty.odt'), 'rb') as fp:
         return fp.read()
Пример #20
0
 def get_empty_odt(self):
     with open(getdatafile('empty.odt'), 'rb') as fp:
         return fp.read()