trans_tests.py
来自「linux subdivision ying gai ke yi le ba」· Python 代码 · 共 592 行 · 第 1/2 页
PY
592 行
def do_nothing(x, y):
return 0
def update_modified_with_translation(sbox):
"update modified file with eol-style 'native'"
sbox.build()
wc_dir = sbox.wc_dir
# Replace contents of rho and set eol translation to 'native'
rho_path = os.path.join(wc_dir, 'A', 'D', 'G', 'rho')
f = open(rho_path, "w")
f.write("1\n2\n3\n4\n5\n6\n7\n8\n9\n")
f.close()
svntest.actions.run_and_verify_svn(None, None, [],
'propset', 'svn:eol-style', 'native',
rho_path)
# Create expected output and status trees of a commit.
expected_output = svntest.wc.State(wc_dir, {
'A/D/G/rho' : Item(verb='Sending'),
})
expected_status = svntest.actions.get_virginal_state(wc_dir, 2)
expected_status.tweak(wc_rev=1)
# rho has props
expected_status.tweak('A/D/G/rho', wc_rev=2, status=' ')
# Commit revision 2: it has the new rho.
svntest.actions.run_and_verify_commit (wc_dir,
expected_output,
expected_status,
None, None, None, None, None,
rho_path)
# Change rho again
f = open(rho_path, "w")
f.write("1\n2\n3\n4\n4.5\n5\n6\n7\n8\n9\n")
f.close()
# Commit revision 3
expected_status = svntest.actions.get_virginal_state(wc_dir, 3)
expected_status.tweak(wc_rev=1)
expected_status.tweak('A/D/G/rho', wc_rev=3, status=' ')
svntest.actions.run_and_verify_commit (wc_dir,
expected_output,
expected_status,
None, None, None, None, None,
rho_path)
# Locally modify rho again.
f = open(rho_path, "w")
f.write("1\n2\n3\n4\n4.5\n5\n6\n7\n8\n9\n10\n")
f.close()
# Prepare trees for an update to rev 1.
expected_output = svntest.wc.State(wc_dir, {
'A/D/G/rho' : Item(status='CU'),
})
expected_disk = svntest.main.greek_state.copy()
expected_disk.tweak('A/D/G/rho', contents="""<<<<<<< .mine
1
2
3
4
4.5
5
6
7
8
9
10
=======
This is the file 'rho'.>>>>>>> .r1
""")
# Updating back to revision 1 should not error; the merge should
# work, with eol-translation turned on.
svntest.actions.run_and_verify_update(wc_dir,
expected_output,
expected_disk,
None, None,
do_nothing, None,
None, None,
0, '-r', '1', wc_dir)
#----------------------------------------------------------------------
# Regression test for issue #1085, whereby setting the eol-style to a
# fixed platform-incorrect value on a file whose line endings are
# platform-correct causes repository insanity (the eol-style prop
# claims one line ending style, the file is in another). This test
# assumes that this can be testing by verifying that a) new file
# contents are transmitted to the server during commit, and b) that
# after the commit, the file and its text-base have been changed to
# have the new line-ending style.
def eol_change_is_text_mod(sbox):
"committing eol-style change forces text send"
sbox.build()
wc_dir = sbox.wc_dir
# add a new file to the working copy.
foo_path = os.path.join(wc_dir, 'foo')
f = open(foo_path, 'wb')
if svntest.main.windows:
f.write("1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n")
else:
f.write("1\n2\n3\n4\n5\n6\n7\n8\n9\n")
f.close()
# commit the file
svntest.actions.run_and_verify_svn(None, None, [], 'add', foo_path)
svntest.actions.run_and_verify_svn(None, None, [], 'ci', '-m', 'log msg',
foo_path)
if svntest.main.windows:
svntest.actions.run_and_verify_svn(None, None, [], 'propset',
'svn:eol-style', 'LF', foo_path)
else:
svntest.actions.run_and_verify_svn(None, None, [], 'propset',
'svn:eol-style', 'CRLF', foo_path)
# check 1: did new contents get transmitted?
expected_output = ["Sending " + foo_path + "\n",
"Transmitting file data .\n",
"Committed revision 3.\n"]
svntest.actions.run_and_verify_svn(None, expected_output, [],
'ci', '-m', 'log msg', foo_path)
# check 2: do the files have the right contents now?
f = open(foo_path, 'rb')
contents = f.read()
f.close()
if svntest.main.windows:
if contents != "1\n2\n3\n4\n5\n6\n7\n8\n9\n":
raise svntest.Failure
else:
if contents != "1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n":
raise svntest.Failure
f = open(os.path.join(wc_dir, '.svn', 'text-base', 'foo.svn-base'), 'rb')
base_contents = f.read()
f.close()
if contents != base_contents:
raise svntest.Failure
#----------------------------------------------------------------------
# Regression test for issue #1151. A single file in a directory
# didn't get keywords expanded on checkout.
def keyword_expanded_on_checkout(sbox):
"keyword expansion for lone file in directory"
sbox.build()
wc_dir = sbox.wc_dir
# The bug didn't occur if there were multiple files in the
# directory, so setup an empty directory.
Z_path = os.path.join(wc_dir, 'Z')
svntest.actions.run_and_verify_svn (None, None, [], 'mkdir', Z_path)
# Add the file that has the keyword to be expanded
url_path = os.path.join(Z_path, 'url')
svntest.main.file_append (url_path, "$URL$")
svntest.actions.run_and_verify_svn (None, None, [], 'add', url_path)
keywords_on(url_path)
svntest.actions.run_and_verify_svn(None, None, [],
'ci', '-m', 'log msg', wc_dir)
other_wc_dir = sbox.add_wc_path('other')
other_url_path = os.path.join(other_wc_dir, 'Z', 'url')
svntest.actions.run_and_verify_svn (None, None, [], 'checkout',
'--username', svntest.main.wc_author,
'--password', svntest.main.wc_passwd,
svntest.main.current_repo_url,
other_wc_dir)
# Check keyword got expanded (and thus the mkdir, add, ps, commit
# etc. worked)
fp = open(other_url_path, 'r')
lines = fp.readlines()
if not ((len(lines) == 1)
and (re.match("\$URL: (http|file|svn|svn\\+ssh)://", lines[0]))):
print "URL expansion failed for", other_url_path
raise svntest.Failure
fp.close()
#----------------------------------------------------------------------
def cat_keyword_expansion(sbox):
"keyword expanded on cat"
sbox.build()
wc_dir = sbox.wc_dir
mu_path = os.path.join(wc_dir, 'A', 'mu')
lambda_path = os.path.join(wc_dir, 'A', 'B', 'lambda')
# Set up A/mu to do $Rev$ keyword expansion
svntest.main.file_append (mu_path , "\n$Rev$")
svntest.actions.run_and_verify_svn(None, None, [],
'propset', 'svn:keywords', 'Rev', mu_path)
expected_output = wc.State(wc_dir, {
'A/mu' : Item(verb='Sending'),
})
expected_status = svntest.actions.get_virginal_state(wc_dir, 2)
expected_status.tweak(wc_rev=1)
expected_status.tweak('A/mu', wc_rev=2)
svntest.actions.run_and_verify_commit (wc_dir,
expected_output, expected_status,
None, None, None, None, None,
wc_dir)
# Make another commit so that the last changed revision for A/mu is
# not HEAD.
svntest.actions.run_and_verify_svn(None, None, [],
'propset', 'foo', 'bar', lambda_path)
expected_output = wc.State(wc_dir, {
'A/B/lambda' : Item(verb='Sending'),
})
expected_status.tweak(repos_rev=3)
expected_status.tweak('A/B/lambda', wc_rev=3)
svntest.actions.run_and_verify_commit (wc_dir,
expected_output, expected_status,
None, None, None, None, None,
wc_dir)
# At one stage the keywords were expanded to values for the requested
# revision, not to those committed revision
svntest.actions.run_and_verify_svn (None, [ "This is the file 'mu'.\n",
"$Rev: 2 $" ], None,
'cat', '-r', 'HEAD', mu_path)
#----------------------------------------------------------------------
def copy_propset_commit(sbox):
"copy, propset svn:eol-style, commit"
sbox.build()
wc_dir = sbox.wc_dir
mu_path = os.path.join(wc_dir, 'A', 'mu')
mu2_path = os.path.join(wc_dir, 'A', 'mu2')
# Copy and propset
svntest.actions.run_and_verify_svn(None, None, [], 'copy', mu_path, mu2_path)
svntest.actions.run_and_verify_svn(None, None, [],
'propset', 'svn:eol-style', 'native',
mu2_path)
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
expected_status.add({
'A/mu2' : Item(status='A ', wc_rev='-', repos_rev=1, copied='+')
})
svntest.actions.run_and_verify_status(wc_dir, expected_status)
# Commit, at one stage this dumped core
expected_output = wc.State(wc_dir, {
'A/mu2' : Item(verb='Adding'),
})
expected_status.tweak(repos_rev=2)
expected_status.tweak('A/mu2', status=' ', wc_rev=2, copied=None)
svntest.actions.run_and_verify_commit (wc_dir,
expected_output, expected_status,
None, None, None, None, None,
wc_dir)
########################################################################
# Run the tests
# list all tests here, starting with None:
test_list = [ None,
keywords_from_birth,
XFail(enable_translation),
XFail(checkout_translated),
XFail(disable_translation),
update_modified_with_translation,
eol_change_is_text_mod,
keyword_expanded_on_checkout,
cat_keyword_expansion,
copy_propset_commit,
]
if __name__ == '__main__':
svntest.main.run_tests(test_list)
# NOTREACHED
### End of file.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?