📄 update_tests.py
字号:
#!/usr/bin/env python
#
# update_tests.py: testing update cases.
#
# Subversion is a tool for revision control.
# See http://subversion.tigris.org for more information.
#
# ====================================================================
# Copyright (c) 2000-2004 CollabNet. All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at http://subversion.tigris.org/license-1.html.
# If newer versions of this license are posted there, you may use a
# newer version instead, at your option.
#
######################################################################
# General modules
import shutil, string, sys, re, os
# Our testing module
import svntest
from svntest import wc, SVNAnyOutput
# (abbreviation)
Skip = svntest.testcase.Skip
XFail = svntest.testcase.XFail
Item = svntest.wc.StateItem
######################################################################
# Tests
#
# Each test must return on success or raise on failure.
#----------------------------------------------------------------------
# Helper for update_binary_file() test -- a custom singleton handler.
def detect_extra_files(node, extra_files):
"""NODE has been discovered as an extra file on disk. Verify that
it matches one of the regular expressions in the EXTRA_FILES list of
lists, and that its contents matches the second part of the list
item. If it matches, remove the match from the list. If it doesn't
match, raise an exception."""
# Baton is of the form:
#
# [ [wc_dir, pattern, contents],
# [wc_dir, pattern, contents], ... ]
for pair in extra_files:
wc_dir = pair[0]
pattern = pair[1]
contents = pair[2]
match_obj = re.match(pattern, node.name)
if match_obj:
fp = open(os.path.join (wc_dir, node.path))
real_contents = fp.read() # suck up contents of a test .png file
fp.close()
if real_contents == contents:
extra_files.pop(extra_files.index(pair)) # delete pattern from list
return
print "Found unexpected disk object:", node.name
raise svntest.main.SVNTreeUnequal
def update_binary_file(sbox):
"update a locally-modified binary file"
sbox.build()
wc_dir = sbox.wc_dir
# Add a binary file to the project.
fp = open(os.path.join(sys.path[0], "theta.bin"))
theta_contents = fp.read() # suck up contents of a test .png file
fp.close()
theta_path = os.path.join(wc_dir, 'A', 'theta')
fp = open(theta_path, 'w')
fp.write(theta_contents) # write png filedata into 'A/theta'
fp.close()
svntest.main.run_svn(None, 'add', theta_path)
# Created expected output tree for 'svn ci'
expected_output = svntest.wc.State(wc_dir, {
'A/theta' : Item(verb='Adding (bin)'),
})
# Create expected status tree
expected_status = svntest.actions.get_virginal_state(wc_dir, 2)
expected_status.tweak(wc_rev=1)
expected_status.add({
'A/theta' : Item(status=' ', wc_rev=2, repos_rev=2),
})
# Commit the new binary file, creating revision 2.
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)
theta_backup_path = os.path.join(wc_backup, 'A', 'theta')
# Make a change to the binary file in the original working copy
svntest.main.file_append(theta_path, "revision 3 text")
theta_contents_r3 = theta_contents + "revision 3 text"
# Created expected output tree for 'svn ci'
expected_output = svntest.wc.State(wc_dir, {
'A/theta' : Item(verb='Sending'),
})
# Create expected status tree
expected_status = svntest.actions.get_virginal_state(wc_dir, 3)
expected_status.tweak(wc_rev=1)
expected_status.add({
'A/theta' : Item(status=' ', wc_rev=3, repos_rev=3),
})
# Commit original working copy again, creating revision 3.
svntest.actions.run_and_verify_commit(wc_dir, expected_output,
expected_status, None,
None, None, None, None, wc_dir)
# Now start working in the backup working copy:
# Make a local mod to theta
svntest.main.file_append(theta_backup_path, "extra theta text")
theta_contents_local = theta_contents + "extra theta text"
# Create expected output tree for an update of wc_backup.
expected_output = svntest.wc.State(wc_backup, {
'A/theta' : Item(status='C '),
})
# Create expected disk tree for the update --
# look! binary contents, and a binary property!
expected_disk = svntest.main.greek_state.copy()
expected_disk.add({
'A/theta' : Item(theta_contents_local,
props={'svn:mime-type' : 'application/octet-stream'}),
})
# Create expected status tree for the update.
expected_status = svntest.actions.get_virginal_state(wc_backup, 3)
expected_status.add({
'A/theta' : Item(status='C ', wc_rev=3, repos_rev=3),
})
# Extra 'singleton' files we expect to exist after the update.
# In the case, the locally-modified binary file should be backed up
# to an .orig file.
# This is a list of lists, of the form [ WC_DIR,
# [pattern, contents], ...]
extra_files = [[wc_backup, 'theta.*\.r2', theta_contents],
[wc_backup, 'theta.*\.r3', theta_contents_r3]]
# Do the update and check the results in three ways. Pass our
# custom singleton handler to verify the .orig file; this handler
# will verify the existence (and contents) of both binary files
# after the update finishes.
svntest.actions.run_and_verify_update(wc_backup,
expected_output,
expected_disk,
expected_status,
None,
detect_extra_files, extra_files,
None, None, 1)
# verify that the extra_files list is now empty.
if len(extra_files) != 0:
print "Not all extra reject files have been accounted for:"
print extra_files
raise svntest.Failure
#----------------------------------------------------------------------
def update_binary_file_2(sbox):
"update to an old revision of a binary files"
sbox.build()
wc_dir = sbox.wc_dir
# Suck up contents of a test .png file.
fp = open(os.path.join(sys.path[0], "theta.bin"))
theta_contents = fp.read()
fp.close()
# 102400 is svn_txdelta_window_size. We're going to make sure we
# have at least 102401 bytes of data in our second binary file (for
# no reason other than we have had problems in the past with getting
# svndiff data out of the repository for files > 102400 bytes).
# How? Well, we'll just keep doubling the binary contents of the
# original theta.png until we're big enough.
zeta_contents = theta_contents
while(len(zeta_contents) < 102401):
zeta_contents = zeta_contents + zeta_contents
# Write our two files' contents out to disk, in A/theta and A/zeta.
theta_path = os.path.join(wc_dir, 'A', 'theta')
fp = open(theta_path, 'w')
fp.write(theta_contents)
fp.close()
zeta_path = os.path.join(wc_dir, 'A', 'zeta')
fp = open(zeta_path, 'w')
fp.write(zeta_contents)
fp.close()
# Now, `svn add' those two files.
svntest.main.run_svn(None, 'add', theta_path, zeta_path)
# Created expected output tree for 'svn ci'
expected_output = svntest.wc.State(wc_dir, {
'A/theta' : Item(verb='Adding (bin)'),
'A/zeta' : Item(verb='Adding (bin)'),
})
# Create expected status tree
expected_status = svntest.actions.get_virginal_state(wc_dir, 2)
expected_status.tweak(wc_rev=1)
expected_status.add({
'A/theta' : Item(status=' ', wc_rev=2, repos_rev=2),
'A/zeta' : Item(status=' ', wc_rev=2, repos_rev=2),
})
# Commit the new binary filea, creating revision 2.
svntest.actions.run_and_verify_commit(wc_dir, expected_output,
expected_status, None,
None, None, None, None, wc_dir)
# Make some mods to the binary files.
svntest.main.file_append (theta_path, "foobar")
new_theta_contents = theta_contents + "foobar"
svntest.main.file_append (zeta_path, "foobar")
new_zeta_contents = zeta_contents + "foobar"
# Created expected output tree for 'svn ci'
expected_output = svntest.wc.State(wc_dir, {
'A/theta' : Item(verb='Sending'),
'A/zeta' : Item(verb='Sending'),
})
# Create expected status tree
expected_status = svntest.actions.get_virginal_state(wc_dir, 3)
expected_status.tweak(wc_rev=1)
expected_status.add({
'A/theta' : Item(status=' ', wc_rev=3, repos_rev=3),
'A/zeta' : Item(status=' ', wc_rev=3, repos_rev=3),
})
# Commit original working copy again, creating revision 3.
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 to rev 2.
expected_output = svntest.wc.State(wc_dir, {
'A/theta' : Item(status='U '),
'A/zeta' : Item(status='U '),
})
# Create expected disk tree for the update --
# look! binary contents, and a binary property!
expected_disk = svntest.main.greek_state.copy()
expected_disk.add({
'A/theta' : Item(theta_contents,
props={'svn:mime-type' : 'application/octet-stream'}),
'A/zeta' : Item(zeta_contents,
props={'svn:mime-type' : 'application/octet-stream'}),
})
# Create expected status tree for the update.
expected_status = svntest.actions.get_virginal_state(wc_dir, 3)
expected_status.tweak(wc_rev=2)
expected_status.add({
'A/theta' : Item(status=' ', wc_rev=2, repos_rev=3),
'A/zeta' : Item(status=' ', wc_rev=2, repos_rev=3),
})
# Do an update from revision 2 and make sure that our binary file
# gets reverted to its original contents.
svntest.actions.run_and_verify_update(wc_dir,
expected_output,
expected_disk,
expected_status,
None, None, None,
None, None, 1,
'-r', '2', wc_dir)
#----------------------------------------------------------------------
def update_missing(sbox):
"update missing items (by name) in working copy"
sbox.build()
wc_dir = sbox.wc_dir
# Remove some files and dirs from the working copy.
mu_path = os.path.join(wc_dir, 'A', 'mu')
rho_path = os.path.join(wc_dir, 'A', 'D', 'G', 'rho')
E_path = os.path.join(wc_dir, 'A', 'B', 'E')
H_path = os.path.join(wc_dir, 'A', 'D', 'H')
### FIXME run_and_verify_update doesn't appear to understand 'Restored'
### feedback
#os.remove(mu_path)
#os.remove(rho_path)
### FIXME I think directories work because they generate 'A'
### feedback, is this the correct feedback?
svntest.main.safe_rmtree(E_path)
svntest.main.safe_rmtree(H_path)
# Create expected output tree for an update of the missing items by name
expected_output = svntest.wc.State(wc_dir, {
#'A/mu' : Item(status='A '),
#'A/D/G/rho' : Item(status='A '),
'A/B/E' : Item(status='A '),
'A/B/E/alpha' : Item(status='A '),
'A/B/E/beta' : Item(status='A '),
'A/D/H' : Item(status='A '),
'A/D/H/chi' : Item(status='A '),
'A/D/H/omega' : Item(status='A '),
'A/D/H/psi' : Item(status='A '),
})
# Create expected disk tree for the update.
expected_disk = svntest.main.greek_state.copy()
# Create expected status tree for the update.
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
# Do the update and check the results in three ways.
svntest.actions.run_and_verify_update(wc_dir,
expected_output,
expected_disk,
expected_status,
None, None, None, None, None, 0,
mu_path, rho_path,
E_path, H_path)
#----------------------------------------------------------------------
def update_ignores_added(sbox):
"update should not munge adds or replaces"
sbox.build()
wc_dir = sbox.wc_dir
# Commit something so there's actually a new revision to update to.
rho_path = os.path.join(wc_dir, 'A', 'D', 'G', 'rho')
svntest.main.file_append(rho_path, "\nMore stuff in rho.")
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -