[patch] fix testsuite under 'python -O'

Martin Pool mbp at canonical.com
Tue Oct 31 05:25:36 GMT 2006


This fixes some cases where we depend on side effects of 'assert', or
test that it raises AssertionError.

As a followon it might be good to change run_bzr_subprocess to pass -O
if __debug__ is set.

(Incidentally I occasionally see a 'bad file descriptor' when the test
suite's simple http server thread is trying to listen on a socket.  I'm
not sure why - the code seems correct.  Has anyone else seen it?)

-- 
Martin
-------------- next part --------------
=== modified file 'bzrlib/builtins.py'
--- bzrlib/builtins.py	2006-10-18 12:54:37 +0000
+++ bzrlib/builtins.py	2006-10-31 05:23:05 +0000
@@ -2412,9 +2412,12 @@
 
 class cmd_assert_fail(Command):
     """Test reporting of assertion failures"""
+    # intended just for use in testing
+
     hidden = True
+
     def run(self):
-        assert False, "always fails"
+        raise AssertionError("always fails")
 
 
 class cmd_help(Command):

=== modified file 'bzrlib/bzrdir.py'
--- bzrlib/bzrdir.py	2006-10-12 03:19:14 +0000
+++ bzrlib/bzrdir.py	2006-10-31 03:52:58 +0000
@@ -1174,8 +1174,11 @@
         _found is a private parameter, do not use it.
         """
         if not _found:
-            assert isinstance(BzrDirFormat.find_format(transport),
-                              self.__class__)
+            found_format = BzrDirFormat.find_format(transport)
+            if not isinstance(found_format, self.__class__):
+                raise AssertionError("%s was asked to open %s, but it seems to need "
+                        "format %s" 
+                        % (self, transport, found_format))
         return self._open(transport)
 
     def _open(self, transport):

=== modified file 'bzrlib/errors.py'
--- bzrlib/errors.py	2006-10-16 04:50:19 +0000
+++ bzrlib/errors.py	2006-10-31 03:52:59 +0000
@@ -208,6 +208,12 @@
         self.base = base
 
 
+class WorkingTreeAlreadyPopulated(BzrNewError):
+    """Working tree already populated in %(base)s"""
+
+    is_user_error = False
+
+
 class NotBuilding(BzrNewError):
     """Not currently building a tree."""
 

=== modified file 'bzrlib/osutils.py'
--- bzrlib/osutils.py	2006-10-23 22:43:31 +0000
+++ bzrlib/osutils.py	2006-10-31 05:23:05 +0000
@@ -1,6 +1,4 @@
-# Bazaar -- distributed version control
-#
-# Copyright (C) 2005 Canonical Ltd
+# Copyright (C) 2005, 2006 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

=== modified file 'bzrlib/tests/test_osutils.py'
--- bzrlib/tests/test_osutils.py	2006-10-16 01:25:46 +0000
+++ bzrlib/tests/test_osutils.py	2006-10-31 05:23:05 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005 Canonical Ltd
+# Copyright (C) 2005, 2006 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
@@ -504,14 +504,14 @@
     def test_copy_basic_tree(self):
         self.build_tree(['source/', 'source/a', 'source/b/', 'source/b/c'])
         osutils.copy_tree('source', 'target')
-        self.assertEqual(['a', 'b'], os.listdir('target'))
+        self.assertEqual(['a', 'b'], sorted(os.listdir('target')))
         self.assertEqual(['c'], os.listdir('target/b'))
 
     def test_copy_tree_target_exists(self):
         self.build_tree(['source/', 'source/a', 'source/b/', 'source/b/c',
                          'target/'])
         osutils.copy_tree('source', 'target')
-        self.assertEqual(['a', 'b'], os.listdir('target'))
+        self.assertEqual(['a', 'b'], sorted(os.listdir('target')))
         self.assertEqual(['c'], os.listdir('target/b'))
 
     def test_copy_tree_symlinks(self):

=== modified file 'bzrlib/tests/test_transform.py'
--- bzrlib/tests/test_transform.py	2006-09-27 02:28:44 +0000
+++ bzrlib/tests/test_transform.py	2006-10-31 03:53:08 +0000
@@ -19,6 +19,7 @@
 import sys
 
 from bzrlib import (
+    errors,
     tests,
     urlutils,
     )
@@ -910,8 +911,8 @@
         target = self.make_branch_and_tree('target')
         self.build_tree(['target/name'])
         target.add('name')
-        self.assertRaises(AssertionError, build_tree, source.basis_tree(),
-                          target)
+        self.assertRaises(errors.WorkingTreeAlreadyPopulated, 
+            build_tree, source.basis_tree(), target)
 
 
 class MockTransform(object):

=== modified file 'bzrlib/transform.py'
--- bzrlib/transform.py	2006-09-28 01:53:23 +0000
+++ bzrlib/transform.py	2006-10-31 03:53:02 +0000
@@ -960,7 +960,8 @@
       it is silently replaced.
     - Otherwise, conflict resolution will move the old file to 'oldname.moved'.
     """
-    assert 2 > len(wt.inventory)
+    if len(wt.inventory) > 1:  # more than just a root
+        raise errors.WorkingTreeAlreadyPopulated(base=wt.basedir)
     file_trans_id = {}
     top_pb = bzrlib.ui.ui_factory.nested_progress_bar()
     pp = ProgressPhase("Build phase", 2, top_pb)



More information about the bazaar mailing list