⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lock_tests.py

📁 subversion-1.4.3-1.tar.gz 配置svn的源码
💻 PY
📖 第 1 页 / 共 5 页
字号:
#!/usr/bin/env python##  lock_tests.py:  testing versioned properties##  Subversion is a tool for revision control.#  See http://subversion.tigris.org for more information.## ====================================================================# Copyright (c) 2005-2006 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 modulesimport string, sys, re, os.path, shutil, stat# Our testing moduleimport svntest# A helper function for examining svn:needs-lockfrom prop_tests import check_prop# (abbreviation)Skip = svntest.testcase.SkipXFail = svntest.testcase.XFailItem = svntest.wc.StateItem####################################################################### Tests#----------------------------------------------------------------------# Each test refers to a section in# notes/locking/locking-functional-spec.txt# II.A.2, II.C.2.a: Lock a file in wc A as user FOO and make sure we# have a representation of it.  Checkout wc B as user BAR.  Verify# that user BAR cannot commit changes to the file nor its properties.def lock_file(sbox):  "lock a file and verify that it's locked"  sbox.build()  wc_dir = sbox.wc_dir  # Make a second copy of the working copy  wc_b = sbox.add_wc_path('_b')  svntest.actions.duplicate_dir(wc_dir, wc_b)  # lock a file as wc_author  fname = 'iota'  file_path = os.path.join(sbox.wc_dir, fname)  file_path_b = os.path.join(wc_b, fname)  svntest.main.file_append(file_path, "This represents a binary file\n")  svntest.main.run_svn(None, 'commit',                       '--username', svntest.main.wc_author,                       '--password', svntest.main.wc_passwd,                       '-m', '', file_path)  svntest.actions.run_and_verify_svn(None, ".*locked by user", [], 'lock',                                     '--username', svntest.main.wc_author,                                     '--password', svntest.main.wc_passwd,                                     '-m', '', file_path)  # --- Meanwhile, in our other working copy... ---  err_re = "((.*User jconstant does not own lock on path.*)|(.*423 Locked.*))"  svntest.main.run_svn(None, 'update', wc_b)  # -- Try to change a file --  # change the locked file  svntest.main.file_append(file_path_b, "Covert tweak\n")  # attempt (and fail) to commit as user Sally  svntest.actions.run_and_verify_commit (wc_b, None, None, err_re,                                         None, None, None, None,                                         '--username',                                         svntest.main.wc_author2,                                         '--password',                                         svntest.main.wc_passwd,                                         '-m', '', file_path_b)  # Revert our change that we failed to commit  svntest.main.run_svn(None, 'revert', file_path_b)  # -- Try to change a property --  # change the locked file's properties  svntest.main.run_svn(None, 'propset', 'sneakyuser', 'Sally', file_path_b)  err_re = "((.*User jconstant does not own lock on path.*)" + \             "|(.*At least one property change failed.*))"  # attempt (and fail) to commit as user Sally  svntest.actions.run_and_verify_commit (wc_b, None, None, err_re,                                         None, None, None, None,                                         '--username',                                         svntest.main.wc_author2,                                         '--password',                                         svntest.main.wc_passwd,                                         '-m', '', file_path_b)#----------------------------------------------------------------------# II.C.2.b.[12]: Lock a file and commit using the lock.  Make sure the# lock is released.  Repeat, but request that the lock not be# released.  Make sure the lock is retained.def commit_file_keep_lock(sbox):  "commit a file and keep lock"  sbox.build()  wc_dir = sbox.wc_dir  fname = 'A/mu'  file_path = os.path.join(sbox.wc_dir, fname)  # lock fname as wc_author  svntest.actions.run_and_verify_svn(None, ".*locked by user", [], 'lock',                                     '--username', svntest.main.wc_author,                                     '--password', svntest.main.wc_passwd,                                     '-m', 'some lock comment', file_path)  # make a change and commit it, holding lock  svntest.main.file_append(file_path, "Tweak!\n")  svntest.main.run_svn(None, 'commit', '-m', '', '--no-unlock', file_path)  expected_status = svntest.actions.get_virginal_state(wc_dir, 2)  expected_status.tweak(wc_rev=1)  expected_status.tweak(fname, wc_rev=2)  expected_status.tweak(fname, writelocked='K')  # Make sure the file is still locked  svntest.actions.run_and_verify_status(wc_dir, expected_status)def commit_file_unlock(sbox):  "commit a file and release lock"  sbox.build()  wc_dir = sbox.wc_dir  fname = 'A/mu'  file_path = os.path.join(sbox.wc_dir, fname)  # lock fname as wc_author  svntest.actions.run_and_verify_svn(None, ".*locked by user", [], 'lock',                                     '--username', svntest.main.wc_author,                                     '--password', svntest.main.wc_passwd,                                     '-m', 'some lock comment', file_path)  # make a change and commit it, allowing lock to be released  svntest.main.file_append(file_path, "Tweak!\n")  svntest.main.run_svn(None, 'commit', '-m', '', file_path)  expected_status = svntest.actions.get_virginal_state(wc_dir, 2)  expected_status.tweak(wc_rev=1)  expected_status.tweak(fname, wc_rev=2)  # Make sure the file is unlocked  svntest.actions.run_and_verify_status(wc_dir, expected_status)#----------------------------------------------------------------------def commit_propchange(sbox):  "commit a locked file with a prop change"  sbox.build()  wc_dir = sbox.wc_dir  fname = 'A/mu'  file_path = os.path.join(sbox.wc_dir, fname)  # lock fname as wc_author  svntest.actions.run_and_verify_svn(None, ".*locked by user", [], 'lock',                                     '--username', svntest.main.wc_author,                                     '--password', svntest.main.wc_passwd,                                     '-m', 'some lock comment', file_path)  # make a property change and commit it, allowing lock to be released  svntest.main.run_svn(None, 'propset', 'blue', 'azul', file_path)  svntest.main.run_svn(None, 'commit', '-m', '', file_path)  expected_status = svntest.actions.get_virginal_state(wc_dir, 2)  expected_status.tweak(wc_rev=1)  expected_status.tweak(fname, wc_rev=2)  # Make sure the file is unlocked  svntest.actions.run_and_verify_status(wc_dir, expected_status)#----------------------------------------------------------------------# II.C.2.c: Lock a file in wc A as user FOO.  Attempt to unlock same# file in same wc as user BAR.  Should fail.## Attempt again with --force.  Should succeed.## II.C.2.c: Lock a file in wc A as user FOO.  Attempt to unlock same# file in wc B as user FOO.  Should fail.## Attempt again with --force.  Should succeed.def break_lock(sbox):  "lock a file and verify lock breaking behavior"  sbox.build()  wc_dir = sbox.wc_dir  # Make a second copy of the working copy  wc_b = sbox.add_wc_path('_b')  svntest.actions.duplicate_dir(wc_dir, wc_b)  # lock a file as wc_author  fname = 'iota'  file_path = os.path.join(sbox.wc_dir, fname)  file_path_b = os.path.join(wc_b, fname)  svntest.actions.run_and_verify_svn(None, ".*locked by user", [], 'lock',                                     '--username', svntest.main.wc_author,                                     '--password', svntest.main.wc_passwd,                                     '-m', '', file_path)  # --- Meanwhile, in our other working copy... ---  svntest.main.run_svn(None, 'update', wc_b)  # attempt (and fail) to unlock file  # This should give a "iota' is not locked in this working copy" error  svntest.actions.run_and_verify_svn(None, None, ".*not locked",                                     'unlock',                                     '--username', svntest.main.wc_author,                                     '--password', svntest.main.wc_passwd,                                     file_path_b)  svntest.actions.run_and_verify_svn(None, ".*unlocked", [],                                     'unlock', '--force',                                     '--username', svntest.main.wc_author,                                     '--password', svntest.main.wc_passwd,                                     file_path_b)#----------------------------------------------------------------------# II.C.2.d: Lock a file in wc A as user FOO.  Attempt to lock same# file in wc B as user BAR.  Should fail.## Attempt again with --force.  Should succeed.## II.C.2.d: Lock a file in wc A as user FOO.  Attempt to lock same# file in wc B as user FOO.  Should fail.## Attempt again with --force.  Should succeed.def steal_lock(sbox):  "lock a file and verify lock stealing behavior"  sbox.build()  wc_dir = sbox.wc_dir  # Make a second copy of the working copy  wc_b = sbox.add_wc_path('_b')  svntest.actions.duplicate_dir(wc_dir, wc_b)  # lock a file as wc_author  fname = 'iota'  file_path = os.path.join(sbox.wc_dir, fname)  file_path_b = os.path.join(wc_b, fname)  svntest.actions.run_and_verify_svn(None, ".*locked by user", [], 'lock',                                     '--username', svntest.main.wc_author,                                     '--password', svntest.main.wc_passwd,                                     '-m', '', file_path)  # --- Meanwhile, in our other working copy... ---  svntest.main.run_svn(None, 'update', wc_b)  # attempt (and fail) to lock file  # This should give a "iota' is already locked... error.  svntest.actions.run_and_verify_svn(None, None,                                     ".*already locked",                                     'lock',                                     '--username', svntest.main.wc_author,                                     '--password', svntest.main.wc_passwd,                                     '-m', 'trying to break', file_path_b)  svntest.actions.run_and_verify_svn(None, ".*locked by user", [],                                     'lock', '--force',                                     '--username', svntest.main.wc_author,                                     '--password', svntest.main.wc_passwd,                                     '-m', 'trying to break', file_path_b)#----------------------------------------------------------------------# II.B.2, II.C.2.e: Lock a file in wc A.  Query wc for the# lock and verify that all lock fields are present and correct.def examine_lock(sbox):  "examine the fields of a lockfile for correctness"  sbox.build()  wc_dir = sbox.wc_dir  fname = 'iota'  comment = 'This is a lock test.'  file_path = os.path.join(sbox.wc_dir, fname)  # lock a file as wc_author  svntest.actions.run_and_verify_svn(None, ".*locked by user", [], 'lock',                                     '--username', svntest.main.wc_author,                                     '--password', svntest.main.wc_passwd,                                     '-m', comment, file_path)  output, err = svntest.actions.run_and_verify_svn(None, None, [],                                                   'info', file_path)  lock_info = output[-6:-1]  if ((len(lock_info) != 5)      or (lock_info[0][0:28] != 'Lock Token: opaquelocktoken:')      or (lock_info[1] != 'Lock Owner: ' + svntest.main.wc_author + '\n')      or (lock_info[2][0:13] != 'Lock Created:')      or (lock_info[4] != comment + '\n')):    raise svntest.Failure#----------------------------------------------------------------------# II.C.1: Lock a file in wc A.  Check out wc B.  Break the lock in wc

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -