diff_tests.py
来自「linux subdivision ying gai ke yi le ba」· Python 代码 · 共 1,611 行 · 第 1/4 页
PY
1,611 行
check_replace_a_file)
# test 5
def diff_multiple_reverse(sbox):
"multiple revisions diff'd forwards and backwards"
sbox.build()
wc_dir = sbox.wc_dir
# rev 2
change_diff_commit_diff(wc_dir, 1,
add_a_file,
check_add_a_file)
#rev 3
change_diff_commit_diff(wc_dir, 2,
add_a_file_in_a_subdir,
check_add_a_file_in_a_subdir)
#rev 4
change_diff_commit_diff(wc_dir, 3,
update_a_file,
check_update_a_file)
# check diffs both ways
update_diff(wc_dir, 4, 1, check_update_a_file)
just_diff(wc_dir, 1, check_add_a_file_in_a_subdir)
just_diff(wc_dir, 1, check_add_a_file)
update_diff(wc_dir, 1, 4, check_update_a_file)
just_diff(wc_dir, 4, check_add_a_file_in_a_subdir_reverse)
just_diff(wc_dir, 4, check_add_a_file_reverse)
# check pure repository diffs
repo_diff(wc_dir, 4, 1, check_update_a_file)
repo_diff(wc_dir, 4, 1, check_add_a_file_in_a_subdir)
repo_diff(wc_dir, 4, 1, check_add_a_file)
repo_diff(wc_dir, 1, 4, check_update_a_file)
# ### TODO: directory delete doesn't work yet
# repo_diff(wc_dir, 1, 4, check_add_a_file_in_a_subdir_reverse)
repo_diff(wc_dir, 1, 4, check_add_a_file_reverse)
# test 6
def diff_non_recursive(sbox):
"non-recursive behaviour"
sbox.build()
wc_dir = sbox.wc_dir
change_diff_commit_diff(wc_dir, 1,
update_three_files,
check_update_three_files)
# The changes are in: ./A/D/gamma
# ./A/D/G/tau
# ./A/D/H/psi
# When checking D recursively there are three changes. When checking
# D non-recursively there is only one change. When checking G
# recursively, there is only one change even though D is the anchor
# full diff has three changes
diff_output, err_output = svntest.main.run_svn(None, 'diff', '-r', '1',
os.path.join(wc_dir, 'A', 'D'))
if count_diff_output(diff_output) != 3:
raise svntest.Failure
# non-recursive has one change
diff_output, err_output = svntest.main.run_svn(None, 'diff', '-r', '1', '-N',
os.path.join(wc_dir, 'A', 'D'))
if count_diff_output(diff_output) != 1:
raise svntest.Failure
# diffing a directory doesn't pick up other diffs in the anchor
diff_output, err_output = svntest.main.run_svn(None, 'diff', '-r', '1',
os.path.join(wc_dir,
'A', 'D', 'G'))
if count_diff_output(diff_output) != 1:
raise svntest.Failure
# test 7
def diff_repo_subset(sbox):
"diff only part of the repository"
sbox.build()
wc_dir = sbox.wc_dir
was_cwd = os.getcwd()
os.chdir(wc_dir)
update_a_file()
add_a_file()
add_a_file_in_a_subdir()
os.chdir(was_cwd)
if diff_check_update_a_file_repo_subset(wc_dir):
raise svntest.Failure
if diff_check_add_a_file_repo_subset(wc_dir):
raise svntest.Failure
if diff_check_add_a_file_in_a_subdir_repo_subset(wc_dir):
raise svntest.Failure
# test 8
def diff_non_version_controlled_file(sbox):
"non version controlled files"
sbox.build()
wc_dir = sbox.wc_dir
svntest.main.file_append(os.path.join(wc_dir, 'A', 'D', 'foo'), "a new file")
diff_output, err_output = svntest.main.run_svn(1, 'diff',
os.path.join(wc_dir,
'A', 'D', 'foo'))
if count_diff_output(diff_output) != 0: raise svntest.Failure
# At one point this would crash, so we would only get a 'Segmentation Fault'
# error message. The appropriate response is a few lines of errors. I wish
# there was a way to figure out if svn crashed, but all run_svn gives us is
# the output, so here we are...
for line in err_output:
if re.search("foo' is not under version control$", line):
break
else:
raise svntest.Failure
# test 9
def diff_pure_repository_update_a_file(sbox):
"pure repository diff update a file"
sbox.build()
wc_dir = sbox.wc_dir
was_cwd = os.getcwd()
os.chdir(wc_dir)
# rev 2
update_a_file()
svntest.main.run_svn(None, 'ci', '-m', 'log msg')
# rev 3
add_a_file_in_a_subdir()
svntest.main.run_svn(None, 'ci', '-m', 'log msg')
# rev 4
add_a_file()
svntest.main.run_svn(None, 'ci', '-m', 'log msg')
# rev 5
update_added_file()
svntest.main.run_svn(None, 'ci', '-m', 'log msg')
svntest.main.run_svn(None, 'up', '-r', '2')
os.chdir(was_cwd)
url = svntest.main.current_repo_url
diff_output, err_output = svntest.main.run_svn(None, 'diff', '-r', '1:2',
'--username',
svntest.main.wc_author,
'--password',
svntest.main.wc_passwd,
url)
if check_update_a_file(diff_output): raise svntest.Failure
os.chdir(wc_dir)
diff_output, err_output = svntest.main.run_svn(None, 'diff', '-r', '1:2',
'--username',
svntest.main.wc_author,
'--password',
svntest.main.wc_passwd)
os.chdir(was_cwd)
if check_update_a_file(diff_output): raise svntest.Failure
diff_output, err_output = svntest.main.run_svn(None, 'diff', '-r', '2:3',
'--username',
svntest.main.wc_author,
'--password',
svntest.main.wc_passwd,
url)
if check_add_a_file_in_a_subdir(diff_output): raise svntest.Failure
os.chdir(wc_dir)
diff_output, err_output = svntest.main.run_svn(None, 'diff', '-r', '2:3',
'--username',
svntest.main.wc_author,
'--password',
svntest.main.wc_passwd)
os.chdir(was_cwd)
if check_add_a_file_in_a_subdir(diff_output): raise svntest.Failure
diff_output, err_output = svntest.main.run_svn(None, 'diff', '-r', '4:5',
'--username',
svntest.main.wc_author,
'--password',
svntest.main.wc_passwd,
url)
if check_update_added_file(diff_output): raise svntest.Failure
os.chdir(wc_dir)
diff_output, err_output = svntest.main.run_svn(None, 'diff', '-r', '4:5',
'--username',
svntest.main.wc_author,
'--password',
svntest.main.wc_passwd)
os.chdir(was_cwd)
if check_update_added_file(diff_output): raise svntest.Failure
os.chdir(wc_dir)
diff_output, err_output = svntest.main.run_svn(None, 'diff', '-r', 'head')
os.chdir(was_cwd)
if check_add_a_file_in_a_subdir_reverse(diff_output): raise svntest.Failure
# test 10
def diff_only_property_change(sbox):
"diff when property was changed but text was not"
### FIXME: Subversion erroneously tried to run an external diff
### program and aborted. This test catches that problem, but it
### really ought to check that the property diff gets output.
sbox.build()
wc_dir = sbox.wc_dir
current_dir = os.getcwd()
os.chdir(sbox.wc_dir)
try:
svntest.actions.run_and_verify_svn(None, None, [],
'propset',
'svn:eol-style', 'native', 'iota')
svntest.actions.run_and_verify_svn(None, None, [],
'ci', '-m', 'empty-msg')
svntest.actions.run_and_verify_svn(None, None, [],
'diff', '-r', '1:2')
svntest.actions.run_and_verify_svn(None, None, [],
'diff', '-r', '2:1')
svntest.actions.run_and_verify_svn(None, None, [],
'diff', '-r', '1')
finally:
os.chdir(current_dir)
#----------------------------------------------------------------------
# Regression test for issue #1019: make sure we don't try to display
# diffs when the file is marked as a binary type. This tests all 3
# uses of 'svn diff': wc-wc, wc-repos, repos-repos.
def dont_diff_binary_file(sbox):
"don't diff file marked as binary type"
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)
# Update the whole working copy to HEAD (rev 2)
expected_output = svntest.wc.State(wc_dir, {})
expected_disk = svntest.main.greek_state.copy()
expected_disk.add({
'A/theta' : Item(theta_contents,
props={'svn:mime-type' : 'application/octet-stream'}),
})
expected_status = svntest.actions.get_virginal_state(wc_dir, 2)
expected_status.add({
'A/theta' : Item(status=' ', wc_rev=2, repos_rev=2),
})
svntest.actions.run_and_verify_update(wc_dir,
expected_output,
expected_disk,
expected_status,
None, None, None, None, None,
1) # verify props, too.
# Make a local mod to the binary file.
svntest.main.file_append(theta_path, "some extra junk")
# First diff use-case: plain old 'svn diff wc' will display any
# local changes in the working copy. (diffing working
# vs. text-base)
re_nodisplay = re.compile('^Cannot display:')
stdout, stderr = svntest.main.run_svn(None, 'diff', wc_dir)
for line in stdout:
if (re_nodisplay.match(line)):
break
else:
raise svntest.Failure
# Second diff use-case: 'svn diff -r1 wc' compares the wc against a
# the first revision in the repository.
stdout, stderr = svntest.main.run_svn(None, 'diff', '-r', '1', wc_dir)
for line in stdout:
if (re_nodisplay.match(line)):
break
else:
raise svntest.Failure
# Now commit the local mod, creating rev 3.
expected_output = svntest.wc.State(wc_dir, {
'A/theta' : Item(verb='Sending'),
})
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=3, repos_rev=3),
})
svntest.actions.run_and_verify_commit(wc_dir, expected_output,
expected_status, None,
None, None, None, None, wc_dir)
# Third diff use-case: 'svn diff -r2:3 wc' will compare two
# repository trees.
stdout, stderr = svntest.main.run_svn(None, 'diff', '-r', '2:3', wc_dir)
for line in stdout:
if (re_nodisplay.match(line)):
break
else:
raise svntest.Failure
def diff_nonextant_urls(sbox):
"svn diff errors against a non-existant URL"
sbox.build()
non_extant_url = sbox.repo_url + '/A/does_not_exist'
extant_url = sbox.repo_url + '/A/mu'
diff_output, err_output = svntest.main.run_svn(1, 'diff',
'--old', non_extant_url,
'--new', extant_url)
for line in err_output:
if re.search('was not found in the repository at revision', line):
break
else:
raise svntest.Failure
diff_output, err_output = svntest.main.run_svn(1, 'diff',
'--old', extant_url,
'--new', non_extant_url)
for line in err_output:
if re.search('was not found in the repository at revision', line):
break
else:
raise svntest.Failure
def diff_head_of_moved_file(sbox):
"diff against the head of a moved file"
sbox.build()
mu_path = os.path.join(sbox.wc_dir, 'A', 'mu')
new_mu_path = mu_path + '.new'
svntest.main.run_svn(None, 'mv', mu_path, new_mu_path)
# Modify the file to ensure that the diff is non-empty.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?