[merge][#135241] better handling of internal errors in blackbox tests

Alexander Belchenko bialix at ukr.net
Tue Sep 25 21:53:46 BST 2007


Alexander Belchenko has voted tweak.
Status is now: Conditionally approved
Comment:
# return codes from the bzr program
EXIT_ERROR = 3
EXIT_INTERNAL_ERROR = 4

^-- Can you list all return codes, please? IMO, this is useful as a sort 
of self-documentation.

=== modified file 'bzrlib/tests/blackbox/test_non_ascii.py'
--- bzrlib/tests/blackbox/test_non_ascii.py     2007-06-26 20:32:49 
+0000
+++ bzrlib/tests/blackbox/test_non_ascii.py     2007-09-21 06:02:45 
+0000
@@ -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

^-- please, junk this line, it's not used in create_base() anymore.

@@ -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')

^-- IMO here variable bzr also should be junked and self.run_bzr_decode 
used instead, because you started this change in the same methods 2 
lines earlier.


For details, see: 
http://bundlebuggy.aaronbentley.com/request/%3Ce01316480709232354t5c649e17h17bb3e9c4e273cd1%40mail.gmail.com%3E



More information about the bazaar mailing list