def test_commit(self): with db.transaction(self.db.conn) as c: c.execute(""" INSERT INTO run (id, cwd, description, start_time) VALUES ('12345', 'cwd-here', 'useful description', 1370436103.65) """) db2 = db.DB(':memory:') c2 = db2.conn.cursor() c2.execute('select * from run') d = c2.fetchall() self.assertEqual(d, []) c3 = self.db.conn.cursor() c3.execute('select * from run') d = c3.fetchall() self.assertEqual(len(d), 1)
def test_commit(self): with db.transaction(self.db.conn) as c: c.execute( """ INSERT INTO run (id, cwd, description, start_time) VALUES ('12345', 'cwd-here', 'useful description', 1370436103.65) """) db2 = db.DB(':memory:') c2 = db2.conn.cursor() c2.execute('select * from run') d = c2.fetchall() self.assertEqual(d, []) c3 = self.db.conn.cursor() c3.execute('select * from run') d = c3.fetchall() self.assertEqual(len(d), 1)
def test_rollback(self): try: with db.transaction(self.db.conn) as c: c.execute(""" INSERT INTO run (id, cwd, description, start_time) VALUES ('12345', 'cwd-here', 'useful description', 1370436103.65) """) db2 = db.DB(':memory:') c2 = db2.conn.cursor() c2.execute('select * from run') d = c2.fetchall() self.assertEqual(d, []) raise RuntimeError('testing') except RuntimeError as err: self.assertEqual(str(err), 'testing') c3 = self.db.conn.cursor() c3.execute('select * from run') d = c3.fetchall() self.assertEqual(len(d), 0)
def test_rollback(self): try: with db.transaction(self.db.conn) as c: c.execute( """ INSERT INTO run (id, cwd, description, start_time) VALUES ('12345', 'cwd-here', 'useful description', 1370436103.65) """) db2 = db.DB(':memory:') c2 = db2.conn.cursor() c2.execute('select * from run') d = c2.fetchall() self.assertEqual(d, []) raise RuntimeError('testing') except RuntimeError as err: self.assertEqual(str(err), 'testing') c3 = self.db.conn.cursor() c3.execute('select * from run') d = c3.fetchall() self.assertEqual(len(d), 0)