📄 lock_tests.py
字号:
expected_status.tweak('A/D/gamma', 'A/B/lambda', writelocked='K') expected_status.tweak('A/B/E/alpha', 'iota', writelocked='O') svntest.actions.run_and_verify_status(wc_dir, expected_status) svntest.actions.run_and_verify_svn(None, ".*unlocked", [], 'unlock', '--username', svntest.main.wc_author, '--password', svntest.main.wc_passwd, '--no-auth-cache', gamma_path, lambda_path) expected_status.tweak('A/D/gamma', 'A/B/lambda', writelocked=None) expected_status.tweak('A/B/E/alpha', 'iota', writelocked=None) svntest.actions.run_and_verify_status(wc_dir, expected_status)def lock_uri_encoded(sbox): "lock and unlock a file with an URI-unsafe name" sbox.build() wc_dir = sbox.wc_dir # lock a file as wc_author fname = 'amazing space' file_path = os.path.join(wc_dir, fname) svntest.main.file_append(file_path, "This represents a binary file\n") svntest.actions.run_and_verify_svn(None, None, [], "add", file_path) expected_output = svntest.wc.State(wc_dir, { fname : Item(verb='Adding'), }) expected_status = svntest.actions.get_virginal_state(wc_dir, 1) expected_status.add({ fname: Item(wc_rev=2, status=' ') }) # Commit the file. svntest.actions.run_and_verify_commit(wc_dir, expected_output, expected_status, None, None, None, None, None, file_path) svntest.actions.run_and_verify_svn(None, ".*locked by user", [], 'lock', '--username', svntest.main.wc_author, '--password', svntest.main.wc_passwd, '-m', '', file_path) # Make sure that the file was locked. expected_status.tweak(fname, writelocked='K') svntest.actions.run_and_verify_status(wc_dir, expected_status) svntest.actions.run_and_verify_svn(None, ".*unlocked", [], 'unlock', '--username', svntest.main.wc_author, '--password', svntest.main.wc_passwd, file_path) # Make sure it was successfully unlocked again. expected_status.tweak(fname, writelocked=None) svntest.actions.run_and_verify_status(wc_dir, expected_status) # And now the URL case. file_url = svntest.main.current_repo_url + '/' + fname svntest.actions.run_and_verify_svn(None, ".*locked by user", [], 'lock', '--username', svntest.main.wc_author, '--password', svntest.main.wc_passwd, '-m', '', file_url) # Make sure that the file was locked. expected_status.tweak(fname, writelocked='O') svntest.actions.run_and_verify_status(wc_dir, expected_status) svntest.actions.run_and_verify_svn(None, ".*unlocked", [], 'unlock', '--username', svntest.main.wc_author, '--password', svntest.main.wc_passwd, file_url) # Make sure it was successfully unlocked again. expected_status.tweak(fname, writelocked=None) svntest.actions.run_and_verify_status(wc_dir, expected_status)#----------------------------------------------------------------------# A regression test for a bug when svn:needs-lock and svn:executable# interact badly. The bug was fixed in trunk @ r14859.def lock_and_exebit1(sbox): "svn:needs-lock and svn:executable, part I" mode_w = stat.S_IWUSR mode_x = stat.S_IXUSR mode_r = stat.S_IRUSR sbox.build() wc_dir = sbox.wc_dir gamma_path = os.path.join(wc_dir, 'A', 'D', 'gamma') svntest.actions.run_and_verify_svn(None, None, [], 'ps', 'svn:needs-lock', ' ', gamma_path) svntest.actions.run_and_verify_svn(None, None, [], 'ps', 'svn:executable', ' ', gamma_path) # commit svntest.actions.run_and_verify_svn(None, None, [], 'commit', '--username', svntest.main.wc_author, '--password', svntest.main.wc_passwd, '-m', '', gamma_path) # mode should be +r, -w, +x gamma_stat = os.stat (gamma_path)[0] if (not gamma_stat & mode_r or gamma_stat & mode_w or not gamma_stat & mode_x): print "Committing a file with 'svn:needs-lock, svn:executable'" print "did not set the file to read-only, executable" raise svntest.Failure # lock svntest.actions.run_and_verify_svn(None, ".*locked by user", [], 'lock', '--username', svntest.main.wc_author, '--password', svntest.main.wc_passwd, '-m', '', gamma_path) # mode should be +r, +w, +x gamma_stat = os.stat (gamma_path)[0] if (not gamma_stat & mode_r or not gamma_stat & mode_w or not gamma_stat & mode_x): print "Locking a file with 'svn:needs-lock, svn:executable'" print "did not set the file to read-write, executable" raise svntest.Failure # modify svntest.main.file_append(gamma_path, "check stat output after mod & unlock") # unlock svntest.actions.run_and_verify_svn(None, ".*unlocked", [], 'unlock', '--username', svntest.main.wc_author, '--password', svntest.main.wc_passwd, gamma_path) # Mode should be +r, -w, +x gamma_stat = os.stat (gamma_path)[0] if (not gamma_stat & mode_r or gamma_stat & mode_w or not gamma_stat & mode_x): print "Unlocking a file with 'svn:needs-lock, svn:executable'" print "did not set the file to read-only, executable" raise svntest.Failure # ci svntest.actions.run_and_verify_svn(None, None, [], 'commit', '--username', svntest.main.wc_author, '--password', svntest.main.wc_passwd, '-m', '', gamma_path) # Mode should be still +r, -w, +x gamma_stat = os.stat (gamma_path)[0] if (not gamma_stat & mode_r or gamma_stat & mode_w or not gamma_stat & mode_x): print "Commiting a file with 'svn:needs-lock, svn:executable'" print "after unlocking modified file's permissions" raise svntest.Failure#----------------------------------------------------------------------# A variant of lock_and_exebit1: same test without unlockdef lock_and_exebit2(sbox): "svn:needs-lock and svn:executable, part II" mode_w = stat.S_IWUSR mode_x = stat.S_IXUSR mode_r = stat.S_IRUSR sbox.build() wc_dir = sbox.wc_dir gamma_path = os.path.join(wc_dir, 'A', 'D', 'gamma') svntest.actions.run_and_verify_svn(None, None, [], 'ps', 'svn:needs-lock', ' ', gamma_path) svntest.actions.run_and_verify_svn(None, None, [], 'ps', 'svn:executable', ' ', gamma_path) # commit svntest.actions.run_and_verify_svn(None, None, [], 'commit', '--username', svntest.main.wc_author, '--password', svntest.main.wc_passwd, '-m', '', gamma_path) # mode should be +r, -w, +x gamma_stat = os.stat (gamma_path)[0] if (not gamma_stat & mode_r or gamma_stat & mode_w or not gamma_stat & mode_x): print "Committing a file with 'svn:needs-lock, svn:executable'" print "did not set the file to read-only, executable" raise svntest.Failure # lock svntest.actions.run_and_verify_svn(None, ".*locked by user", [], 'lock', '--username', svntest.main.wc_author, '--password', svntest.main.wc_passwd, '-m', '', gamma_path) # mode should be +r, +w, +x gamma_stat = os.stat (gamma_path)[0] if (not gamma_stat & mode_r or not gamma_stat & mode_w or not gamma_stat & mode_x): print "Locking a file with 'svn:needs-lock, svn:executable'" print "did not set the file to read-write, executable" raise svntest.Failure # modify svntest.main.file_append(gamma_path, "check stat output after mod & unlock") # commit svntest.actions.run_and_verify_svn(None, None, [], 'commit', '--username', svntest.main.wc_author, '--password', svntest.main.wc_passwd, '-m', '', gamma_path) # Mode should be +r, -w, +x gamma_stat = os.stat (gamma_path)[0] if (not gamma_stat & mode_r or gamma_stat & mode_w or not gamma_stat & mode_x): print "Commiting a file with 'svn:needs-lock, svn:executable'" print "did not set the file to read-only, executable" raise svntest.Failuredef commit_xml_unsafe_file_unlock(sbox): "commit file with xml-unsafe name and release lock" sbox.build() wc_dir = sbox.wc_dir fname = 'foo & bar' file_path = os.path.join(sbox.wc_dir, fname) svntest.main.file_append(file_path, "Initial data.\n") svntest.main.run_svn(None, 'add', file_path) svntest.main.run_svn(None, 'commit', '-m', '', file_path) # lock fname as wc_author svntest.actions.run_and_verify_svn(None, ".*locked by user", [], 'lock', '--username', svntest.main.wc_author, '--password', svntest.main.wc_passwd, '-m', 'some lock comment', file_path) # make a change and commit it, allowing lock to be released svntest.main.file_append(file_path, "Followup data.\n") svntest.main.run_svn(None, 'commit', '-m', '', file_path) expected_status = svntest.actions.get_virginal_state(wc_dir, 3) expected_status.tweak(wc_rev=1) expected_status.add({ fname : Item(status=' ', wc_rev=3), }) # Make sure the file is unlocked svntest.actions.run_and_verify_status(wc_dir, expected_status)#----------------------------------------------------------------------def repos_lock_with_info(sbox): "verify info path@X or path -rY return repos lock" sbox.build() wc_dir = sbox.wc_dir fname = 'iota' comment = 'This is a lock test.' file_path = os.path.join(sbox.wc_dir, fname) file_url = svntest.main.current_repo_url + '/' + fname # lock wc file svntest.actions.run_and_verify_svn(None, ".*locked by user", [], 'lock', '--username', svntest.main.wc_author2, '--password', svntest.main.wc_passwd, '--no-auth-cache', '-m', comment, file_path) expected_status = svntest.actions.get_virginal_state(wc_dir, 1) expected_status.tweak(fname, writelocked='K') svntest.actions.run_and_verify_status(wc_dir, expected_status) # Steal lock on wc file svntest.actions.run_and_verify_svn(None, ".*locked by user", [], 'lock', '--username', svntest.main.wc_author2, '--password', svntest.main.wc_passwd, '--no-auth-cache', '--force', '-m', comment, file_url) expected_status.tweak(fname, writelocked='T') svntest.actions.run_and_verify_status(wc_dir, expected_status) # Get repository lock token output, err = svntest.actions.run_and_verify_svn(None, None, [], 'info', file_url) for line in output: if line.find("Lock Token:") != -1: repos_lock_token = line[12:] break else: print "Error: Lock token not found" raise svntest.Failure # info with revision option output, err = svntest.actions.run_and_verify_svn(None, None, [], 'info', file_path, '-r1') for line in output: if line.find("Lock Token:") != -1: lock_token = line[12:] break else: print "Error: Lock token not found" raise svntest.Failure if (repos_lock_token != lock_token): print "Error: expected repository lock information not found." raise svntest.Failure # info with peg revision output, err = svntest.actions.run_and_verify_svn(None, None, [], 'info', file_path + '@1') for line in output:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -