本文整理汇总了Python中Tribler.Core.CacheDB.sqlitecachedb.SQLiteCacheDB.set_show_sql方法的典型用法代码示例。如果您正苦于以下问题:Python SQLiteCacheDB.set_show_sql方法的具体用法?Python SQLiteCacheDB.set_show_sql怎么用?Python SQLiteCacheDB.set_show_sql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tribler.Core.CacheDB.sqlitecachedb.SQLiteCacheDB
的用法示例。
在下文中一共展示了SQLiteCacheDB.set_show_sql方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSqliteCacheDB
# 需要导入模块: from Tribler.Core.CacheDB.sqlitecachedb import SQLiteCacheDB [as 别名]
# 或者: from Tribler.Core.CacheDB.sqlitecachedb.SQLiteCacheDB import set_show_sql [as 别名]
class TestSqliteCacheDB(TriblerCoreTest):
FILE_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
SQLITE_SCRIPTS_DIR = os.path.abspath(os.path.join(FILE_DIR, u"data/sqlite_scripts/"))
@inlineCallbacks
def setUp(self):
yield super(TestSqliteCacheDB, self).setUp()
db_path = u":memory:"
self.sqlite_test = SQLiteCacheDB(db_path)
self.sqlite_test.set_show_sql(True)
def tearDown(self):
self.sqlite_test.close()
self.sqlite_test = None
super(TestSqliteCacheDB, self).tearDown()
def test_create_db(self):
sql = u"CREATE TABLE person(lastname, firstname);"
self.sqlite_test.execute(sql)
self.assertIsInstance(self.sqlite_test.version, int)
@raises(OSError)
def test_no_file_db_error(self):
file_dir = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
sqlite_test_2 = SQLiteCacheDB(file_dir)
def test_open_db_new_file(self):
db_path = os.path.join(self.session_base_dir, "test_db.db")
sqlite_test_2 = SQLiteCacheDB(db_path)
self.assertTrue(os.path.isfile(db_path))
@raises(OSError)
def test_open_db_script_file_invalid_location(self):
sqlite_test_2 = SQLiteCacheDB(os.path.join(self.session_base_dir, "test_db.db"), u'myfakelocation')
@raises(OSError)
def test_open_db_script_file_directory(self):
file_dir = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
sqlite_test_2 = SQLiteCacheDB(os.path.join(self.session_base_dir, "test_db.db"), file_dir)
def test_open_db_script_file(self):
sqlite_test_2 = SQLiteCacheDB(os.path.join(self.session_base_dir, "test_db.db"), DB_SCRIPT_ABSOLUTE_PATH)
sqlite_test_2.write_version(4)
self.assertEqual(sqlite_test_2.version, 4)
@raises(SQLError)
def test_failed_commit(self):
sqlite_test_2 = SQLiteCacheDB(os.path.join(self.session_base_dir, "test_db.db"), DB_SCRIPT_ABSOLUTE_PATH)
sqlite_test_2.initial_begin()
sqlite_test_2.write_version(4)
@skipIf(sys.platform == "win32", "chmod does not work on Windows")
@raises(IOError)
def test_no_permission_on_script(self):
db_path = os.path.join(self.session_base_dir, "test_db.db")
new_script_path = os.path.join(self.session_base_dir, "script.sql")
shutil.copyfile(DB_SCRIPT_ABSOLUTE_PATH, new_script_path)
os.chmod(new_script_path, 0)
sqlite_test_2 = SQLiteCacheDB(db_path, new_script_path)
@raises(CorruptedDatabaseError)
def test_no_version_info_in_database(self):
sqlite_test_2 = SQLiteCacheDB(os.path.join(self.session_base_dir, "test_db.db"),
os.path.join(self.SQLITE_SCRIPTS_DIR, "script1.sql"))
@raises(CorruptedDatabaseError)
def test_integrity_check_failed(self):
sqlite_test_2 = SQLiteCacheDB(os.path.join(self.session_base_dir, "test_db.db"),
os.path.join(self.SQLITE_SCRIPTS_DIR, "script1.sql"))
def execute(sql):
if sql == u"PRAGMA quick_check":
db_response = MockObject()
db_response.next = lambda: ("Error: database disk image is malformed", )
return db_response
sqlite_test_2.execute = execute
def test_integrity_check_triggered(self):
""" Tests if integrity check is triggered if temporary rollback files are present."""
def do_integrity_check(_):
do_integrity_check.called = True
db_path = os.path.join(self.session_base_dir, "test_db.db")
sqlite_test = SQLiteCacheDB(db_path)
sqlite_test.do_quick_integrity_check = do_integrity_check
do_integrity_check.called = False
self.assertFalse(do_integrity_check.called)
db_path2 = os.path.join(self.session_base_dir, "test_db2.db")
wal_file = open(os.path.join(self.session_base_dir, "test_db2.db-shm"), 'w')
wal_file.close()
do_integrity_check.called = False
SQLiteCacheDB.do_quick_integrity_check = do_integrity_check
#.........这里部分代码省略.........