📄 switch_tests.py
字号:
G_url = svntest.main.current_repo_url + '/A/D/G' G_psi_url = G_url + '/psi' svntest.actions.run_and_verify_svn(None, ['\n', 'Committed revision 2.\n'], [], 'mkdir', '-m', 'log msg', G_psi_url) H_path = os.path.join(wc_dir, 'A', 'D', 'H') psi_path = os.path.join(H_path, 'psi') svntest.main.file_append(psi_path, "more text") # This switch leaves psi unversioned, because of the local mods, # then fails because it tries to add a directory of the same name. out, err = svntest.main.run_svn(1, 'switch', '--username', svntest.main.wc_author, '--password', svntest.main.wc_passwd, G_url, H_path) if not err: raise svntest.Failure # Some items under H show up as switched because, while H itself was # switched, the switch command failed before it reached all items # # NOTE: I suspect this whole test is dependent on the order in # which changes are received, but since the new psi is a dir, it # appears we can count on it being received last. But if this test # ever starts failing, you read it here first :-). expected_status = svntest.actions.get_virginal_state(wc_dir, 2) expected_status.tweak(wc_rev=1) expected_status.tweak('A/D/H', status='! ', switched='S', wc_rev=2) expected_status.remove('A/D/H/psi', 'A/D/H/chi', 'A/D/H/omega') expected_status.add({ 'A/D/H/pi' : Item(status=' ', wc_rev=2), 'A/D/H/tau' : Item(status=' ', wc_rev=2), 'A/D/H/rho' : Item(status=' ', wc_rev=2), }) svntest.actions.run_and_verify_status(wc_dir, expected_status) # There was a bug whereby the failed switch left the wrong URL in # the target directory H. Check for that. out, err = svntest.actions.run_and_verify_svn(None, None, [], 'info', H_path) for line in out: if line.find('URL: ' + G_url) != -1: break else: raise svntest.Failure # Remove the now-unversioned psi, and repeat the switch. This # should complete the switch. os.remove(psi_path) svntest.actions.run_and_verify_svn(None, None, [], 'switch', '--username', svntest.main.wc_author, '--password', svntest.main.wc_passwd, G_url, H_path) expected_status.tweak('A/D/H', status=' ') # remains switched expected_status.add({ 'A/D/H/psi' : Item(status=' ', switched=None, wc_rev=2) }) svntest.actions.run_and_verify_status(wc_dir, expected_status)#----------------------------------------------------------------------# Issue #1826 - svn switch temporarily drops invalid URLs into the entries# files (which become not-temporary if the switch fails).def bad_intermediate_urls(sbox): "bad intermediate urls in use" sbox.build() wc_dir = sbox.wc_dir # We'll be switching our working copy to (a modified) A/C in the Greek tree. # First, make an extra subdirectory in C to match one in the root, plus # another one inside of that. C_url = svntest.main.current_repo_url + '/A/C' C_A_url = svntest.main.current_repo_url + '/A/C/A' C_A_Z_url = svntest.main.current_repo_url + '/A/C/A/Z' svntest.actions.run_and_verify_svn(None, ['\n', 'Committed revision 2.\n'], [], 'mkdir', '-m', 'log msg', C_A_url, C_A_Z_url) # Now, we'll drop a conflicting path under the root. A_path = os.path.join(wc_dir, 'A') A_Z_path = os.path.join(A_path, 'Z') svntest.main.file_append(A_Z_path, 'Look, Mom, no ... switch success.') # This switch should fail for reasons of obstruction. out, err = svntest.main.run_svn(1, 'switch', '--username', svntest.main.wc_author, '--password', svntest.main.wc_passwd, C_url, wc_dir) if not err: raise svntest.Failure # However, the URL for A should now reflect A/C/A, not something else. out, err = svntest.actions.run_and_verify_svn(None, None, [], 'info', A_path) if out[1].find('/A/C/A') == -1: raise svntest.Failure #----------------------------------------------------------------------# Regression test for issue #1825: failed switch may corrupt# working copydef obstructed_switch(sbox): "obstructed switch" sbox.build() wc_dir = sbox.wc_dir E_url = svntest.main.current_repo_url + '/A/B/E' E_url2 = svntest.main.current_repo_url + '/A/B/Esave' svntest.actions.run_and_verify_svn(None, ['\n', 'Committed revision 2.\n'], [], 'cp', '-m', 'msgcopy', E_url, E_url2) E_path = os.path.join(wc_dir, 'A', 'B', 'E') alpha_path = os.path.join(E_path, 'alpha') svntest.actions.run_and_verify_svn(None, None, [], 'rm', alpha_path) expected_status = svntest.actions.get_virginal_state(wc_dir, 3) expected_status.tweak(wc_rev=1) expected_status.remove('A/B/E/alpha') expected_output = svntest.wc.State(wc_dir, { 'A/B/E/alpha' : Item(verb='Deleting'), }) svntest.actions.run_and_verify_commit(wc_dir, expected_output, expected_status, None, None, None, None, None, wc_dir) svntest.main.file_append(alpha_path, "hello") out, err = svntest.main.run_svn(1, 'sw', E_url2, E_path) for line in err: if line.find("object of the same name already exists") != -1: break else: raise svntest.Failure os.remove(alpha_path) svntest.actions.run_and_verify_svn(None, None, [], 'sw', E_url2, E_path) expected_status = svntest.actions.get_virginal_state(wc_dir, 1) expected_status.tweak('A/B/E', 'A/B/E/alpha', 'A/B/E/beta', wc_rev=3) expected_status.tweak('A/B/E', switched='S') svntest.actions.run_and_verify_status(wc_dir, expected_status)#----------------------------------------------------------------------# Issue 2353.def commit_mods_below_switch(sbox): "commit with mods below switch" sbox.build() wc_dir = sbox.wc_dir C_path = os.path.join(wc_dir, 'A', 'C') B_url = svntest.main.current_repo_url + '/A/B' expected_output = svntest.wc.State(wc_dir, { 'A/C/E' : Item(status='A '), 'A/C/E/alpha' : Item(status='A '), 'A/C/E/beta' : Item(status='A '), 'A/C/F' : Item(status='A '), 'A/C/lambda' : Item(status='A '), }) expected_disk = svntest.main.greek_state.copy() expected_disk.add({ 'A/C/E' : Item(), 'A/C/E/alpha' : Item(contents="This is the file 'alpha'.\n"), 'A/C/E/beta' : Item(contents="This is the file 'beta'.\n"), 'A/C/F' : Item(), 'A/C/lambda' : Item(contents="This is the file 'lambda'.\n"), }) expected_status = svntest.actions.get_virginal_state(wc_dir, 1) expected_status.tweak('A/C', switched='S') expected_status.add({ 'A/C/E' : Item(status=' ', wc_rev=1), 'A/C/E/alpha' : Item(status=' ', wc_rev=1), 'A/C/E/beta' : Item(status=' ', wc_rev=1), 'A/C/F' : Item(status=' ', wc_rev=1), 'A/C/lambda' : Item(status=' ', wc_rev=1), }) svntest.actions.run_and_verify_switch(wc_dir, C_path, B_url, expected_output, expected_disk, expected_status) D_path = os.path.join(wc_dir, 'A', 'D') svntest.actions.run_and_verify_svn(None, None, [], 'propset', 'x', 'x', C_path, D_path) expected_status.tweak('A/C', 'A/D', status=' M') svntest.actions.run_and_verify_status(wc_dir, expected_status) expected_output = svntest.wc.State(wc_dir, { 'A/C' : Item(verb='Sending'), 'A/D' : Item(verb='Sending'), }) expected_status.tweak('A/C', 'A/D', status=' ', wc_rev=2) # A/C erroneously classified as a wc root caused the commit to fail # with "'A/C/E' is missing or not locked" svntest.actions.run_and_verify_commit(wc_dir, expected_output, expected_status, None, None, None, None, None, C_path, D_path)def relocate_beyond_repos_root(sbox): "relocate with prefixes longer than repo root" sbox.build() wc_dir = sbox.wc_dir repo_dir = sbox.repo_dir repo_url = sbox.repo_url other_repo_dir, other_repo_url = sbox.add_repo_path('other') svntest.main.copy_repos(repo_dir, other_repo_dir, 1) svntest.main.safe_rmtree(repo_dir, 1) A_url = repo_url + "/A" other_A_url = other_repo_url + "/A" other_B_url = other_repo_url + "/B" A_wc_dir = os.path.join(wc_dir, "A") # A relocate that changes the repo path part of the URL shouldn't work. # This tests for issue #2380. svntest.actions.run_and_verify_svn(None, None, ".*can only change the repository part.*", 'switch', '--relocate', A_url, other_B_url, A_wc_dir) # Another way of trying to change the fs path, leading to an invalid # repository root. svntest.actions.run_and_verify_svn(None, None, ".*is not the root.*", 'switch', '--relocate', repo_url, other_B_url, A_wc_dir) svntest.actions.run_and_verify_svn(None, None, [], 'switch', '--relocate', A_url, other_A_url, A_wc_dir) # Check that we can contact the repository, meaning that the # relocate actually changed the URI. Escape the expected URI to # avoid problems from any regex meta-characters it may contain # (e.g. '+'). escaped_exp = '^URL: ' + re.escape(other_A_url) + '$' svntest.actions.run_and_verify_svn(None, escaped_exp, [], 'info', '-rHEAD', A_wc_dir)#----------------------------------------------------------------------# Issue 2306.def refresh_read_only_attribute(sbox): "refresh the WC file system read-only attribute " sbox.build() wc_dir = sbox.wc_dir # Create a branch. url = svntest.main.current_repo_url + '/A' branch_url = svntest.main.current_repo_url + '/A-branch' svntest.actions.run_and_verify_svn(None, ['\n', 'Committed revision 2.\n'], [], 'cp', '-m', 'svn:needs-lock not set', url, branch_url) # Set the svn:needs-lock property on a file from the "trunk". A_path = os.path.join(wc_dir, 'A') mu_path = os.path.join(A_path, 'mu') svntest.actions.run_and_verify_svn(None, None, [], 'ps', 'svn:needs-lock', '1', mu_path) # Commit the propset of svn:needs-lock. expected_output = svntest.wc.State(wc_dir, { 'A/mu' : Item(verb='Sending'), }) expected_status = svntest.actions.get_virginal_state(wc_dir, 3) expected_status.tweak(wc_rev=1) expected_status.tweak('A/mu', wc_rev=3) svntest.actions.run_and_verify_commit(wc_dir, expected_output, expected_status, None, None, None, None, None, mu_path) # The file on which svn:needs-lock was set is now expected to be read-only. if os.access(mu_path, os.W_OK): raise svntest.Failure("'%s' expected to be read-only after having had " "its svn:needs-lock property set" % mu_path) # Switch to the branch with the WC state from before the propset of # svn:needs-lock. expected_output = svntest.wc.State(wc_dir, { 'A/mu' : Item(status=' U'), }) expected_disk = svntest.main.greek_state.copy() expected_status = svntest.actions.get_virginal_state(wc_dir, 3) expected_status.tweak('', wc_rev=1) expected_status.tweak('iota', wc_rev=1) expected_status.tweak('A', switched='S') svntest.actions.run_and_verify_switch(wc_dir, A_path, branch_url, expected_output, expected_disk, expected_status) # The file with we set svn:needs-lock on should now be writable, but # is still read-only! if not os.access(mu_path, os.W_OK): raise svntest.Failure("'%s' expected to be writable after being switched " "to a branch on which its svn:needs-lock property " "is not set" % mu_path)# Check that switch can't change the repository root.def switch_change_repos_root(sbox): "switch shouldn't allow changing repos root" sbox.build() wc_dir = sbox.wc_dir repo_url = sbox.repo_url other_repo_url = repo_url # Strip trailing slashes and add something bogus to that other URL. while other_repo_url[-1] == '/': other_repos_url = other_repo_url[:-1] other_repo_url = other_repo_url + "_bogus" other_A_url = other_repo_url + "/A" A_wc_dir = os.path.join(wc_dir, "A") # A switch that changes the repo root part of the URL shouldn't work. svntest.actions.run_and_verify_svn(None, None, ".*not the same repository.*", 'switch', other_A_url, A_wc_dir) # Make sure we didn't break the WC. expected_status = svntest.actions.get_virginal_state(wc_dir, 1) svntest.actions.run_and_verify_status(wc_dir, expected_status) ######################################################################### Run the tests# list all tests here, starting with None:test_list = [ None, routine_switching, commit_switched_things, full_update, full_rev_update, update_switched_things, rev_update_switched_things, log_switched_file, relocate_deleted_missing_copied, delete_subdir, XFail(file_dir_file), nonrecursive_switching, failed_anchor_is_target, bad_intermediate_urls, obstructed_switch, commit_mods_below_switch, relocate_beyond_repos_root, refresh_read_only_attribute, switch_change_repos_root, ]if __name__ == '__main__': svntest.main.run_tests(test_list) # NOTREACHED### End of file.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -