📄 basic_tests.py
字号:
os.chmod (tb_dir_path, tb_dir_saved_mode)
os.chmod (mu_tb_path, mu_tb_saved_mode)
# Do the update and check the results in three ways.
svntest.actions.run_and_verify_update(other_wc,
expected_output,
expected_disk,
expected_status,
"svn: Checksum", other_wc)
# Restore the uncorrupted text base.
os.chmod (tb_dir_path, 0777)
os.chmod (mu_tb_path, 0666)
os.remove (mu_tb_path)
os.rename (mu_saved_tb_path, mu_tb_path)
os.chmod (tb_dir_path, tb_dir_saved_mode)
os.chmod (mu_tb_path, mu_tb_saved_mode)
# This update should succeed. (Actually, I'm kind of astonished
# that this works without even an intervening "svn cleanup".)
svntest.actions.run_and_verify_update (other_wc,
expected_output,
expected_disk,
expected_status)
#----------------------------------------------------------------------
def basic_merging_update(sbox):
"receiving text merges as part of an update"
sbox.build()
wc_dir = sbox.wc_dir
# First change the greek tree to make two files 10 lines long
mu_path = os.path.join(wc_dir, 'A', 'mu')
rho_path = os.path.join(wc_dir, 'A', 'D', 'G', 'rho')
mu_text = ""
rho_text = ""
for x in range(2,11):
mu_text = mu_text + '\nThis is line ' + `x` + ' in mu'
rho_text = rho_text + '\nThis is line ' + `x` + ' in rho'
svntest.main.file_append (mu_path, mu_text)
svntest.main.file_append (rho_path, rho_text)
# Create expected output tree for initial commit
expected_output = wc.State(wc_dir, {
'A/mu' : Item(verb='Sending'),
'A/D/G/rho' : Item(verb='Sending'),
})
# Create expected status tree; all local revisions should be at 1,
# but mu and rho should be at revision 2.
expected_status = svntest.actions.get_virginal_state(wc_dir, 2)
expected_status.tweak(wc_rev=1)
expected_status.tweak('A/mu', 'A/D/G/rho', wc_rev=2)
# Initial commit.
svntest.actions.run_and_verify_commit (wc_dir,
expected_output,
expected_status,
None,
None, None, None, None,
wc_dir)
# Make a backup copy of the working copy
wc_backup = sbox.add_wc_path('backup')
svntest.actions.duplicate_dir(wc_dir, wc_backup)
# Make a couple of local mods to files
svntest.main.file_append (mu_path, ' Appended to line 10 of mu')
svntest.main.file_append (rho_path, ' Appended to line 10 of rho')
# Created expected output tree for 'svn ci'
expected_output = wc.State(wc_dir, {
'A/mu' : Item(verb='Sending'),
'A/D/G/rho' : Item(verb='Sending'),
})
# Create expected status tree; all local revisions should be at 1,
# but mu and rho should be at revision 3.
expected_status = svntest.actions.get_virginal_state(wc_dir, 3)
expected_status.tweak(wc_rev=1)
expected_status.tweak('A/mu', 'A/D/G/rho', wc_rev=3)
# Commit.
svntest.actions.run_and_verify_commit (wc_dir,
expected_output,
expected_status,
None,
None, None, None, None,
wc_dir)
# Make local mods to wc_backup by recreating mu and rho
mu_path_backup = os.path.join(wc_backup, 'A', 'mu')
rho_path_backup = os.path.join(wc_backup, 'A', 'D', 'G', 'rho')
fp_mu = open(mu_path_backup, 'w+')
# open in 'truncate to zero then write" mode
backup_mu_text='This is the new line 1 in the backup copy of mu'
for x in range(2,11):
backup_mu_text = backup_mu_text + '\nThis is line ' + `x` + ' in mu'
fp_mu.write(backup_mu_text)
fp_mu.close()
fp_rho = open(rho_path_backup, 'w+') # now open rho in write mode
backup_rho_text='This is the new line 1 in the backup copy of rho'
for x in range(2,11):
backup_rho_text = backup_rho_text + '\nThis is line ' + `x` + ' in rho'
fp_rho.write(backup_rho_text)
fp_rho.close()
# Create expected output tree for an update of the wc_backup.
expected_output = wc.State(wc_backup, {
'A/mu' : Item(status='G '),
'A/D/G/rho' : Item(status='G '),
})
# Create expected disk tree for the update.
expected_disk = svntest.main.greek_state.copy()
expected_disk.tweak('A/mu',
contents=backup_mu_text + ' Appended to line 10 of mu')
expected_disk.tweak('A/D/G/rho',
contents=backup_rho_text + ' Appended to line 10 of rho')
# Create expected status tree for the update.
expected_status = svntest.actions.get_virginal_state(wc_backup, 3)
expected_status.tweak('A/mu', 'A/D/G/rho', status='M ')
# Do the update and check the results in three ways.
svntest.actions.run_and_verify_update(wc_backup,
expected_output,
expected_disk,
expected_status)
#----------------------------------------------------------------------
def basic_conflict(sbox):
"basic conflict creation and resolution"
sbox.build()
wc_dir = sbox.wc_dir
# Make a backup copy of the working copy
wc_backup = sbox.add_wc_path('backup')
svntest.actions.duplicate_dir(wc_dir, wc_backup)
# Make a couple of local mods to files which will be committed
mu_path = os.path.join(wc_dir, 'A', 'mu')
rho_path = os.path.join(wc_dir, 'A', 'D', 'G', 'rho')
svntest.main.file_append (mu_path, '\nOriginal appended text for mu')
svntest.main.file_append (rho_path, '\nOriginal appended text for rho')
# Make a couple of local mods to files which will be conflicted
mu_path_backup = os.path.join(wc_backup, 'A', 'mu')
rho_path_backup = os.path.join(wc_backup, 'A', 'D', 'G', 'rho')
svntest.main.file_append (mu_path_backup,
'\nConflicting appended text for mu')
svntest.main.file_append (rho_path_backup,
'\nConflicting appended text for rho')
# Created expected output tree for 'svn ci'
expected_output = wc.State(wc_dir, {
'A/mu' : Item(verb='Sending'),
'A/D/G/rho' : Item(verb='Sending'),
})
# Create expected status tree; all local revisions should be at 1,
# but mu and rho should be at revision 2.
expected_status = svntest.actions.get_virginal_state(wc_dir, 2)
expected_status.tweak(wc_rev=1)
expected_status.tweak('A/mu', 'A/D/G/rho', wc_rev=2)
# Commit.
svntest.actions.run_and_verify_commit (wc_dir, expected_output,
expected_status, None,
None, None, None, None, wc_dir)
# Create expected output tree for an update of the wc_backup.
expected_output = wc.State(wc_backup, {
'A/mu' : Item(status='C '),
'A/D/G/rho' : Item(status='C '),
})
# Create expected disk tree for the update.
expected_disk = svntest.main.greek_state.copy()
expected_disk.tweak('A/mu', contents="""<<<<<<< .mine
This is the file 'mu'.
Conflicting appended text for mu=======
This is the file 'mu'.
Original appended text for mu>>>>>>> .r2
""")
expected_disk.tweak('A/D/G/rho', contents="""<<<<<<< .mine
This is the file 'rho'.
Conflicting appended text for rho=======
This is the file 'rho'.
Original appended text for rho>>>>>>> .r2
""")
# Create expected status tree for the update.
expected_status = svntest.actions.get_virginal_state(wc_backup, '2')
expected_status.tweak('A/mu', 'A/D/G/rho', status='C ')
# "Extra" files that we expect to result from the conflicts.
# These are expressed as list of regexps. What a cool system! :-)
extra_files = ['mu.*\.r1', 'mu.*\.r2', 'mu.*\.mine',
'rho.*\.r1', 'rho.*\.r2', 'rho.*\.mine',]
# Do the update and check the results in three ways.
# All "extra" files are passed to expect_extra_files().
svntest.actions.run_and_verify_update(wc_backup,
expected_output,
expected_disk,
expected_status,
None,
expect_extra_files,
extra_files)
# verify that the extra_files list is now empty.
if len(extra_files) != 0:
# Because we want to be a well-behaved test, we silently raise if
# the test fails. However, these two print statements would
# probably reveal the cause for the failure, if they were
# uncommented:
#
# print "Not all extra reject files have been accounted for:"
# print extra_files
### we should raise a less generic error here. which?
raise svntest.Failure
# So now mu and rho are both in a "conflicted" state. Run 'svn
# resolved' on them.
svntest.actions.run_and_verify_svn("Resolved command", None, [],
'resolved',
mu_path_backup,
rho_path_backup)
# See if they've changed back to plain old 'M' state.
expected_status.tweak('A/mu', 'A/D/G/rho', status='M ')
# There should be *no* extra backup files lying around the working
# copy after resolving the conflict; thus we're not passing a custom
# singleton handler.
svntest.actions.run_and_verify_status(wc_backup, expected_status)
#----------------------------------------------------------------------
def basic_cleanup(sbox):
"basic cleanup command"
sbox.build()
wc_dir = sbox.wc_dir
# Lock some directories.
B_path = os.path.join(wc_dir, 'A', 'B')
G_path = os.path.join(wc_dir, 'A', 'D', 'G')
C_path = os.path.join(wc_dir, 'A', 'C')
svntest.actions.lock_admin_dir(B_path)
svntest.actions.lock_admin_dir(G_path)
svntest.actions.lock_admin_dir(C_path)
# Verify locked status.
expected_output = svntest.actions.get_virginal_state(wc_dir, 1)
expected_output.tweak('A/B', 'A/D/G', 'A/C', locked='L')
svntest.actions.run_and_verify_status (wc_dir, expected_output)
# Run cleanup (### todo: cleanup doesn't currently print anything)
svntest.actions.run_and_verify_svn("Cleanup command", None, [],
'cleanup', wc_dir)
# Verify unlocked status.
expected_output = svntest.actions.get_virginal_state(wc_dir, 1)
svntest.actions.run_and_verify_status(wc_dir, expected_output)
#----------------------------------------------------------------------
def basic_revert(sbox):
"basic revert command"
sbox.build()
wc_dir = sbox.wc_dir
# Modify some files.
beta_path = os.path.join(wc_dir, 'A', 'B', 'E', 'beta')
iota_path = os.path.join(wc_dir, 'iota')
rho_path = os.path.join(wc_dir, 'A', 'D', 'G', 'rho')
zeta_path = os.path.join(wc_dir, 'A', 'D', 'H', 'zeta')
svntest.main.file_append(beta_path, "Added some text to 'beta'.")
svntest.main.file_append(iota_path, "Added some text to 'iota'.")
svntest.main.file_append(rho_path, "Added some text to 'rho'.")
svntest.main.file_append(zeta_path, "Added some text to 'zeta'.")
svntest.actions.run_and_verify_svn("Add command", None, [],
'add', zeta_path)
# Verify modified status.
expected_output = svntest.actions.get_virginal_state(wc_dir, 1)
expected_output.tweak('A/B/E/beta', 'iota', 'A/D/G/rho', status='M ')
expected_output.add({
'A/D/H/zeta' : Item(status='A ', wc_rev=0, repos_rev=1),
})
svntest.actions.run_and_verify_status (wc_dir, expected_output)
# Run revert (### todo: revert doesn't currently print anything)
svntest.actions.run_and_verify_svn("Revert command", None, [],
'revert', beta_path)
svntest.actions.run_and_verify_svn("Revert command", None, [],
'revert', iota_path)
svntest.actions.run_and_verify_svn("Revert command", None, [],
'revert', rho_path)
svntest.actions.run_and_verify_svn("Revert command", None, [],
'revert', zeta_path)
# Verify unmodified status.
expected_output = svntest.actions.get_virginal_state(wc_dir, 1)
svntest.actions.run_and_verify_status (wc_dir, expected_output)
# Now, really make sure the contents are back to their original state.
fp = open(beta_path, 'r')
lines = fp.readlines()
if not ((len (lines) == 1) and (lines[0] == "This is the file 'beta'.")):
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'.")):
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'.")):
print "Revert failed to restore original text."
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -