📄 prop_tests.py
字号:
#!/usr/bin/env python
#
# prop_tests.py: testing versioned properties
#
# 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, re, os.path, shutil
# Our testing module
import svntest
# (abbreviation)
Skip = svntest.testcase.Skip
XFail = svntest.testcase.XFail
Item = svntest.wc.StateItem
# Helper functions
def check_prop(name, path, exp_out):
"""Verify that property NAME on PATH has a value of EXP_OUT"""
# Not using run_svn because binary_mode must be set
out, err = svntest.main.run_command(svntest.main.svn_binary, None, 1,
'pg', '--strict', name, path,
'--config-dir', svntest.main.config_dir)
if out != exp_out:
print "svn pg --strict", name, "output does not match expected."
print "Expected standard output: ", exp_out, "\n"
print "Actual standard output: ", out, "\n"
raise svntest.Failure
######################################################################
# Tests
#----------------------------------------------------------------------
def make_local_props(sbox):
"write/read props in wc only (ps, pl, pdel)"
# Bootstrap
sbox.build()
wc_dir = sbox.wc_dir
# Add properties to one file and one directory
svntest.main.run_svn(None, 'propset', 'blue', 'azul',
os.path.join(wc_dir, 'A', 'mu'))
svntest.main.run_svn(None, 'propset', 'green', 'verde',
os.path.join(wc_dir, 'A', 'mu'))
svntest.main.run_svn(None, 'propset', 'red', 'rojo',
os.path.join(wc_dir, 'A', 'D', 'G'))
svntest.main.run_svn(None, 'propset', 'yellow', 'amarillo',
os.path.join(wc_dir, 'A', 'D', 'G'))
# Make sure they show up as local mods in status
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
expected_status.tweak('A/mu', status=' M')
expected_status.tweak('A/D/G', status=' M')
svntest.actions.run_and_verify_status(wc_dir, expected_status)
# Remove one property
svntest.main.run_svn(None, 'propdel', 'yellow',
os.path.join(wc_dir, 'A', 'D', 'G'))
# What we expect the disk tree to look like:
expected_disk = svntest.main.greek_state.copy()
expected_disk.tweak('A/mu', props={'blue' : 'azul', 'green' : 'verde'})
expected_disk.tweak('A/D/G', props={'red' : 'rojo'})
# Read the real disk tree. Notice we are passing the (normally
# disabled) "load props" flag to this routine. This will run 'svn
# proplist' on every item in the working copy!
actual_disk_tree = svntest.tree.build_tree_from_wc(wc_dir, 1)
# Compare actual vs. expected disk trees.
svntest.tree.compare_trees(actual_disk_tree, expected_disk.old_tree())
#----------------------------------------------------------------------
def commit_props(sbox):
"commit properties"
# Bootstrap
sbox.build()
wc_dir = sbox.wc_dir
# Add a property to a file and a directory
mu_path = os.path.join(wc_dir, 'A', 'mu')
H_path = os.path.join(wc_dir, 'A', 'D', 'H')
svntest.main.run_svn(None, 'propset', 'blue', 'azul', mu_path)
svntest.main.run_svn(None, 'propset', 'red', 'rojo', H_path)
# Create expected output tree.
expected_output = svntest.wc.State(wc_dir, {
'A/mu' : Item(verb='Sending'),
'A/D/H' : Item(verb='Sending'),
})
# Created expected status tree.
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
expected_status.tweak(repos_rev=2)
expected_status.tweak('A/mu', 'A/D/H', wc_rev=2, status=' ')
# Commit the one file.
svntest.actions.run_and_verify_commit (wc_dir,
expected_output,
expected_status,
None,
None, None,
None, None,
wc_dir)
#----------------------------------------------------------------------
def update_props(sbox):
"receive properties via update"
# Bootstrap
sbox.build()
wc_dir = sbox.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)
# Add a property to a file and a directory
mu_path = os.path.join(wc_dir, 'A', 'mu')
H_path = os.path.join(wc_dir, 'A', 'D', 'H')
svntest.main.run_svn(None, 'propset', 'blue', 'azul', mu_path)
svntest.main.run_svn(None, 'propset', 'red', 'rojo', H_path)
# Create expected output tree.
expected_output = svntest.wc.State(wc_dir, {
'A/mu' : Item(verb='Sending'),
'A/D/H' : Item(verb='Sending'),
})
# Created expected status tree.
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
expected_status.tweak(repos_rev=2)
expected_status.tweak('A/mu', 'A/D/H', wc_rev=2, status=' ')
# Commit the one file.
svntest.actions.run_and_verify_commit (wc_dir, expected_output,
expected_status,
None, None, None, None, None,
wc_dir)
# Overwrite mu_path and H_path to refer to the backup copies from
# here on out.
mu_path = os.path.join(wc_backup, 'A', 'mu')
H_path = os.path.join(wc_backup, 'A', 'D', 'H')
# Create expected output tree for an update of the wc_backup.
expected_output = svntest.wc.State(wc_backup, {
'A/mu' : Item(status=' U'),
'A/D/H' : Item(status=' U'),
})
# Create expected disk tree for the update.
expected_disk = svntest.main.greek_state.copy()
expected_disk.tweak('A/mu', props={'blue' : 'azul'})
expected_disk.tweak('A/D/H', props={'red' : 'rojo'})
# Create expected status tree for the update.
expected_status = svntest.actions.get_virginal_state(wc_backup, 2)
expected_status.tweak('A/mu', 'A/D/H', status=' ')
# Do the update and check the results in three ways... INCLUDING PROPS
svntest.actions.run_and_verify_update(wc_backup,
expected_output,
expected_disk,
expected_status,
None, None, None, None, None, 1)
#----------------------------------------------------------------------
def downdate_props(sbox):
"receive property changes as part of a downdate"
# Bootstrap
sbox.build()
wc_dir = sbox.wc_dir
iota_path = os.path.join(wc_dir, 'iota')
mu_path = os.path.join(wc_dir, 'A', 'mu')
# Add a property to a file
svntest.main.run_svn(None, 'propset', 'cash-sound', 'cha-ching!', iota_path)
# Create expected output tree.
expected_output = svntest.wc.State(wc_dir, {
'iota' : Item(verb='Sending'),
})
# Created expected status tree.
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
expected_status.tweak(repos_rev=2)
expected_status.tweak('iota', wc_rev=2, status=' ')
# Commit the one file.
svntest.actions.run_and_verify_commit (wc_dir, expected_output,
expected_status,
None, None, None, None, None,
wc_dir)
# Make some mod (something to commit)
svntest.main.file_append (mu_path, "some mod")
# Create expected output tree.
expected_output = svntest.wc.State(wc_dir, {
'A/mu' : Item(verb='Sending'),
})
# Created expected status tree.
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
expected_status.tweak(repos_rev=3)
expected_status.tweak('iota', wc_rev=2, status=' ')
expected_status.tweak('A/mu', wc_rev=3, status=' ')
# Commit the one file.
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.
expected_output = svntest.wc.State(wc_dir, {
'iota' : Item(status=' U'),
'A/mu' : Item(status='U '),
})
# Create expected disk tree for the update.
expected_disk = svntest.main.greek_state
# Create expected status tree for the update.
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
expected_status.tweak(repos_rev=3)
# Do the update and check the results in three ways... INCLUDING PROPS
svntest.actions.run_and_verify_update(wc_dir,
expected_output,
expected_disk,
expected_status,
None, None, None, None, None, 1,
'-r', '1', wc_dir)
#----------------------------------------------------------------------
def remove_props(sbox):
"commit the removal of props"
# Bootstrap
sbox.build()
wc_dir = sbox.wc_dir
# Add a property to a file
iota_path = os.path.join(wc_dir, 'iota')
svntest.main.run_svn(None, 'propset', 'cash-sound', 'cha-ching!', iota_path)
# Commit the file
svntest.main.run_svn(None, 'ci', '-m', 'logmsg', iota_path)
# Now, remove the property
svntest.main.run_svn(None, 'propdel', 'cash-sound', iota_path)
# Create expected output tree.
expected_output = svntest.wc.State(wc_dir, {
'iota' : Item(verb='Sending'),
})
# Created expected status tree.
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
expected_status.tweak(repos_rev=3)
expected_status.tweak('iota', wc_rev=3, status=' ')
# Commit the one file.
svntest.actions.run_and_verify_commit (wc_dir, expected_output,
expected_status,
None, None, None, None, None,
wc_dir)
#----------------------------------------------------------------------
# Helper for update_conflict_props() test -- a custom singleton handler.
def detect_conflict_files(node, extra_files):
"""NODE has been discovered an extra file on disk. Verify that it
matches one of the regular expressions in the EXTRA_FILES list. If
it matches, remove the match from the list. If it doesn't match,
raise an exception."""
for pattern in extra_files:
mo = re.match(pattern, node.name)
if mo:
extra_files.pop(extra_files.index(pattern)) # delete pattern from list
break
else:
print "Found unexpected disk object:", node.name
raise svntest.tree.SVNTreeUnequal
def update_conflict_props(sbox):
"update with conflicting props"
# Bootstrap
sbox.build()
wc_dir = sbox.wc_dir
# Add a property to a file and a directory
mu_path = os.path.join(wc_dir, 'A', 'mu')
svntest.main.run_svn(None, 'propset', 'cash-sound', 'cha-ching!', mu_path)
A_path = os.path.join(wc_dir, 'A')
svntest.main.run_svn(None, 'propset', 'foo', 'bar', A_path)
# Commit the file and directory
svntest.main.run_svn(None, 'ci', '-m', 'logmsg', wc_dir)
# Update to rev 1
svntest.main.run_svn(None, 'up', '-r', '1', wc_dir)
# Add conflicting properties
svntest.main.run_svn(None, 'propset', 'cash-sound', 'beep!', mu_path)
svntest.main.run_svn(None, 'propset', 'foo', 'baz', A_path)
# Create expected output tree for an update of the wc_backup.
expected_output = svntest.wc.State(wc_dir, {
'A/mu' : Item(status=' C'),
'A' : Item(status=' C'),
})
# Create expected disk tree for the update.
expected_disk = svntest.main.greek_state.copy()
expected_disk.tweak('A/mu', props={'cash-sound' : 'beep!'})
expected_disk.tweak('A', props={'foo' : 'baz'})
# Create expected status tree for the update.
expected_status = svntest.actions.get_virginal_state(wc_dir, 2)
expected_status.tweak('A/mu', 'A', status=' C')
extra_files = ['mu.*\.prej', 'dir_conflicts.*\.prej']
# Do the update and check the results in three ways... INCLUDING PROPS
svntest.actions.run_and_verify_update(wc_dir,
expected_output,
expected_disk,
expected_status,
None,
detect_conflict_files, extra_files,
None, None, 1)
if len(extra_files) != 0:
print "didn't get expected conflict files"
raise svntest.actions.SVNUnexpectedOutput
# Resolve the conflicts
svntest.main.run_svn(None, 'resolved', mu_path)
svntest.main.run_svn(None, 'resolved', A_path)
expected_status = svntest.actions.get_virginal_state(wc_dir, 2)
expected_status.tweak('A/mu', 'A', status=' M')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -