📄 externals_tests.py
字号:
#!/usr/bin/env python## module_tests.py: testing modules / external sources.## Subversion is a tool for revision control. # See http://subversion.tigris.org for more information.# # ====================================================================# Copyright (c) 2000-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 shutil, string, sys, re, osimport warnings# Our testing moduleimport svntestfrom svntest import SVNAnyOutput# (abbreviation)Skip = svntest.testcase.SkipXFail = svntest.testcase.XFailItem = svntest.wc.StateItem####################################################################### Tests## Each test must return on success or raise on failure.#----------------------------------------------------------------------### todo: it's inefficient to keep calling externals_test_setup() for### every test. It's slow. But it's very safe -- we're guaranteed to### have a clean repository, built from the latest Subversion, with### the svn:externals properties preset in a known way. Right now I### can't think of any other way to achieve that guarantee, so the### result is that each individual test is slow.def externals_test_setup(sbox): """Set up a repository in which some directories have the externals property, and set up another repository, referred to by some of those externals. Both repositories contain greek trees with five revisions worth of random changes, then in the sixth revision the first repository -- and only the first -- has some externals properties set. ### Later, test putting externals on the second repository. ### The arrangement of the externals in the first repository is: /A/C/ ==> exdir_G <scheme>:///<other_repos>/A/D/G exdir_H -r 1 <scheme>:///<other_repos>/A/D/H /A/D/ ==> exdir_A <scheme>:///<other_repos>/A exdir_A/G <scheme>:///<other_repos>/A/D/G exdir_A/H -r 3 <scheme>:///<other_repos>/A/D/H x/y/z/blah <scheme>:///<other_repos>/A/B NOTE: Before calling this, use externals_test_cleanup(SBOX) to remove a previous incarnation of the other repository. """ # The test itself will create a working copy sbox.build(create_wc = False) svntest.main.safe_rmtree(sbox.wc_dir) wc_init_dir = sbox.add_wc_path('init') # just for setting up props repo_dir = sbox.repo_dir repo_url = sbox.repo_url other_repo_dir, other_repo_url = sbox.add_repo_path('other') # These files will get changed in revisions 2 through 5. mu_path = os.path.join(wc_init_dir, "A/mu") pi_path = os.path.join(wc_init_dir, "A/D/G/pi") lambda_path = os.path.join(wc_init_dir, "A/B/lambda") omega_path = os.path.join(wc_init_dir, "A/D/H/omega") # These are the directories on which `svn:externals' will be set, in # revision 6 on the first repo. C_path = os.path.join(wc_init_dir, "A/C") D_path = os.path.join(wc_init_dir, "A/D") # Create a working copy. svntest.actions.run_and_verify_svn("", None, [], 'checkout', '--username', svntest.main.wc_author, '--password', svntest.main.wc_passwd, repo_url, wc_init_dir) # Make revisions 2 through 5, but don't bother with pre- and # post-commit status checks. svntest.main.file_append(mu_path, "Added to mu in revision 2.\n") svntest.actions.run_and_verify_svn("", None, [], 'ci', '-m', 'log msg', '--quiet', wc_init_dir) svntest.main.file_append(pi_path, "Added to pi in revision 3.\n") svntest.actions.run_and_verify_svn("", None, [], 'ci', '-m', 'log msg', '--quiet', wc_init_dir) svntest.main.file_append(lambda_path, "Added to lambda in revision 4.\n") svntest.actions.run_and_verify_svn("", None, [], 'ci', '-m', 'log msg', '--quiet', wc_init_dir) svntest.main.file_append(omega_path, "Added to omega in revision 5.\n") svntest.actions.run_and_verify_svn("", None, [], 'ci', '-m', 'log msg', '--quiet', wc_init_dir) # Get the whole working copy to revision 5. svntest.actions.run_and_verify_svn("", None, [], 'up', wc_init_dir) # Now copy the initial repository to create the "other" repository, # the one to which the first repository's `svn:externals' properties # will refer. After this, both repositories have five revisions # of random stuff, with no svn:externals props set yet. svntest.main.copy_repos(repo_dir, other_repo_dir, 5) # Set up the externals properties on A/B/ and A/D/. externals_desc = \ "exdir_G " + other_repo_url + "/A/D/G" + "\n" + \ "exdir_H -r 1 " + other_repo_url + "/A/D/H" + "\n" tmp_f = os.tempnam(wc_init_dir, 'tmp') svntest.main.file_append(tmp_f, externals_desc) svntest.actions.run_and_verify_svn("", None, [], 'pset', '-F', tmp_f, 'svn:externals', C_path) os.remove(tmp_f) externals_desc = \ "exdir_A " + other_repo_url + "/A" + \ "\n" + \ "exdir_A/G/ " + other_repo_url + "/A/D/G/" + \ "\n" + \ "exdir_A/H -r 1 " + other_repo_url + "/A/D/H" + \ "\n" + \ "x/y/z/blah " + other_repo_url + "/A/B" + \ "\n" svntest.main.file_append(tmp_f, externals_desc) svntest.actions.run_and_verify_svn("", None, [], 'pset', '-F', tmp_f, 'svn:externals', D_path) os.remove(tmp_f) # Commit the property changes. expected_output = svntest.wc.State(wc_init_dir, { 'A/C' : Item(verb='Sending'), 'A/D' : Item(verb='Sending'), }) expected_status = svntest.actions.get_virginal_state(wc_init_dir, 5) expected_status.tweak('A/C', 'A/D', wc_rev=6, status=' ') svntest.actions.run_and_verify_commit(wc_init_dir, expected_output, expected_status, None, None, None, None, None, wc_init_dir)def change_external(path, new_val): """Change the value of the externals property on PATH to NEW_VAL, and commit the change.""" tmp_f = os.tempnam(svntest.main.temp_dir, 'tmp') svntest.main.file_append(tmp_f, new_val) svntest.actions.run_and_verify_svn("", None, [], 'pset', '-F', tmp_f, 'svn:externals', path) svntest.actions.run_and_verify_svn("", None, [], 'ci', '-m', 'log msg', '--quiet', path) os.remove(tmp_f)#----------------------------------------------------------------------### todo: It would be great if everything used the new wc.py system to### check output/status. In fact, it would be great to do more output### and status checking period! But must first see how well the### output checkers deal with multiple summary lines. With external### modules, you can get the first "Updated to revision X" line, and### then there will be more "Updated to..." and "Checked out..." lines### following it, one line for each new or changed external.#----------------------------------------------------------------------def checkout_with_externals(sbox): "test checkouts with externals" externals_test_setup(sbox) wc_dir = sbox.wc_dir repo_dir = sbox.repo_dir repo_url = sbox.repo_url # Create a working copy. svntest.actions.run_and_verify_svn("", None, [], 'checkout', '--username', svntest.main.wc_author, '--password', svntest.main.wc_passwd, repo_url, wc_dir) # Probe the working copy a bit, see if it's as expected. exdir_G_path = os.path.join(wc_dir, "A", "C", "exdir_G") exdir_G_pi_path = os.path.join(exdir_G_path, "pi") exdir_H_path = os.path.join(wc_dir, "A", "C", "exdir_H") exdir_H_omega_path = os.path.join(exdir_H_path, "omega") x_path = os.path.join(wc_dir, "A", "D", "x") y_path = os.path.join(x_path, "y") z_path = os.path.join(y_path, "z") blah_path = os.path.join(z_path, "blah") alpha_path = os.path.join(blah_path, "E", "alpha") beta_path = os.path.join(blah_path, "E", "beta") if (not os.path.exists(exdir_G_path)): raise svntest.Failure("Probing for " + exdir_G_path + " failed.") if (not os.path.exists(exdir_G_pi_path)): raise svntest.Failure("Probing for " + exdir_G_pi_path + " failed.") if (not os.path.exists(exdir_H_path)): raise svntest.Failure("Probing for " + exdir_H_path + " failed.") if (not os.path.exists(exdir_H_omega_path)): raise svntest.Failure("Probing for " + exdir_H_omega_path + " failed.") if (not os.path.exists(x_path)): raise svntest.Failure("Probing for " + x_path + " failed.") if (not os.path.exists(y_path)): raise svntest.Failure("Probing for " + y_path + " failed.") if (not os.path.exists(z_path)): raise svntest.Failure("Probing for " + z_path + " failed.") if (not os.path.exists(z_path)): raise svntest.Failure("Probing for " + z_path + " failed.") if (not os.path.exists(alpha_path)): raise svntest.Failure("Probing for " + alpha_path + " failed.") if (not os.path.exists(beta_path)): raise svntest.Failure("Probing for " + beta_path + " failed.") # Pick a file at random, make sure it has the expected contents. fp = open(exdir_H_omega_path, 'r') lines = fp.readlines() if not ((len(lines) == 1) and (lines[0] == "This is the file 'omega'.\n")): raise svntest.Failure("Unexpected contents for rev 1 of " + exdir_H_omega_path)#----------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -