Rev 2836: Make run_bzr_decode undeprecated again, but put it in the particular test class in http://sourcefrog.net/bzr/test-traceback
Martin Pool
mbp at sourcefrog.net
Fri Sep 21 07:02:56 BST 2007
At http://sourcefrog.net/bzr/test-traceback
------------------------------------------------------------
revno: 2836
revision-id: mbp at sourcefrog.net-20070921060245-j6a3g6oxdbs1bdjn
parent: mbp at sourcefrog.net-20070918063155-ifdze60wpnslgdbv
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: test-traceback
timestamp: Fri 2007-09-21 16:02:45 +1000
message:
Make run_bzr_decode undeprecated again, but put it in the particular test class
TestNonAscii that needs it. Remove run_bzr(output_encoding) parameter.
run_bzr_decode now takes a specific parameter that says if we expect the
operation to fail with a UnicodeError, and we test for that in particular.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/blackbox/test_non_ascii.py test_non_ascii.py-20060105214030-68010be784a5d854
=== modified file 'NEWS'
--- a/NEWS 2007-09-18 06:31:55 +0000
+++ b/NEWS 2007-09-21 06:02:45 +0000
@@ -58,8 +58,8 @@
inventories without such data, pass working=True to write_inventory.
(Robert Collins)
- * Deprecated ``run_bzr_decode``; use the new ``output_encoding`` parameter to
- ``TestCase.run_bzr`` instead.
+ * Special purpose method ``TestCase.run_bzr_decode`` is moved to the test_non_ascii
+ class that needs it.
(Martin Pool)
* Removed previously deprecated varargs interface to ``TestCase.run_bzr`` and
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2007-09-18 06:31:55 +0000
+++ b/bzrlib/tests/__init__.py 2007-09-21 06:02:45 +0000
@@ -1378,7 +1378,6 @@
:keyword working_dir: The directory to run the command in
:keyword error_regexes: A list of expected error messages. If
specified they must be seen in the error output of the command.
- :keyword output_encoding: Expected encoding of output from bzr.
"""
out, err = self._run_bzr_autosplit(
args=args,
@@ -1389,27 +1388,8 @@
)
for regex in error_regexes:
self.assertContainsRe(err, regex)
- if output_encoding:
- out = out.decode(output_encoding)
- err = err.decode(output_encoding)
return out, err
- @deprecated_method(zero_ninetytwo)
- def run_bzr_decode(self, *args, **kwargs):
- """Run bzr and decode the output into a particular encoding.
-
- Returns a string containing the stdout output from bzr.
-
- This is deprecated in favour of passing output_encoding to run_bzr
- instead.
- """
- if 'encoding' in kwargs:
- encoding = kwargs['encoding']
- else:
- encoding = bzrlib.user_encoding
- return self.run_bzr(output_encoding=encoding,
- *args, **kwargs)[0]
-
def run_bzr_error(self, error_regexes, *args, **kwargs):
"""Run bzr, and check that stderr contains the supplied regexes
=== modified file 'bzrlib/tests/blackbox/test_non_ascii.py'
--- a/bzrlib/tests/blackbox/test_non_ascii.py 2007-06-26 20:32:49 +0000
+++ b/bzrlib/tests/blackbox/test_non_ascii.py 2007-09-21 06:02:45 +0000
@@ -1,5 +1,4 @@
-# Copyright (C) 2006 Canonical Ltd
-# -*- coding: utf-8 -*-
+# Copyright (C) 2006, 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
@@ -48,6 +47,31 @@
bzrlib.user_encoding = self._orig_encoding
super(TestNonAscii, self).tearDown()
+ def run_bzr_decode(self, args, encoding=None, fail=False, retcode=None):
+ """Run bzr and decode the output into a particular encoding.
+
+ Returns a string containing the stdout output from bzr.
+
+ :param fail: If true, the operation is expected to fail with
+ a UnicodeError.
+ """
+ if encoding is None:
+ encoding = bzrlib.user_encoding
+ try:
+ out = self.run_bzr(args, output_encoding=encoding, encoding=encoding,
+ retcode=retcode)[0]
+ return out.decode(encoding)
+ except UnicodeError, e:
+ if not fail:
+ raise
+ else:
+ # This command, run from the regular command line, will give a
+ # traceback to the user. That's not really good for a situation
+ # that can be provoked just by the interaction of their input data
+ # and locale, as some of these are. What would be better?
+ if fail:
+ self.fail("Expected UnicodeError not raised")
+
def create_base(self):
bzr = self.run_bzr
@@ -89,7 +113,7 @@
bzr = self.run_bzr_decode
open(self.info['filename'], 'ab').write('added something\n')
- txt = bzr('status')
+ txt = self.run_bzr_decode('status')
self.assertEqual(u'modified:\n %s\n' % (self.info['filename'],), txt)
txt = bzr('status', encoding='ascii')
@@ -136,7 +160,7 @@
txt = bzr(['relpath', self.info['filename']])
self.assertEqual(self.info['filename'] + '\n', txt)
- bzr(['relpath', self.info['filename']], encoding='ascii', retcode=3)
+ bzr(['relpath', self.info['filename']], encoding='ascii', fail=True)
def test_inventory(self):
bzr = self.run_bzr_decode
@@ -146,7 +170,7 @@
txt.splitlines())
# inventory should fail if unable to encode
- bzr('inventory', encoding='ascii', retcode=3)
+ bzr('inventory', encoding='ascii', fail=True)
# We don't really care about the ids themselves,
# but the command shouldn't fail
@@ -177,7 +201,7 @@
dirname = self.info['directory']
# fname1 already exists
- bzr(['mv', 'a', fname1], retcode=3)
+ bzr(['mv', 'a', fname1], fail=True)
txt = bzr(['mv', 'a', fname2])
self.assertEqual(u'a => %s\n' % fname2, txt)
@@ -285,7 +309,7 @@
txt = bzr('renames')
self.assertEqual(u'a => %s\n' % fname, txt)
- bzr('renames', retcode=3, encoding='ascii')
+ bzr('renames', fail=True, encoding='ascii')
def test_remove(self):
bzr = self.run_bzr_decode
@@ -368,7 +392,7 @@
# Deleted should fail if cannot decode
# Because it is giving the exact paths
# which might be used by a front end
- bzr('deleted', encoding='ascii', retcode=3)
+ bzr('deleted', encoding='ascii', fail=True)
def test_modified(self):
bzr = self.run_bzr_decode
@@ -379,7 +403,7 @@
txt = bzr('modified')
self.assertEqual(fname+'\n', txt)
- bzr('modified', encoding='ascii', retcode=3)
+ bzr('modified', encoding='ascii', fail=True)
def test_added(self):
bzr = self.run_bzr_decode
@@ -391,7 +415,7 @@
txt = bzr('added')
self.assertEqual(fname+'\n', txt)
- bzr('added', encoding='ascii', retcode=3)
+ bzr('added', encoding='ascii', fail=True)
def test_root(self):
bzr = self.run_bzr_decode
@@ -407,7 +431,7 @@
txt = bzr('root')
self.failUnless(txt.endswith(dirname+'\n'))
- txt = bzr('root', encoding='ascii', retcode=3)
+ txt = bzr('root', encoding='ascii', fail=True)
def test_log(self):
bzr = self.run_bzr_decode
@@ -443,7 +467,7 @@
% (fname, fname, fname2))
self.assertEqual(expected_txt, txt)
- bzr(['touching-revisions', fname2], encoding='ascii', retcode=3)
+ bzr(['touching-revisions', fname2], encoding='ascii', fail=True)
def test_ls(self):
bzr = self.run_bzr_decode
@@ -455,8 +479,8 @@
self.assertEqual(sorted(['', 'a', 'b', self.info['filename']]),
sorted(txt.split('\0')))
- txt = bzr('ls', encoding='ascii', retcode=3)
- txt = bzr('ls --null', encoding='ascii', retcode=3)
+ txt = bzr('ls', encoding='ascii', fail=True)
+ txt = bzr('ls --null', encoding='ascii', fail=True)
def test_unknowns(self):
bzr = self.run_bzr_decode
@@ -469,7 +493,7 @@
txt = bzr('unknowns')
self.assertEqual(u'"%s"\n' % (fname,), txt)
- bzr('unknowns', encoding='ascii', retcode=3)
+ bzr('unknowns', encoding='ascii', fail=True)
def test_ignore(self):
bzr = self.run_bzr_decode
More information about the bazaar-commits
mailing list