📄 actions.py
字号:
'--username', main.wc_author, '--password', main.wc_passwd, '-m', 'log msg', *args) if (error_re_string): rm = re.compile(error_re_string) for line in errput: match = rm.search(line) if match: return raise main.SVNUnmatchedError # Else not expecting error: # Remove the final output line, and verify that the commit succeeded. lastline = "" if len(output): lastline = string.strip(output.pop()) cm = re.compile("(Committed|Imported) revision [0-9]+.") match = cm.search(lastline) if not match: print "ERROR: commit did not succeed." print "The final line from 'svn ci' was:" print lastline raise main.SVNCommitFailure # The new 'final' line in the output is either a regular line that # mentions {Adding, Deleting, Sending, ...}, or it could be a line # that says "Transmitting file data ...". If the latter case, we # want to remove the line from the output; it should be ignored when # building a tree. if len(output): lastline = output.pop() tm = re.compile("Transmitting file data.+") match = tm.search(lastline) if not match: # whoops, it was important output, put it back. output.append(lastline) # Convert the output into a tree. mytree = tree.build_tree_from_commit (output) # Verify actual output against expected output. try: tree.compare_trees (mytree, output_tree) except tree.SVNTreeError: display_trees("Output of commit is unexpected.", "OUTPUT TREE", output_tree, mytree) raise # Verify via 'status' command too, if possible. if status_output_tree: run_and_verify_status(wc_dir_name, status_output_tree)# This function always passes '-q' to the status command, which# suppresses the printing of any unversioned or nonexistent items.def run_and_verify_status(wc_dir_name, output_tree, singleton_handler_a = None, a_baton = None, singleton_handler_b = None, b_baton = None): """Run 'status' on WC_DIR_NAME and compare it with the expected OUTPUT_TREE. SINGLETON_HANDLER_A and SINGLETON_HANDLER_B will be passed to tree.compare_trees - see that function's doc string for more details. Returns on success, raises on failure.""" if isinstance(output_tree, wc.State): output_tree = output_tree.old_tree() output, errput = main.run_svn (None, 'status', '-v', '-u', '-q', '--username', main.wc_author, '--password', main.wc_passwd, wc_dir_name) mytree = tree.build_tree_from_status (output) # Verify actual output against expected output. try: tree.compare_trees (mytree, output_tree, singleton_handler_a, a_baton, singleton_handler_b, b_baton) except tree.SVNTreeError: display_trees(None, 'STATUS OUTPUT TREE', output_tree, mytree) raise# A variant of previous func, but doesn't pass '-q'. This allows us# to verify unversioned or nonexistent items in the list.def run_and_verify_unquiet_status(wc_dir_name, output_tree, singleton_handler_a = None, a_baton = None, singleton_handler_b = None, b_baton = None): """Run 'status' on WC_DIR_NAME and compare it with the expected OUTPUT_TREE. SINGLETON_HANDLER_A and SINGLETON_HANDLER_B will be passed to tree.compare_trees - see that function's doc string for more details. Returns on success, raises on failure.""" if isinstance(output_tree, wc.State): output_tree = output_tree.old_tree() output, errput = main.run_svn (None, 'status', '-v', '-u', wc_dir_name) mytree = tree.build_tree_from_status (output) # Verify actual output against expected output. if (singleton_handler_a or singleton_handler_b): tree.compare_trees (mytree, output_tree, singleton_handler_a, a_baton, singleton_handler_b, b_baton) else: tree.compare_trees (mytree, output_tree)def run_and_verify_diff_summarize(output_tree, error_re_string = None, singleton_handler_a = None, a_baton = None, singleton_handler_b = None, b_baton = None, *args): """Run 'diff --summarize' with the arguments *ARGS. If ERROR_RE_STRING, the command must exit with error, and the error message must match regular expression ERROR_RE_STRING. Else if ERROR_RE_STRING is None, the subcommand output will be verified against OUTPUT_TREE. SINGLETON_HANDLER_A and SINGLETON_HANDLER_B will be passed to tree.compare_trees - see that function's doc string for more details. Returns on success, raises on failure.""" if isinstance(output_tree, wc.State): output_tree = output_tree.old_tree() output, errput = main.run_svn (None, 'diff', '--summarize', '--username', main.wc_author, '--password', main.wc_passwd, *args) if (error_re_string): rm = re.compile(error_re_string) for line in errput: match = rm.search(line) if match: return raise main.SVNUnmatchedError mytree = tree.build_tree_from_diff_summarize (output) # Verify actual output against expected output. try: tree.compare_trees (mytree, output_tree, singleton_handler_a, a_baton, singleton_handler_b, b_baton) except tree.SVNTreeError: display_trees(None, 'DIFF OUTPUT TREE', output_tree, mytree) raise####################################################################### Displaying expected and actual outputdef display_trees(message, label, expected, actual): 'Print two trees, expected and actual.' if message is not None: print message if expected is not None: print 'EXPECTED', label + ':' tree.dump_tree(expected) if actual is not None: print 'ACTUAL', label + ':' tree.dump_tree(actual)def display_lines(message, label, expected, actual, expected_is_regexp=None): """Print MESSAGE, unless it is None, then print EXPECTED (labeled with LABEL) followed by ACTUAL (also labeled with LABEL). Both EXPECTED and ACTUAL may be strings or lists of strings.""" if message is not None: print message if expected is not None: if expected_is_regexp: print 'EXPECTED', label + ' (regexp):' else: print 'EXPECTED', label + ':' map(sys.stdout.write, expected) if expected_is_regexp: map(sys.stdout.write, '\n') if actual is not None: print 'ACTUAL', label + ':' map(sys.stdout.write, actual)def compare_and_display_lines(message, label, expected, actual): 'Compare two sets of output lines, and print them if they differ.' # This catches the None vs. [] cases if expected is None: exp = [] else: exp = expected if actual is None: act = [] else: act = actual if exp != act: display_lines(message, label, expected, actual) raise main.SVNLineUnequaldef match_or_fail(message, label, expected, actual): """Make sure that regexp EXPECTED matches at least one line in list ACTUAL. If no match, then print MESSAGE (if it's not None), followed by EXPECTED and ACTUAL, both labeled with LABEL, and raise SVNLineUnequal.""" for line in actual: if re.match(expected, line): break else: display_lines(message, label, expected, actual, 1) raise main.SVNLineUnequal####################################################################### Other general utilities# This allows a test to *quickly* bootstrap itself.def make_repo_and_wc(sbox, create_wc = True): """Create a fresh repository and checkout a wc from it. The repo and wc directories will both be named TEST_NAME, and repsectively live within the global dirs 'general_repo_dir' and 'general_wc_dir' (variables defined at the top of this test suite.) Returns on success, raises on failure.""" # Store the path of the current repository. main.set_repos_paths(sbox.repo_dir) # Create (or copy afresh) a new repos with a greek tree in it. guarantee_greek_repository(sbox.repo_dir) if create_wc: # Generate the expected output tree. expected_output = main.greek_state.copy() expected_output.wc_dir = sbox.wc_dir expected_output.tweak(status='A ', contents=None) # Generate an expected wc tree. expected_wc = main.greek_state # Do a checkout, and verify the resulting output and disk contents. run_and_verify_checkout(main.current_repo_url, sbox.wc_dir, expected_output, expected_wc) else: # just make sure the parent folder of our working copy is created try: os.mkdir(main.general_wc_dir) except OSError, err: if err.errno != errno.EEXIST: raise# Duplicate a working copy or other dir.def duplicate_dir(wc_name, wc_copy_name): """Copy the working copy WC_NAME to WC_COPY_NAME. Overwrite any existing tree at that location.""" main.safe_rmtree(wc_copy_name) shutil.copytree(wc_name, wc_copy_name)def get_virginal_state(wc_dir, rev): "Return a virginal greek tree state for a WC and repos at revision REV." rev = str(rev) ### maybe switch rev to an integer? # copy the greek tree, shift it to the new wc_dir, insert a root elem, # then tweak all values state = main.greek_state.copy() state.wc_dir = wc_dir state.desc[''] = wc.StateItem() state.tweak(contents=None, status=' ', wc_rev=rev) return state# Cheap administrative directory lockingdef lock_admin_dir(wc_dir): "Lock a SVN administrative directory" path = os.path.join(wc_dir, main.get_admin_name(), 'lock') main.file_append(path, "stop looking!")def enable_revprop_changes(repo_dir): """Enable revprop changes in a repository REPOS_DIR by creating apre-revprop-change hook script and (if appropriate) making it executable.""" hook_path = main.get_pre_revprop_change_hook_path (repo_dir) main.create_python_hook_script (hook_path, 'import sys; sys.exit(0)')def create_failing_post_commit_hook(repo_dir): """Disable commits in a repository REPOS_DIR by creating a post-commit hookscript which always reports errors.""" hook_path = main.get_post_commit_hook_path (repo_dir) main.create_python_hook_script (hook_path, 'import sys; ' 'sys.stderr.write("Post-commit hook failed"); ' 'sys.exit(1)')### End of file.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -