📄 prop_tests.py
字号:
set_prop('svn:ignore', '*.o\nfoo.c\n', B_path) # A trailing newline should be added set_prop('svn:externals', 'foo http://foo.com/repos', A_path) set_prop('svn:externals', 'foo http://foo.com/repos\n', B_path) # Leading and trailing whitespace should be stripped, but not internal # whitespace set_prop('svn:keywords', ' Rev Date \n', iota_path) set_prop('svn:keywords', 'Rev Date', mu_path) # svn:executable value should be forced to a '*' set_prop('svn:executable', 'foo', iota_path) set_prop('svn:executable', '', lambda_path) set_prop('svn:executable', ' ', mu_path) # Anything else should be untouched set_prop('svn:some-prop', 'bar', lambda_path) set_prop('svn:some-prop', ' bar baz', mu_path) set_prop('svn:some-prop', 'bar\n', iota_path) set_prop('some-prop', 'bar', lambda_path) set_prop('some-prop', ' bar baz', mu_path) set_prop('some-prop', 'bar\n', iota_path) # Close and remove the prop value file propval_file.close() os.unlink(propval_path) # NOTE: When writing out multi-line prop values in svn:* props, the # client converts to local encoding and local eoln style. # Therefore, the expected output must contain the right kind of eoln # strings. That's why we use os.linesep in the tests below, not just # plain '\n'. The _last_ \n is also from the client, but it's not # part of the prop value and it doesn't get converted in the pipe. # Check svn:mime-type check_prop('svn:mime-type', iota_path, ['text/html']) check_prop('svn:mime-type', mu_path, ['text/html']) # Check svn:eol-style check_prop('svn:eol-style', iota_path, ['native']) check_prop('svn:eol-style', mu_path, ['native']) # Check svn:ignore check_prop('svn:ignore', A_path, ['*.o'+os.linesep, 'foo.c'+os.linesep]) check_prop('svn:ignore', B_path, ['*.o'+os.linesep, 'foo.c'+os.linesep]) # Check svn:externals check_prop('svn:externals', A_path, ['foo http://foo.com/repos'+os.linesep]) check_prop('svn:externals', B_path, ['foo http://foo.com/repos'+os.linesep]) # Check svn:keywords check_prop('svn:keywords', iota_path, ['Rev Date']) check_prop('svn:keywords', mu_path, ['Rev Date']) # Check svn:executable check_prop('svn:executable', iota_path, ['*']) check_prop('svn:executable', lambda_path, ['*']) check_prop('svn:executable', mu_path, ['*']) # Check other props check_prop('svn:some-prop', lambda_path, ['bar']) check_prop('svn:some-prop', mu_path, [' bar baz']) check_prop('svn:some-prop', iota_path, ['bar'+os.linesep]) check_prop('some-prop', lambda_path, ['bar']) check_prop('some-prop', mu_path,[' bar baz']) check_prop('some-prop', iota_path, ['bar\n'])#----------------------------------------------------------------------def binary_props(sbox): "test binary property support" # 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) # Some path convenience vars. A_path = os.path.join(wc_dir, 'A') B_path = os.path.join(wc_dir, 'A', 'B') iota_path = os.path.join(wc_dir, 'iota') lambda_path = os.path.join(wc_dir, 'A', 'B', 'lambda') mu_path = os.path.join(wc_dir, 'A', 'mu') A_path_bak = os.path.join(wc_backup, 'A') B_path_bak = os.path.join(wc_backup, 'A', 'B') iota_path_bak = os.path.join(wc_backup, 'iota') lambda_path_bak = os.path.join(wc_backup, 'A', 'B', 'lambda') mu_path_bak = os.path.join(wc_backup, 'A', 'mu') # Property value convenience vars. prop_zb = "This property has a zer\000 byte." prop_ff = "This property has a form\014feed." prop_xml = "This property has an <xml> tag." prop_binx = "This property has an <xml> tag and a zer\000 byte." # Set some binary properties. propval_path = os.path.join(wc_dir, 'propval.tmp') propval_file = open(propval_path, 'wb') def set_prop(name, value, path, valf=propval_file, valp=propval_path): valf.seek(0) valf.truncate(0) valf.write(value) valf.flush() svntest.main.run_svn(None, 'propset', '-F', valp, name, path) set_prop('prop_zb', prop_zb, B_path) set_prop('prop_ff', prop_ff, iota_path) set_prop('prop_xml', prop_xml, lambda_path) set_prop('prop_binx', prop_binx, mu_path) set_prop('prop_binx', prop_binx, A_path) # Create expected output and status trees. expected_output = svntest.wc.State(wc_dir, { 'A' : Item(verb='Sending'), 'A/B' : Item(verb='Sending'), 'iota' : Item(verb='Sending'), 'A/B/lambda' : Item(verb='Sending'), 'A/mu' : Item(verb='Sending'), }) expected_status = svntest.actions.get_virginal_state(wc_dir, 1) expected_status.tweak('A', 'A/B', 'iota', 'A/B/lambda', 'A/mu', wc_rev=2, status=' ') # Commit the propsets. svntest.actions.run_and_verify_commit (wc_dir, expected_output, expected_status, None, None, None, None, None, wc_dir) # Create expected output, disk, and status trees for an update of # the wc_backup. expected_output = svntest.wc.State(wc_backup, { 'A' : Item(status=' U'), 'A/B' : Item(status=' U'), 'iota' : Item(status=' U'), 'A/B/lambda' : Item(status=' U'), 'A/mu' : Item(status=' U'), }) expected_disk = svntest.main.greek_state.copy() expected_status = svntest.actions.get_virginal_state(wc_backup, 2) # Do the update and check the results. svntest.actions.run_and_verify_update(wc_backup, expected_output, expected_disk, expected_status, None, None, None, None, None, 0) # Now, check those properties. check_prop('prop_zb', B_path_bak, [prop_zb]) check_prop('prop_ff', iota_path_bak, [prop_ff]) check_prop('prop_xml', lambda_path_bak, [prop_xml]) check_prop('prop_binx', mu_path_bak, [prop_binx]) check_prop('prop_binx', A_path_bak, [prop_binx])#----------------------------------------------------------------------def recursive_base_wc_ops(sbox): "recursive property operations in BASE and WC" # Bootstrap sbox.build() wc_dir = sbox.wc_dir # Files with which to test, in alphabetical order f_add = os.path.join('A', 'added') f_del = os.path.join('A', 'mu') f_keep= os.path.join('iota') fp_add = os.path.join(wc_dir, f_add) fp_del = os.path.join(wc_dir, f_del) fp_keep= os.path.join(wc_dir, f_keep) # Set up properties svntest.main.run_svn(None, 'propset', 'p', 'old-del', fp_del) svntest.main.run_svn(None, 'propset', 'p', 'old-keep',fp_keep) svntest.main.run_svn(None, 'commit', '-m', '', wc_dir) svntest.main.file_append(fp_add, 'blah') svntest.main.run_svn(None, 'add', fp_add) svntest.main.run_svn(None, 'propset', 'p', 'new-add', fp_add) svntest.main.run_svn(None, 'propset', 'p', 'new-del', fp_del) svntest.main.run_svn(None, 'propset', 'p', 'new-keep',fp_keep) svntest.main.run_svn(None, 'del', '--force', fp_del) # Ensure that each line of output contains the corresponding string of # expected_out, and that errput is empty. def verify_output(expected_out, output, errput): if errput != []: print 'Error: stderr:' print errput raise svntest.Failure output.sort() ln = 0 for line in output: if ((line.find(expected_out[ln]) == -1) or (line != '' and expected_out[ln] == '')): print 'Error: expected keywords: ', expected_out print ' actual full output:', output raise svntest.Failure ln = ln + 1 # Test recursive proplist output, errput = svntest.main.run_svn(None, 'proplist', '-R', '-v', wc_dir, '-rBASE') verify_output([ 'old-del', 'old-keep', 'Properties on ', 'Properties on ' ], output, errput) output, errput = svntest.main.run_svn(None, 'proplist', '-R', '-v', wc_dir) verify_output([ 'new-add', 'new-keep', 'Properties on ', 'Properties on ' ], output, errput) # Test recursive propget output, errput = svntest.main.run_svn(None, 'propget', '-R', 'p', wc_dir, '-rBASE') verify_output([ 'old-del', 'old-keep' ], output, errput) output, errput = svntest.main.run_svn(None, 'propget', '-R', 'p', wc_dir) verify_output([ 'new-add', 'new-keep' ], output, errput) # Test recursive propset (issue 1794) expected_status = svntest.actions.get_virginal_state(wc_dir, 1) expected_status.tweak('A/mu', status='D ', wc_rev=2) expected_status.tweak('iota', status=' M', wc_rev=2) expected_status.add({ 'A/added' : Item(status='A ', wc_rev=0), }) svntest.actions.run_and_verify_status(wc_dir, expected_status) svntest.actions.run_and_verify_svn(None, None, [], 'propset', '-R', 'svn:keywords', 'Date', os.path.join(wc_dir, 'A', 'B')) expected_status.tweak('A/B/lambda', 'A/B/E/alpha', 'A/B/E/beta', status=' M') svntest.actions.run_and_verify_status(wc_dir, expected_status)#----------------------------------------------------------------------def url_props_ops(sbox): "property operations on an URL" # Bootstrap sbox.build() wc_dir = sbox.wc_dir prop1 = 'prop1' propval1 = 'propval1' prop2 = 'prop2' propval2 = 'propval2' iota_path = os.path.join(sbox.wc_dir, 'iota') iota_url = svntest.main.current_repo_url + '/iota' A_path = os.path.join(sbox.wc_dir, 'A') A_url = svntest.main.current_repo_url + '/A' # Add a couple of properties svntest.main.run_svn(None, 'propset', prop1, propval1, iota_path) svntest.main.run_svn(None, 'propset', prop1, propval1, A_path) # Commit svntest.main.run_svn(None, 'ci', '-m', 'logmsg', sbox.wc_dir) # Add a few more properties svntest.main.run_svn(None, 'propset', prop2, propval2, iota_path) svntest.main.run_svn(None, 'propset', prop2, propval2, A_path) # Commit again svntest.main.run_svn(None, 'ci', '-m', 'logmsg', sbox.wc_dir) # Ensure that each line of output contains the corresponding string of # expected_out, and that errput is empty. def verify_output(expected_out, output, errput): if errput != []: print 'Error: stderr:' print errput raise svntest.Failure output.sort() ln = 0 for line in output: if ((line.find(expected_out[ln]) == -1) or (line != '' and expected_out[ln] == '')): print 'Error: expected keywords: ', expected_out print ' actual full output:', output raise svntest.Failure ln = ln + 1 # Test propget svntest.actions.run_and_verify_svn(None, [ propval1 + '\n' ], [], 'propget', prop1, iota_url) svntest.actions.run_and_verify_svn(None, [ propval1 + '\n' ], [], 'propget', prop1, A_url) # Test normal proplist output, errput = svntest.main.run_svn(None, 'proplist', iota_url) verify_output([ prop1, prop2, 'Properties on ' ], output, errput) output, errput = svntest.main.run_svn(None, 'proplist', A_url) verify_output([ prop1, prop2, 'Properties on ' ], output, errput) # Test verbose proplist output, errput = svntest.main.run_svn(None, 'proplist', '-v', iota_url) verify_output([ prop1 + ' : ' + propval1, prop2 + ' : ' + propval2, 'Properties on ' ], output, errput) output, errput = svntest.main.run_svn(None, 'proplist', '-v', A_url) verify_output([ prop1 + ' : ' + propval1, prop2 + ' : ' + propval2, 'Properties on ' ], output, errput)#----------------------------------------------------------------------def removal_schedule_added_props(sbox): "removal of schedule added file with properties" sbox.build() wc_dir = sbox.wc_dir newfile_path = os.path.join(wc_dir, 'newfile') file_add_output = ["A " + newfile_path + "\n"] propset_output = ["property 'newprop' set on '" + newfile_path + "'\n"] file_rm_output = ["D " + newfile_path + "\n"] propls_output = [ "Properties on '" + newfile_path + "':\n", " newprop : newvalue\n", ] # create new fs file open(newfile_path, 'w').close() # Add it and set a property svntest.actions.run_and_verify_svn(None, file_add_output, [], 'add', newfile_path) svntest.actions.run_and_verify_svn(None, propset_output, [], 'propset', 'newprop', 'newvalue', newfile_path) svntest.actions.run_and_verify_svn(None, propls_output, [], 'proplist', '-v', newfile_path) # remove the file svntest.actions.run_and_verify_svn(None, file_rm_output, [], 'rm', '--force', newfile_path) # recreate the file and add it again open(newfile_path, 'w').close() svntest.actions.run_and_verify_svn(None, file_add_output, [], 'add', newfile_path) # Now there should be NO properties leftover... svntest.actions.run_and_verify_svn(None, [], [], 'proplist', '-v', newfile_path)######################################################################### Run the tests# list all tests here, starting with None:test_list = [ None, make_local_props, commit_props, update_props, downdate_props, remove_props, update_conflict_props, commit_replacement_props, revert_replacement_props, inappropriate_props, copy_inherits_special_props, # If we learn how to write a pre-revprop-change hook for # non-Posix platforms, we won't have to skip here: Skip(revprop_change, (os.name != 'posix' and sys.platform != 'win32')), prop_value_conversions, binary_props, recursive_base_wc_ops, url_props_ops, removal_schedule_added_props, ]if __name__ == '__main__': svntest.main.run_tests(test_list) # NOTREACHED### End of file.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -