📄 basic_tests.py
字号:
if not ((len (lines) == 1) and (lines[0] == "This is the file 'beta'.\n")): print "Revert failed to restore original text." raise svntest.Failure fp = open(iota_path, 'r') lines = fp.readlines() if not ((len (lines) == 1) and (lines[0] == "This is the file 'iota'.\n")): print "Revert failed to restore original text." raise svntest.Failure fp = open(rho_path, 'r') lines = fp.readlines() if not ((len (lines) == 1) and (lines[0] == "This is the file 'rho'.\n")): print "Revert failed to restore original text." raise svntest.Failure fp = open(zeta_path, 'r') lines = fp.readlines() if not ((len (lines) == 1) and (lines[0] == "Added some text to 'zeta'.\n")): ### we should raise a less generic error here. which? raise svntest.Failure # Finally, check that reverted file is not readonly os.remove(beta_path) svntest.actions.run_and_verify_svn(None, None, [], 'revert', beta_path) if not (open(beta_path, 'rw+')): raise svntest.Failure # Check that a directory scheduled to be added, but physically # removed, can be reverted. X_path = os.path.join(wc_dir, 'X') svntest.actions.run_and_verify_svn(None, None, [], 'mkdir', X_path) expected_status = svntest.actions.get_virginal_state(wc_dir, 1) expected_status.add({ 'X' : Item(status='A ', wc_rev=0), }) svntest.actions.run_and_verify_status (wc_dir, expected_status) svntest.main.safe_rmtree(X_path) svntest.actions.run_and_verify_svn(None, None, [], 'revert', X_path) expected_status.remove('X') svntest.actions.run_and_verify_status (wc_dir, expected_status) # Check that a directory scheduled for deletion, but physically # removed, can be reverted. E_path = os.path.join(wc_dir, 'A', 'B', 'E') expected_status = svntest.actions.get_virginal_state(wc_dir, 1) ### Most of the rest of this test is ineffective, due to the ### problems described in issue #1611. svntest.actions.run_and_verify_svn("", None, [], 'rm', E_path) svntest.main.safe_rmtree(E_path) expected_status.tweak('A/B/E', status='D ') expected_status.tweak('A/B/E', wc_rev='?') ### FIXME: A weakness in the test framework, described in detail ### in issue #1611, prevents us from checking via status. Grr. # # svntest.actions.run_and_verify_status (wc_dir, expected_status, # None, None, None, None) # # ### If you were to uncomment the above, you'd get an error like so: # # ============================================================= # Expected E and actual E are different! # ============================================================= # EXPECTED NODE TO BE: # ============================================================= # * Node name: E # Path: working_copies/basic_tests-10/A/B/E # Contents: None # Properties: {} # Attributes: {'status': 'D ', 'wc_rev': '?'} # Children: 2 # ============================================================= # ACTUAL NODE FOUND: # ============================================================= # * Node name: E # Path: working_copies/basic_tests-10/A/B/E # Contents: None # Properties: {} # Attributes: {'status': 'D ', 'wc_rev': '?'} # Children: is a file. # Unequal Types: one Node is a file, the other is a directory # This will actually print # # "Failed to revert 'working_copies/basic_tests-10/A/B/E' -- \ # try updating instead." # # ...but due to test suite lossage, it'll still look like success. svntest.actions.run_and_verify_svn(None, None, [], 'revert', E_path) ### FIXME: Again, the problem described in issue #1611 bites us here. # # expected_status.tweak('A/B/E', status=' ') # svntest.actions.run_and_verify_status (wc_dir, expected_status, # None, None, None, None) #----------------------------------------------------------------------def basic_switch(sbox): "basic switch command" sbox.build() wc_dir = sbox.wc_dir ### Switch the file `iota' to `A/D/gamma'. # Construct some paths for convenience iota_path = os.path.join(wc_dir, 'iota') gamma_url = svntest.main.current_repo_url + '/A/D/gamma' # Create expected output tree expected_output = wc.State(wc_dir, { 'iota' : Item(status='U '), }) # Create expected disk tree (iota will have gamma's contents) expected_disk = svntest.main.greek_state.copy() expected_disk.tweak('iota', contents=expected_disk.desc['A/D/gamma'].contents) # Create expected status tree expected_status = svntest.actions.get_virginal_state(wc_dir, 1) expected_status.tweak('iota', switched='S') # Do the switch and check the results in three ways. svntest.actions.run_and_verify_switch(wc_dir, iota_path, gamma_url, expected_output, expected_disk, expected_status) ### Switch the directory `A/D/H' to `A/D/G'. # Construct some paths for convenience ADH_path = os.path.join(wc_dir, 'A', 'D', 'H') chi_path = os.path.join(ADH_path, 'chi') omega_path = os.path.join(ADH_path, 'omega') psi_path = os.path.join(ADH_path, 'psi') pi_path = os.path.join(ADH_path, 'pi') tau_path = os.path.join(ADH_path, 'tau') rho_path = os.path.join(ADH_path, 'rho') ADG_url = svntest.main.current_repo_url + '/A/D/G' # Create expected output tree expected_output = wc.State(wc_dir, { 'A/D/H/chi' : Item(status='D '), 'A/D/H/omega' : Item(status='D '), 'A/D/H/psi' : Item(status='D '), 'A/D/H/pi' : Item(status='A '), 'A/D/H/rho' : Item(status='A '), 'A/D/H/tau' : Item(status='A '), }) # Create expected disk tree (iota will have gamma's contents, # A/D/H/* will look like A/D/G/*) expected_disk = svntest.main.greek_state.copy() expected_disk.tweak('iota', contents=expected_disk.desc['A/D/gamma'].contents) expected_disk.remove('A/D/H/chi', 'A/D/H/omega', 'A/D/H/psi') expected_disk.add({ 'A/D/H/pi' : Item("This is the file 'pi'.\n"), 'A/D/H/rho' : Item("This is the file 'rho'.\n"), 'A/D/H/tau' : Item("This is the file 'tau'.\n"), }) # Create expected status expected_status = svntest.actions.get_virginal_state(wc_dir, 1) expected_status.remove('A/D/H/chi', 'A/D/H/omega', 'A/D/H/psi') expected_status.add({ 'A/D/H/pi' : Item(status=' ', wc_rev=1), 'A/D/H/rho' : Item(status=' ', wc_rev=1), 'A/D/H/tau' : Item(status=' ', wc_rev=1), }) expected_status.tweak('iota', 'A/D/H', switched='S') # Do the switch and check the results in three ways. svntest.actions.run_and_verify_switch(wc_dir, ADH_path, ADG_url, expected_output, expected_disk, expected_status)#----------------------------------------------------------------------def verify_file_deleted(message, path): try: open(path, 'r') except IOError: return if message is not None: print message ###TODO We should raise a less generic error here. which? raise Failure def can_cd_to_dir(path): current_dir = os.getcwd() try: os.chdir(path) except OSError: return 0 os.chdir(current_dir) return 1 def basic_delete(sbox): "basic delete command" sbox.build() wc_dir = sbox.wc_dir # modify text of chi chi_parent_path = os.path.join(wc_dir, 'A', 'D', 'H') chi_path = os.path.join(chi_parent_path, 'chi') svntest.main.file_append(chi_path, 'added to chi') # modify props of rho (file) rho_parent_path = os.path.join(wc_dir, 'A', 'D', 'G') rho_path = os.path.join(rho_parent_path, 'rho') svntest.main.run_svn(None, 'ps', 'abc', 'def', rho_path) # modify props of F (dir) F_parent_path = os.path.join(wc_dir, 'A', 'B') F_path = os.path.join(F_parent_path, 'F') svntest.main.run_svn(None, 'ps', 'abc', 'def', F_path) # unversioned file sigma_parent_path = os.path.join(wc_dir, 'A', 'C') sigma_path = os.path.join(sigma_parent_path, 'sigma') svntest.main.file_append(sigma_path, 'unversioned sigma') # unversioned directory Q_parent_path = sigma_parent_path Q_path = os.path.join(Q_parent_path, 'Q') os.mkdir(Q_path) # added directory hierarchies X_parent_path = os.path.join(wc_dir, 'A', 'B') X_path = os.path.join(X_parent_path, 'X') svntest.main.run_svn(None, 'mkdir', X_path) X_child_path = os.path.join(X_path, 'xi') svntest.main.file_append(X_child_path, 'added xi') svntest.main.run_svn(None, 'add', X_child_path) Y_parent_path = os.path.join(wc_dir, 'A', 'D') Y_path = os.path.join(Y_parent_path, 'Y') svntest.main.run_svn(None, 'mkdir', Y_path) # check status expected_output = svntest.actions.get_virginal_state(wc_dir, 1) expected_output.tweak('A/D/H/chi', status='M ') expected_output.tweak('A/D/G/rho', 'A/B/F', status=' M')# expected_output.tweak('A/C/sigma', status='? ') expected_output.add({ 'A/B/X' : Item(status='A ', wc_rev=0), 'A/B/X/xi' : Item(status='A ', wc_rev=0), 'A/D/Y' : Item(status='A ', wc_rev=0), }) svntest.actions.run_and_verify_status(wc_dir, expected_output) # 'svn rm' that should fail svntest.actions.run_and_verify_svn(None, None, SVNAnyOutput, 'rm', chi_path) svntest.actions.run_and_verify_svn(None, None, SVNAnyOutput, 'rm', chi_parent_path) svntest.actions.run_and_verify_svn(None, None, SVNAnyOutput, 'rm', rho_path) svntest.actions.run_and_verify_svn(None, None, SVNAnyOutput, 'rm', rho_parent_path) svntest.actions.run_and_verify_svn(None, None, SVNAnyOutput, 'rm', F_path) svntest.actions.run_and_verify_svn(None, None, SVNAnyOutput, 'rm', F_parent_path) svntest.actions.run_and_verify_svn(None, None, SVNAnyOutput, 'rm', sigma_path) svntest.actions.run_and_verify_svn(None, None, SVNAnyOutput, 'rm', sigma_parent_path) svntest.actions.run_and_verify_svn(None, None, SVNAnyOutput, 'rm', X_path) # check status has not changed svntest.actions.run_and_verify_status (wc_dir, expected_output) # 'svn rm' that should work E_path = os.path.join(wc_dir, 'A', 'B', 'E') svntest.actions.run_and_verify_svn(None, None, [], 'rm', E_path) # 'svn rm --force' that should work svntest.actions.run_and_verify_svn(None, None, [], 'rm', '--force', chi_parent_path) svntest.actions.run_and_verify_svn(None, None, [], 'rm', '--force', rho_parent_path) svntest.actions.run_and_verify_svn(None, None, [], 'rm', '--force', F_path) svntest.actions.run_and_verify_svn(None, None, [], 'rm', '--force', sigma_parent_path) svntest.actions.run_and_verify_svn(None, None, [], 'rm', '--force', X_path) # Deleting already removed from wc versioned item with --force iota_path = os.path.join(wc_dir, 'iota') os.remove(iota_path) svntest.actions.run_and_verify_svn(None, None, [], 'rm', '--force', iota_path) # and without --force gamma_path = os.path.join(wc_dir, 'A', 'D', 'gamma') os.remove(gamma_path) svntest.actions.run_and_verify_svn(None, None, [], 'rm', gamma_path) # Deleting already scheduled for deletion doesn't require --force svntest.actions.run_and_verify_svn(None, None, [], 'rm', gamma_path) svntest.actions.run_and_verify_svn(None, None, [], 'rm', E_path) # check status expected_status = svntest.actions.get_virginal_state(wc_dir, 1) expected_status.tweak('A/D/H', 'A/D/H/chi', 'A/D/H/omega', 'A/D/H/psi', 'A/D/G', 'A/D/G/rho', 'A/D/G/pi', 'A/D/G/tau', 'A/B/E', 'A/B/E/alpha', 'A/B/E/beta', 'A/B/F', 'A/C', 'iota', 'A/D/gamma', status='D ') expected_status.add({ 'A/D/Y' : Item(status='A ', wc_rev=0), }) svntest.actions.run_and_verify_status(wc_dir, expected_status)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -