Rev 2533: Clean up some callers that use varargs syntax for run_bzr, but don't in http://sourcefrog.net/bzr/cleanup-runbzr
Martin Pool
mbp at sourcefrog.net
Tue Jun 26 10:35:08 BST 2007
At http://sourcefrog.net/bzr/cleanup-runbzr
------------------------------------------------------------
revno: 2533
revision-id: mbp at sourcefrog.net-20070626093507-6g30srio9kuy2j0e
parent: mbp at sourcefrog.net-20070626084623-5l1ej6s026urooi1
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: cleanup-runbzr
timestamp: Tue 2007-06-26 19:35:07 +1000
message:
Clean up some callers that use varargs syntax for run_bzr, but don't
deprecate it yet because it's too widely used.
Separate out _run_bzr_core from _run_bzr_autosplit.
Remove long-deprecated TestCase.merge helper.
modified:
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/blackbox/test_add.py test_add.py-20060518072250-857e4f86f54a30b2
bzrlib/tests/blackbox/test_selftest.py test_selftest.py-20060123024542-01c5f1bbcb596d78
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2007-06-26 08:46:23 +0000
+++ b/bzrlib/tests/__init__.py 2007-06-26 09:35:07 +0000
@@ -989,6 +989,9 @@
def applyDeprecated(self, deprecation_format, a_callable, *args, **kwargs):
"""Call a deprecated callable without warning the user.
+ Note that this only captures warnings raised by symbol_versioning.warn,
+ not other callers that go direct to the warning module.
+
:param deprecation_format: The deprecation format that the callable
should have been deprecated with. This is the same type as the
parameter to deprecated_method/deprecated_function. If the
@@ -1018,6 +1021,9 @@
as it allows you to simply specify the deprecation format being used
and will ensure that that is issued for the function being called.
+ Note that this only captures warnings raised by symbol_versioning.warn,
+ not other callers that go direct to the warning module.
+
:param expected: a list of the deprecation warnings expected, in order
:param callable: The callable to call
:param args: The positional arguments for the callable
@@ -1243,6 +1249,15 @@
def _run_bzr_autosplit(self, args, retcode, encoding, stdin,
working_dir):
+ """Run bazaar command line, splitting up a string command line."""
+ if isinstance(args, basestring):
+ args = list(shlex.split(args))
+ return self._run_bzr_core(args, retcode=retcode,
+ encoding=encoding, stdin=stdin, working_dir=working_dir,
+ )
+
+ def _run_bzr_core(self, args, retcode, encoding, stdin,
+ working_dir):
if encoding is None:
encoding = bzrlib.user_encoding
stdout = StringIOWrapper()
@@ -1250,12 +1265,6 @@
stdout.encoding = encoding
stderr.encoding = encoding
- if isinstance(args, basestring):
- args = shlex.split(args)
- elif isinstance(args, tuple):
- if len(args) == 1 and isinstance(args[0], basestring):
- args = shlex.split(args[0])
-
self.log('run bzr: %r', args)
# FIXME: don't call into logging here
handler = logging.StreamHandler(stderr)
@@ -1312,7 +1321,7 @@
for hardcoded commands.
3- Several varargs parameters, eg run_bzr("add", "a").
- This is deprecated.
+ This is not recommended for new code.
This should be the main method for tests that want to exercise the
overall behavior of the bzr application (rather than a unit test
@@ -1335,9 +1344,11 @@
if isinstance(args[0], (list, basestring)):
args = args[0]
else:
- warnings.warn("passing varargs to run_bzr is deprecated "
- "from bzr 0.18 onwards; please pass a list or "
- "string instead")
+ ## symbol_versioning.warn(zero_eighteen % "passing varargs to run_bzr",
+ ## DeprecationWarning, stacklevel=2)
+ # not done yet, because too many tests would need to be updated -
+ # but please don't do this in new code. -- mbp 20070626
+ pass
out, err = self._run_bzr_autosplit(args=args,
retcode=retcode,
@@ -1575,23 +1586,6 @@
sys.stderr = real_stderr
sys.stdin = real_stdin
- @symbol_versioning.deprecated_method(symbol_versioning.zero_eleven)
- def merge(self, branch_from, wt_to):
- """A helper for tests to do a ui-less merge.
-
- This should move to the main library when someone has time to integrate
- it in.
- """
- # minimal ui-less merge.
- wt_to.branch.fetch(branch_from)
- base_rev = common_ancestor(branch_from.last_revision(),
- wt_to.branch.last_revision(),
- wt_to.branch.repository)
- merge_inner(wt_to.branch, branch_from.basis_tree(),
- wt_to.branch.repository.revision_tree(base_rev),
- this_tree=wt_to)
- wt_to.add_parent_tree_id(branch_from.last_revision())
-
def reduceLockdirTimeout(self):
"""Reduce the default lock timeout for the duration of the test, so that
if LockContention occurs during a test, it does so quickly.
=== modified file 'bzrlib/tests/blackbox/test_add.py'
--- a/bzrlib/tests/blackbox/test_add.py 2007-06-26 08:02:36 +0000
+++ b/bzrlib/tests/blackbox/test_add.py 2007-06-26 09:35:07 +0000
@@ -64,19 +64,19 @@
self.run_bzr('init')
self.build_tree(['inertiatic/', 'inertiatic/esp'])
self.assertEquals(self.run_bzr_captured(['unknowns'])[0], 'inertiatic\n')
- self.run_bzr('add', 'inertiatic/esp')
+ self.run_bzr('add inertiatic/esp')
self.assertEquals(self.run_bzr_captured(['unknowns'])[0], '')
# Multiple unversioned parents
self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
self.assertEquals(self.run_bzr_captured(['unknowns'])[0], 'veil\n')
- self.run_bzr('add', 'veil/cerpin/taxt')
+ self.run_bzr('add veil/cerpin/taxt')
self.assertEquals(self.run_bzr_captured(['unknowns'])[0], '')
# Check whacky paths work
self.build_tree(['cicatriz/', 'cicatriz/esp'])
self.assertEquals(self.run_bzr_captured(['unknowns'])[0], 'cicatriz\n')
- self.run_bzr('add', 'inertiatic/../cicatriz/esp')
+ self.run_bzr('add inertiatic/../cicatriz/esp')
self.assertEquals(self.run_bzr_captured(['unknowns'])[0], '')
def test_add_in_versioned(self):
@@ -87,9 +87,9 @@
self.run_bzr('init')
self.build_tree(['inertiatic/', 'inertiatic/esp'])
self.assertEquals(self.run_bzr_captured(['unknowns'])[0], 'inertiatic\n')
- self.run_bzr('add', '--no-recurse', 'inertiatic')
+ self.run_bzr('add --no-recurse inertiatic')
self.assertEquals(self.run_bzr_captured(['unknowns'])[0], 'inertiatic/esp\n')
- self.run_bzr('add', 'inertiatic/esp')
+ self.run_bzr('add inertiatic/esp')
self.assertEquals(self.run_bzr_captured(['unknowns'])[0], '')
def test_subdir_add(self):
@@ -107,7 +107,7 @@
eq(sorted(t.unknowns()),
['README', 'src'])
- self.run_bzr('add', 'src')
+ self.run_bzr('add src')
self.build_tree(['src/foo.c'])
@@ -131,7 +131,7 @@
def test_add_missing(self):
"""bzr add foo where foo is missing should error."""
self.make_branch_and_tree('.')
- self.run_bzr('add', 'missing-file', retcode=3)
+ self.run_bzr('add missing-file', retcode=3)
def test_add_from(self):
base_tree = self.make_branch_and_tree('base')
@@ -143,7 +143,7 @@
self.build_tree(['new/a', 'new/b/', 'new/b/c', 'd'])
os.chdir('new')
- out, err = self.run_bzr('add', '--file-ids-from', '../base')
+ out, err = self.run_bzr('add --file-ids-from ../base')
self.assertEqual('', err)
self.assertEqualDiff('added a w/ file id from a\n'
'added b w/ file id from b\n'
@@ -164,7 +164,7 @@
self.build_tree(['new/c', 'new/d'])
os.chdir('new')
- out, err = self.run_bzr('add', '--file-ids-from', '../base/b')
+ out, err = self.run_bzr('add --file-ids-from ../base/b')
self.assertEqual('', err)
self.assertEqualDiff('added c w/ file id from b/c\n'
'added d w/ file id from b/d\n',
@@ -186,10 +186,10 @@
def test_add_control_dir(self):
"""The control dir and its content should be refused."""
self.make_branch_and_tree('.')
- err = self.run_bzr('add', '.bzr', retcode=3)[1]
+ err = self.run_bzr('add .bzr', retcode=3)[1]
self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
- err = self.run_bzr('add', '.bzr/README', retcode=3)[1]
+ err = self.run_bzr('add .bzr/README', retcode=3)[1]
self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
self.build_tree(['.bzr/crescent'])
- err = self.run_bzr('add', '.bzr/crescent', retcode=3)[1]
+ err = self.run_bzr('add .bzr/crescent', retcode=3)[1]
self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
=== modified file 'bzrlib/tests/blackbox/test_selftest.py'
--- a/bzrlib/tests/blackbox/test_selftest.py 2007-06-26 08:02:36 +0000
+++ b/bzrlib/tests/blackbox/test_selftest.py 2007-06-26 09:35:07 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005 Canonical Ltd
+# Copyright (C) 2005, 2007 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -34,6 +34,9 @@
TestUIFactory,
TestSkipped,
)
+from bzrlib.symbol_versioning import (
+ zero_eighteen,
+ )
from bzrlib.tests.blackbox import ExternalBase
@@ -91,7 +94,7 @@
class TestRunBzr(ExternalBase):
- def run_bzr_captured(self, argv, retcode=0, encoding=None, stdin=None,
+ def _run_bzr_core(self, argv, retcode=0, encoding=None, stdin=None,
working_dir=None):
"""Override run_bzr_captured to test how it is invoked by run_bzr.
@@ -101,7 +104,7 @@
Here we only need to test that it is run_bzr passes the right
parameters to run_bzr_captured.
"""
- self.argv = argv
+ self.argv = list(argv)
self.retcode = retcode
self.encoding = encoding
self.stdin = stdin
@@ -110,37 +113,41 @@
def test_args(self):
"""Test that run_bzr passes args correctly to run_bzr_captured"""
+ ## self.callDeprecated(
+ ## ['passing varargs to run_bzr was deprecated in version 0.18.'],
+ ## self.run_bzr,
+ ## 'arg1', 'arg2', 'arg3', retcode=1)
self.run_bzr('arg1', 'arg2', 'arg3', retcode=1)
- self.assertEqual(('arg1', 'arg2', 'arg3'), self.argv)
+ self.assertEqual(['arg1', 'arg2', 'arg3'], self.argv)
def test_encoding(self):
"""Test that run_bzr passes encoding to run_bzr_captured"""
- self.run_bzr('foo', 'bar')
+ self.run_bzr('foo bar')
self.assertEqual(None, self.encoding)
- self.assertEqual(('foo', 'bar'), self.argv)
+ self.assertEqual(['foo', 'bar'], self.argv)
- self.run_bzr('foo', 'bar', encoding='baz')
+ self.run_bzr('foo bar', encoding='baz')
self.assertEqual('baz', self.encoding)
- self.assertEqual(('foo', 'bar'), self.argv)
+ self.assertEqual(['foo', 'bar'], self.argv)
def test_retcode(self):
"""Test that run_bzr passes retcode to run_bzr_captured"""
# Default is retcode == 0
- self.run_bzr('foo', 'bar')
+ self.run_bzr('foo bar')
self.assertEqual(0, self.retcode)
- self.assertEqual(('foo', 'bar'), self.argv)
+ self.assertEqual(['foo', 'bar'], self.argv)
- self.run_bzr('foo', 'bar', retcode=1)
+ self.run_bzr('foo bar', retcode=1)
self.assertEqual(1, self.retcode)
- self.assertEqual(('foo', 'bar'), self.argv)
+ self.assertEqual(['foo', 'bar'], self.argv)
- self.run_bzr('foo', 'bar', retcode=None)
+ self.run_bzr('foo bar', retcode=None)
self.assertEqual(None, self.retcode)
- self.assertEqual(('foo', 'bar'), self.argv)
+ self.assertEqual(['foo', 'bar'], self.argv)
- self.run_bzr('foo', 'bar', retcode=3)
+ self.run_bzr(['foo', 'bar'], retcode=3)
self.assertEqual(3, self.retcode)
- self.assertEqual(('foo', 'bar'), self.argv)
+ self.assertEqual(['foo', 'bar'], self.argv)
def test_stdin(self):
# test that the stdin keyword to run_bzr is passed through to
@@ -148,23 +155,23 @@
# run_bzr_captured in this class, and then calling run_bzr,
# which is a convenience function for run_bzr_captured, so
# should invoke it.
- self.run_bzr('foo', 'bar', stdin='gam')
+ self.run_bzr('foo bar', stdin='gam')
self.assertEqual('gam', self.stdin)
- self.assertEqual(('foo', 'bar'), self.argv)
+ self.assertEqual(['foo', 'bar'], self.argv)
- self.run_bzr('foo', 'bar', stdin='zippy')
+ self.run_bzr('foo bar', stdin='zippy')
self.assertEqual('zippy', self.stdin)
- self.assertEqual(('foo', 'bar'), self.argv)
+ self.assertEqual(['foo', 'bar'], self.argv)
def test_working_dir(self):
"""Test that run_bzr passes working_dir to run_bzr_captured"""
- self.run_bzr('foo', 'bar')
+ self.run_bzr('foo bar')
self.assertEqual(None, self.working_dir)
- self.assertEqual(('foo', 'bar'), self.argv)
+ self.assertEqual(['foo', 'bar'], self.argv)
- self.run_bzr('foo', 'bar', working_dir='baz')
+ self.run_bzr('foo bar', working_dir='baz')
self.assertEqual('baz', self.working_dir)
- self.assertEqual(('foo', 'bar'), self.argv)
+ self.assertEqual(['foo', 'bar'], self.argv)
class TestBenchmarkTests(TestCaseWithTransport):
@@ -176,7 +183,8 @@
old_root = TestCaseWithMemoryTransport.TEST_ROOT
try:
TestCaseWithMemoryTransport.TEST_ROOT = None
- out, err = self.run_bzr('selftest', '--benchmark', 'workingtree_implementations')
+ out, err = self.run_bzr(['selftest', '--benchmark',
+ 'workingtree_implementations'])
finally:
TestCaseWithMemoryTransport.TEST_ROOT = old_root
self.assertContainsRe(out, 'Ran 0 tests.*\n\nOK')
@@ -454,11 +462,11 @@
class TestRunBzrError(ExternalBase):
def test_run_bzr_error(self):
- out, err = self.run_bzr_error(['^$'], 'rocks', retcode=0)
+ out, err = self.run_bzr_error(['^$'], ['rocks'], retcode=0)
self.assertEqual(out, 'It sure does!\n')
out, err = self.run_bzr_error(["bzr: ERROR: foobarbaz is not versioned"],
- 'file-id', 'foobarbaz')
+ ['file-id', 'foobarbaz'])
class TestSelftestCleanOutput(TestCaseInTempDir):
More information about the bazaar-commits
mailing list