本文整理汇总了Python中platemap.lib.sql_connection.TRN.rollback方法的典型用法代码示例。如果您正苦于以下问题:Python TRN.rollback方法的具体用法?Python TRN.rollback怎么用?Python TRN.rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类platemap.lib.sql_connection.TRN
的用法示例。
在下文中一共展示了TRN.rollback方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_post_rollback_funcs_error
# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import rollback [as 别名]
def test_post_rollback_funcs_error(self):
def func():
raise ValueError()
with self.assertRaises(RuntimeError):
with TRN:
TRN.add("SELECT 42")
TRN.add_post_rollback_func(func)
TRN.rollback()
示例2: test_post_rollback_funcs
# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import rollback [as 别名]
def test_post_rollback_funcs(self):
fd, fp = mkstemp()
close(fd)
self._files_to_remove.append(fp)
def func(fp):
with open(fp, 'w') as f:
f.write('\n')
with TRN:
TRN.add("SELECT 42")
TRN.add_post_rollback_func(func, fp)
TRN.rollback()
self.assertTrue(exists(fp))
示例3: test_execute_commit_false_rollback
# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import rollback [as 别名]
def test_execute_commit_false_rollback(self):
with TRN:
sql = """INSERT INTO barcodes.test_table (str_column, int_column)
VALUES (%s, %s) RETURNING str_column, int_column"""
args = [['insert1', 1], ['insert2', 2], ['insert3', 3]]
TRN.add(sql, args, many=True)
obs = TRN.execute()
exp = [[['insert1', 1]], [['insert2', 2]], [['insert3', 3]]]
self.assertEqual(obs, exp)
self._assert_sql_equal([])
TRN.rollback()
self._assert_sql_equal([])
示例4: test_context_manager_checker
# 需要导入模块: from platemap.lib.sql_connection import TRN [as 别名]
# 或者: from platemap.lib.sql_connection.TRN import rollback [as 别名]
def test_context_manager_checker(self):
with self.assertRaises(RuntimeError):
TRN.add("SELECT 42")
with self.assertRaises(RuntimeError):
TRN.execute()
with self.assertRaises(RuntimeError):
TRN.commit()
with self.assertRaises(RuntimeError):
TRN.rollback()
with TRN:
TRN.add("SELECT 42")
with self.assertRaises(RuntimeError):
TRN.execute()