📄 schedule_tests.py
字号:
#!/usr/bin/env python
#
# schedule_tests.py: testing working copy scheduling
# (adds, deletes, reversion)
#
# 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 string, sys, os, shutil
# Our testing module
import svntest
from svntest import 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.
#
# NOTE: Tests in this section should be written in triplets. First
# compose a test which make schedule changes and local mods, and
# verifies that status output is as expected. Secondly, compose a
# test which calls the first test (to do all the dirty work), then
# test reversion of those changes. Finally, compose a third test
# which, again, calls the first test to "set the stage", and then
# commit those changes.
#
#----------------------------------------------------------------------
#######################################################################
# Stage I - Schedules and modifications, verified with `svn status'
#
def add_files(sbox):
"schedule: add some files"
sbox.build()
wc_dir = sbox.wc_dir
# Create some files, then schedule them for addition
delta_path = os.path.join(wc_dir, 'delta')
zeta_path = os.path.join(wc_dir, 'A', 'B', 'zeta')
epsilon_path = os.path.join(wc_dir, 'A', 'D', 'G', 'epsilon')
svntest.main.file_append(delta_path, "This is the file 'delta'.")
svntest.main.file_append(zeta_path, "This is the file 'zeta'.")
svntest.main.file_append(epsilon_path, "This is the file 'epsilon'.")
svntest.main.run_svn(None, 'add', delta_path, zeta_path, epsilon_path)
# Make sure the adds show up as such in status
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
expected_status.add({
'delta' : Item(status='A ', wc_rev=0, repos_rev=1),
'A/B/zeta' : Item(status='A ', wc_rev=0, repos_rev=1),
'A/D/G/epsilon' : Item(status='A ', wc_rev=0, repos_rev=1),
})
svntest.actions.run_and_verify_status(wc_dir, expected_status)
#----------------------------------------------------------------------
def add_directories(sbox):
"schedule: add some directories"
sbox.build()
wc_dir = sbox.wc_dir
# Create some directories, then schedule them for addition
X_path = os.path.join(wc_dir, 'X')
Y_path = os.path.join(wc_dir, 'A', 'C', 'Y')
Z_path = os.path.join(wc_dir, 'A', 'D', 'H', 'Z')
os.mkdir(X_path)
os.mkdir(Y_path)
os.mkdir(Z_path)
svntest.main.run_svn(None, 'add', X_path, Y_path, Z_path)
# Make sure the adds show up as such in status
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
expected_status.add({
'X' : Item(status='A ', wc_rev=0, repos_rev=1),
'A/C/Y' : Item(status='A ', wc_rev=0, repos_rev=1),
'A/D/H/Z' : Item(status='A ', wc_rev=0, repos_rev=1),
})
svntest.actions.run_and_verify_status(wc_dir, expected_status)
#----------------------------------------------------------------------
def nested_adds(sbox):
"schedule: add some nested files and directories"
sbox.build()
wc_dir = sbox.wc_dir
# Create some directories then schedule them for addition
X_path = os.path.join(wc_dir, 'X')
Y_path = os.path.join(wc_dir, 'A', 'C', 'Y')
Z_path = os.path.join(wc_dir, 'A', 'D', 'H', 'Z')
os.mkdir(X_path)
os.mkdir(Y_path)
os.mkdir(Z_path)
# Now, create some files and directories to put into our newly added
# directories
P_path = os.path.join(X_path, 'P')
Q_path = os.path.join(Y_path, 'Q')
R_path = os.path.join(Z_path, 'R')
os.mkdir(P_path)
os.mkdir(Q_path)
os.mkdir(R_path)
delta_path = os.path.join(X_path, 'delta')
epsilon_path = os.path.join(Y_path, 'epsilon')
upsilon_path = os.path.join(Y_path, 'upsilon')
zeta_path = os.path.join(Z_path, 'zeta')
svntest.main.file_append(delta_path, "This is the file 'delta'.")
svntest.main.file_append(epsilon_path, "This is the file 'epsilon'.")
svntest.main.file_append(upsilon_path, "This is the file 'upsilon'.")
svntest.main.file_append(zeta_path, "This is the file 'zeta'.")
# Finally, let's try adding our new files and directories
svntest.main.run_svn(None, 'add', X_path, Y_path, Z_path)
# Make sure the adds show up as such in status
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
expected_status.add({
'X' : Item(status='A ', wc_rev=0, repos_rev=1),
'A/C/Y' : Item(status='A ', wc_rev=0, repos_rev=1),
'A/D/H/Z' : Item(status='A ', wc_rev=0, repos_rev=1),
'X/P' : Item(status='A ', wc_rev=0, repos_rev=1),
'A/C/Y/Q' : Item(status='A ', wc_rev=0, repos_rev=1),
'A/D/H/Z/R' : Item(status='A ', wc_rev=0, repos_rev=1),
'X/delta' : Item(status='A ', wc_rev=0, repos_rev=1),
'A/C/Y/epsilon' : Item(status='A ', wc_rev=0, repos_rev=1),
'A/C/Y/upsilon' : Item(status='A ', wc_rev=0, repos_rev=1),
'A/D/H/Z/zeta' : Item(status='A ', wc_rev=0, repos_rev=1),
})
svntest.actions.run_and_verify_status(wc_dir, expected_status)
#----------------------------------------------------------------------
def add_executable(sbox):
"schedule: add some executable files"
sbox.build()
def runTest(wc_dir, fileName, perm, executable):
fileName = os.path.join(wc_dir, fileName)
if executable:
expected_out = ["*\n"]
else:
expected_out = []
f = open(fileName,"w")
f.close()
os.chmod(fileName,perm)
svntest.main.run_svn(None, 'add', fileName)
svntest.actions.run_and_verify_svn(None, expected_out, [],
'propget', "svn:executable", fileName)
test_cases = [
("all_exe", 0777, 1),
("none_exe", 0666, 0),
("user_exe", 0766, 1),
("group_exe", 0676, 0),
("other_exe", 0667, 0),
]
for test_case in test_cases:
runTest(sbox.wc_dir, *test_case)
#----------------------------------------------------------------------
def delete_files(sbox):
"schedule: delete some files"
sbox.build()
wc_dir = sbox.wc_dir
# Schedule some files for deletion
iota_path = os.path.join(wc_dir, 'iota')
mu_path = os.path.join(wc_dir, 'A', 'mu')
rho_path = os.path.join(wc_dir, 'A', 'D', 'G', 'rho')
omega_path = os.path.join(wc_dir, 'A', 'D', 'H', 'omega')
svntest.main.run_svn(None, 'del', iota_path, mu_path, rho_path, omega_path)
# Make sure the deletes show up as such in status
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
expected_status.tweak('iota', 'A/mu', 'A/D/G/rho', 'A/D/H/omega',
status='D ')
svntest.actions.run_and_verify_status(wc_dir, expected_status)
#----------------------------------------------------------------------
def delete_dirs(sbox):
"schedule: delete some directories"
sbox.build()
wc_dir = sbox.wc_dir
# Schedule some directories for deletion (this is recursive!)
E_path = os.path.join(wc_dir, 'A', 'B', 'E')
F_path = os.path.join(wc_dir, 'A', 'B', 'F')
H_path = os.path.join(wc_dir, 'A', 'D', 'H')
alpha_path = os.path.join(E_path, 'alpha')
beta_path = os.path.join(E_path, 'beta')
chi_path = os.path.join(H_path, 'chi')
omega_path = os.path.join(H_path, 'omega')
psi_path = os.path.join(H_path, 'psi')
# Now, delete (recursively) the directories.
svntest.main.run_svn(None, 'del', E_path, F_path, H_path)
# Make sure the deletes show up as such in status
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
expected_status.tweak('A/B/E', 'A/B/E/alpha', 'A/B/E/beta',
'A/B/F',
'A/D/H', 'A/D/H/chi', 'A/D/H/omega', 'A/D/H/psi',
status='D ')
svntest.actions.run_and_verify_status(wc_dir, expected_status)
#######################################################################
# Stage II - Reversion of changes made in Stage I
#
def check_reversion(files, output):
expected_output = []
for file in files:
expected_output = expected_output + ["Reverted '" + file + "'\n"]
output.sort()
expected_output.sort()
if output != expected_output:
print "Expected output:", expected_output
print "Actual output: ", output
raise svntest.Failure
#----------------------------------------------------------------------
def revert_add_files(sbox):
"revert: add some files"
add_files(sbox)
wc_dir = sbox.wc_dir
# Revert our changes recursively from wc_dir.
delta_path = os.path.join(wc_dir, 'delta')
zeta_path = os.path.join(wc_dir, 'A', 'B', 'zeta')
epsilon_path = os.path.join(wc_dir, 'A', 'D', 'G', 'epsilon')
files = [delta_path, zeta_path, epsilon_path]
output, err = svntest.actions.run_and_verify_svn(None, None, [],
'revert',
'--recursive', wc_dir)
check_reversion(files, output)
#----------------------------------------------------------------------
def revert_add_directories(sbox):
"revert: add some directories"
add_directories(sbox)
wc_dir = sbox.wc_dir
# Revert our changes recursively from wc_dir.
X_path = os.path.join(wc_dir, 'X')
Y_path = os.path.join(wc_dir, 'A', 'C', 'Y')
Z_path = os.path.join(wc_dir, 'A', 'D', 'H', 'Z')
files = [X_path, Y_path, Z_path]
output, err = svntest.actions.run_and_verify_svn(None, None, [],
'revert',
'--recursive', wc_dir)
check_reversion(files, output)
#----------------------------------------------------------------------
def revert_nested_adds(sbox):
"revert: add some nested files and directories"
nested_adds(sbox)
wc_dir = sbox.wc_dir
# Revert our changes recursively from wc_dir.
X_path = os.path.join(wc_dir, 'X')
Y_path = os.path.join(wc_dir, 'A', 'C', 'Y')
Z_path = os.path.join(wc_dir, 'A', 'D', 'H', 'Z')
files = [X_path, Y_path, Z_path]
output, err = svntest.actions.run_and_verify_svn(None, None, [],
'revert',
'--recursive', wc_dir)
check_reversion(files, output)
#----------------------------------------------------------------------
def revert_add_executable(sbox):
"revert: add some executable files"
add_executable(sbox)
wc_dir = sbox.wc_dir
all_path = os.path.join(wc_dir, 'all_exe')
none_path = os.path.join(wc_dir, 'none_exe')
user_path = os.path.join(wc_dir, 'user_exe')
group_path = os.path.join(wc_dir, 'group_exe')
other_path = os.path.join(wc_dir, 'other_exe')
files = [all_path, none_path, user_path, group_path, other_path]
output, err = svntest.actions.run_and_verify_svn(None, None, [],
'revert',
'--recursive', wc_dir)
check_reversion(files, output)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -