Example #1
0
    def test_odf_to_sqlite(self):
        sqlite = None
        try:
            from sqlite3 import dbapi2 as sqlite    # Python25
        except ImportError:
            from pysqlite2 import dbapi2 as sqlite  # Python24 and pysqlite
        except ImportError:
            print 'Warning: SQLite not available'
            return

        doc = odf.load(self.file)
        fd, name = tempfile.mkstemp()
        odf.dump(doc, name)

        f = os.fdopen(fd, 'rb')
        s = f.read()
        f.close()
        blob1 = sqlite.Binary(s)

        blob2 = odf.OdfToSqlite(name)

        os.remove(name)

        self.assertEqual(blob1, blob2, 'Previously encoded data is not equal to OdfToSqlite() data')

        con = sqlite.connect(':memory:')
        cur = con.cursor()
        cur.execute("CREATE TABLE odf(document BLOB)")

        cur.execute("INSERT INTO odf VALUES (?)",(blob1,))
        con.commit()
        cur.execute("SELECT document FROM odf")
        blob3 = cur.fetchone()[0]

        self.assertEqual(blob1, blob3, 'Stored SQLite data is not equal to previously encoded data')
Example #2
0
 def test_dump(self):
     doc = odf.load(self.file)
     s1 = odf.dumps(doc)
     fd, name = tempfile.mkstemp()
     odf.dump(doc, name)
     f = os.fdopen(fd, 'rb')
     s2 = f.read()
     f.close()
     os.remove(name)
     self.assertEqual(s1, s2, 'File dump is not equal to string dumps')
Example #3
0
def main():
    """Main function, start module"""
    doc = parse_docs.get_doc('test.ods')
    doc = parse_docs.get_ods_doc_by_table_num(doc, 0)
    doc = clone_cycle(doc, 5, 'cycle_line')
    odf.dump(doc, '/tmp/dump.ods')