Server IP : 103.119.228.120 / Your IP : 3.144.29.213 Web Server : Apache System : Linux v8.techscape8.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64 User : nobody ( 99) PHP Version : 5.6.40 Disable Function : shell_exec,symlink,system,exec,proc_get_status,proc_nice,proc_terminate,define_syslog_variables,syslog,openlog,closelog,escapeshellcmd,passthru,ocinum cols,ini_alter,leak,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dl,dll,myshellexec,proc_open,socket_bind,proc_close,escapeshellarg,parse_ini_filepopen,fpassthru,exec,passthru,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,popen,show_source,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,dl,symlink,shell_exec,system,dl,passthru,escapeshellarg,escapeshellcmd,myshellexec,c99_buff_prepare,c99_sess_put,fpassthru,getdisfunc,fx29exec,fx29exec2,is_windows,disp_freespace,fx29sh_getupdate,fx29_buff_prepare,fx29_sess_put,fx29shexit,fx29fsearch,fx29ftpbrutecheck,fx29sh_tools,fx29sh_about,milw0rm,imagez,sh_name,myshellexec,checkproxyhost,dosyayicek,c99_buff_prepare,c99_sess_put,c99getsource,c99sh_getupdate,c99fsearch,c99shexit,view_perms,posix_getpwuid,posix_getgrgid,posix_kill,parse_perms,parsesort,view_perms_color,set_encoder_input,ls_setcheckboxall,ls_reverse_all,rsg_read,rsg_glob,selfURL,dispsecinfo,unix2DosTime,addFile,system,get_users,view_size,DirFiles,DirFilesWide,DirPrintHTMLHeaders,GetFilesTotal,GetTitles,GetTimeTotal,GetMatchesCount,GetFileMatchesCount,GetResultFiles,fs_copy_dir,fs_copy_obj,fs_move_dir,fs_move_obj,fs_rmdir,SearchText,getmicrotime MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/local/ssl/local/ssl/local/ssl/lib/mysqlsh/lib/python3.9/sqlite3/test/ |
Upload File : |
import sqlite3 as sqlite import unittest @unittest.skipIf(sqlite.sqlite_version_info < (3, 6, 11), "Backup API not supported") class BackupTests(unittest.TestCase): def setUp(self): cx = self.cx = sqlite.connect(":memory:") cx.execute('CREATE TABLE foo (key INTEGER)') cx.executemany('INSERT INTO foo (key) VALUES (?)', [(3,), (4,)]) cx.commit() def tearDown(self): self.cx.close() def verify_backup(self, bckcx): result = bckcx.execute("SELECT key FROM foo ORDER BY key").fetchall() self.assertEqual(result[0][0], 3) self.assertEqual(result[1][0], 4) def test_bad_target_none(self): with self.assertRaises(TypeError): self.cx.backup(None) def test_bad_target_filename(self): with self.assertRaises(TypeError): self.cx.backup('some_file_name.db') def test_bad_target_same_connection(self): with self.assertRaises(ValueError): self.cx.backup(self.cx) def test_bad_target_closed_connection(self): bck = sqlite.connect(':memory:') bck.close() with self.assertRaises(sqlite.ProgrammingError): self.cx.backup(bck) def test_bad_source_closed_connection(self): bck = sqlite.connect(':memory:') source = sqlite.connect(":memory:") source.close() with self.assertRaises(sqlite.ProgrammingError): source.backup(bck) def test_bad_target_in_transaction(self): bck = sqlite.connect(':memory:') bck.execute('CREATE TABLE bar (key INTEGER)') bck.executemany('INSERT INTO bar (key) VALUES (?)', [(3,), (4,)]) with self.assertRaises(sqlite.OperationalError) as cm: self.cx.backup(bck) if sqlite.sqlite_version_info < (3, 8, 8): self.assertEqual(str(cm.exception), 'target is in transaction') def test_keyword_only_args(self): with self.assertRaises(TypeError): with sqlite.connect(':memory:') as bck: self.cx.backup(bck, 1) def test_simple(self): with sqlite.connect(':memory:') as bck: self.cx.backup(bck) self.verify_backup(bck) def test_progress(self): journal = [] def progress(status, remaining, total): journal.append(status) with sqlite.connect(':memory:') as bck: self.cx.backup(bck, pages=1, progress=progress) self.verify_backup(bck) self.assertEqual(len(journal), 2) self.assertEqual(journal[0], sqlite.SQLITE_OK) self.assertEqual(journal[1], sqlite.SQLITE_DONE) def test_progress_all_pages_at_once_1(self): journal = [] def progress(status, remaining, total): journal.append(remaining) with sqlite.connect(':memory:') as bck: self.cx.backup(bck, progress=progress) self.verify_backup(bck) self.assertEqual(len(journal), 1) self.assertEqual(journal[0], 0) def test_progress_all_pages_at_once_2(self): journal = [] def progress(status, remaining, total): journal.append(remaining) with sqlite.connect(':memory:') as bck: self.cx.backup(bck, pages=-1, progress=progress) self.verify_backup(bck) self.assertEqual(len(journal), 1) self.assertEqual(journal[0], 0) def test_non_callable_progress(self): with self.assertRaises(TypeError) as cm: with sqlite.connect(':memory:') as bck: self.cx.backup(bck, pages=1, progress='bar') self.assertEqual(str(cm.exception), 'progress argument must be a callable') def test_modifying_progress(self): journal = [] def progress(status, remaining, total): if not journal: self.cx.execute('INSERT INTO foo (key) VALUES (?)', (remaining+1000,)) self.cx.commit() journal.append(remaining) with sqlite.connect(':memory:') as bck: self.cx.backup(bck, pages=1, progress=progress) self.verify_backup(bck) result = bck.execute("SELECT key FROM foo" " WHERE key >= 1000" " ORDER BY key").fetchall() self.assertEqual(result[0][0], 1001) self.assertEqual(len(journal), 3) self.assertEqual(journal[0], 1) self.assertEqual(journal[1], 1) self.assertEqual(journal[2], 0) def test_failing_progress(self): def progress(status, remaining, total): raise SystemError('nearly out of space') with self.assertRaises(SystemError) as err: with sqlite.connect(':memory:') as bck: self.cx.backup(bck, progress=progress) self.assertEqual(str(err.exception), 'nearly out of space') def test_database_source_name(self): with sqlite.connect(':memory:') as bck: self.cx.backup(bck, name='main') with sqlite.connect(':memory:') as bck: self.cx.backup(bck, name='temp') with self.assertRaises(sqlite.OperationalError) as cm: with sqlite.connect(':memory:') as bck: self.cx.backup(bck, name='non-existing') self.assertIn( str(cm.exception), ['SQL logic error', 'SQL logic error or missing database', 'unknown database non-existing'] ) self.cx.execute("ATTACH DATABASE ':memory:' AS attached_db") self.cx.execute('CREATE TABLE attached_db.foo (key INTEGER)') self.cx.executemany('INSERT INTO attached_db.foo (key) VALUES (?)', [(3,), (4,)]) self.cx.commit() with sqlite.connect(':memory:') as bck: self.cx.backup(bck, name='attached_db') self.verify_backup(bck) def suite(): return unittest.makeSuite(BackupTests) if __name__ == "__main__": unittest.main()