📄 basic_tests.py
字号:
raise svntest.Failure
fp = open(zeta_path, 'r')
lines = fp.readlines()
if not ((len (lines) == 1) and (lines[0] == "Added some text to 'zeta'.")):
### 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, repos_rev=1),
})
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)
svntest.actions.run_and_verify_svn("", None, [], 'rm', E_path)
svntest.main.safe_rmtree(E_path)
expected_status.tweak('A/B/E', status='D ')
extra_files = ['E']
svntest.actions.run_and_verify_status (wc_dir, expected_status,
None, None,
expect_extra_files, extra_files)
if len(extra_files) != 0:
### we should raise a less generic error here. which?
raise svntest.Failure
svntest.actions.run_and_verify_svn(None, None, [], 'revert', E_path)
expected_status.tweak('A/B/E', status=' ')
extra_files = ['E']
svntest.actions.run_and_verify_status (wc_dir, expected_status,
None, None,
expect_extra_files, extra_files)
if len(extra_files) != 0:
### we should raise a less generic error here. which?
raise svntest.Failure
#----------------------------------------------------------------------
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'."),
'A/D/H/rho' : Item("This is the file 'rho'."),
'A/D/H/tau' : Item("This is the file 'tau'."),
})
# 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, repos_rev=1),
'A/D/H/rho' : Item(status=' ', wc_rev=1, repos_rev=1),
'A/D/H/tau' : Item(status=' ', wc_rev=1, repos_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, repos_rev=1),
'A/B/X/xi' : Item(status='A ', wc_rev=0, repos_rev=1),
'A/D/Y' : Item(status='A ', wc_rev=0, repos_rev=1),
})
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, repos_rev=1),
})
svntest.actions.run_and_verify_status(wc_dir, expected_status)
# issue 687 delete directory with uncommitted directory child
svntest.actions.run_and_verify_svn(None, None, [],
'rm', '--force', Y_parent_path)
expected_status.tweak('A/D', status='D ')
expected_status.remove('A/D/Y')
svntest.actions.run_and_verify_status(wc_dir, expected_status)
# check files have been removed
verify_file_deleted("Failed to remove text modified file", rho_path)
verify_file_deleted("Failed to remove prop modified file", chi_path)
verify_file_deleted("Failed to remove unversioned file", sigma_path)
verify_file_deleted("Failed to remove unmodified file",
os.path.join(E_path, 'alpha'))
# check versioned dir is not removed
if not can_cd_to_dir(F_path):
print "Removed versioned dir"
### we should raise a less generic error here. which?
raise svntest.Failure
# check unversioned and added dirs has been removed
if can_cd_to_dir(Q_path):
print "Failed to remove unversioned dir"
### we should raise a less generic error here. which?
raise svntest.Failure
if can_cd_to_dir(X_path):
print "Failed to remove added dir"
### we should raise a less generic error here. which?
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -