Rev 5985: (vila) Tighten BZR_LOG file handling in tests (Vincent Ladeuil) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Sat Jun 18 09:53:58 UTC 2011


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5985 [merge]
revision-id: pqm at pqm.ubuntu.com-20110618095356-7wt06aywv34uysp9
parent: pqm at pqm.ubuntu.com-20110616233147-l57xwon6dzb6waze
parent: v.ladeuil+lp at free.fr-20110617150725-0nzsbkgnjzc1gzqf
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sat 2011-06-18 09:53:56 +0000
message:
  (vila) Tighten BZR_LOG file handling in tests (Vincent Ladeuil)
modified:
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/blackbox/test_exceptions.py test_exceptions.py-20060604211237-yi2cxg0ose3xk4id-1
  bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
  doc/en/release-notes/bzr-2.4.txt bzr2.4.txt-20110114053217-k7ym9jfz243fddjm-1
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2011-06-16 19:00:24 +0000
+++ b/bzrlib/tests/__init__.py	2011-06-17 15:01:40 +0000
@@ -142,7 +142,10 @@
     'BZREMAIL': None, # may still be present in the environment
     'EMAIL': 'jrandom at example.com', # set EMAIL as bzr does not guess
     'BZR_PROGRESS_BAR': None,
-    'BZR_LOG': None,
+    # This should trap leaks to ~/.bzr.log. This occurs when tests use TestCase
+    # as a base class instead of TestCaseInTempDir. Tests inheriting from
+    # TestCase should not use disk resources, BZR_LOG is one.
+    'BZR_LOG': '/you-should-use-TestCaseInTempDir-if-you-need-a-log-file',
     'BZR_PLUGIN_PATH': None,
     'BZR_DISABLE_PLUGINS': None,
     'BZR_PLUGINS_AT': None,
@@ -928,7 +931,7 @@
 
     The method is really a factory and users are expected to use it as such.
     """
-    
+
     kwargs['setUp'] = isolated_doctest_setUp
     kwargs['tearDown'] = isolated_doctest_tearDown
     return doctest.DocTestSuite(*args, **kwargs)
@@ -1704,7 +1707,7 @@
     def _finishLogFile(self):
         """Finished with the log file.
 
-        Close the file and delete it, unless setKeepLogfile was called.
+        Close the file and delete it.
         """
         if trace._trace_file:
             # flush the log file, to get all content
@@ -2325,20 +2328,21 @@
 class TestCaseWithMemoryTransport(TestCase):
     """Common test class for tests that do not need disk resources.
 
-    Tests that need disk resources should derive from TestCaseWithTransport.
+    Tests that need disk resources should derive from TestCaseInTempDir
+    orTestCaseWithTransport.
 
     TestCaseWithMemoryTransport sets the TEST_ROOT variable for all bzr tests.
 
-    For TestCaseWithMemoryTransport the test_home_dir is set to the name of
+    For TestCaseWithMemoryTransport the ``test_home_dir`` is set to the name of
     a directory which does not exist. This serves to help ensure test isolation
-    is preserved. test_dir is set to the TEST_ROOT, as is cwd, because they
-    must exist. However, TestCaseWithMemoryTransport does not offer local
-    file defaults for the transport in tests, nor does it obey the command line
+    is preserved. ``test_dir`` is set to the TEST_ROOT, as is cwd, because they
+    must exist. However, TestCaseWithMemoryTransport does not offer local file
+    defaults for the transport in tests, nor does it obey the command line
     override, so tests that accidentally write to the common directory should
     be rare.
 
-    :cvar TEST_ROOT: Directory containing all temporary directories, plus
-    a .bzr directory that stops us ascending higher into the filesystem.
+    :cvar TEST_ROOT: Directory containing all temporary directories, plus a
+        ``.bzr`` directory that stops us ascending higher into the filesystem.
     """
 
     TEST_ROOT = None
@@ -2668,6 +2672,12 @@
 
     OVERRIDE_PYTHON = 'python'
 
+    def setUp(self):
+        super(TestCaseInTempDir, self).setUp()
+        # Remove the protection set in isolated_environ, we have a proper
+        # access to disk resources now.
+        self.overrideEnv('BZR_LOG', None)
+
     def check_file_contents(self, filename, expect):
         self.log("check contents of file %s" % filename)
         f = file(filename)

=== modified file 'bzrlib/tests/blackbox/test_exceptions.py'
--- a/bzrlib/tests/blackbox/test_exceptions.py	2011-06-02 09:21:46 +0000
+++ b/bzrlib/tests/blackbox/test_exceptions.py	2011-06-17 13:53:59 +0000
@@ -30,10 +30,8 @@
     )
 from bzrlib.repofmt.groupcompress_repo import RepositoryFormat2a
 
-from bzrlib.tests import TestCase
-
-
-class TestExceptionReporting(TestCase):
+
+class TestExceptionReporting(tests.TestCaseInTempDir):
 
     def test_exception_exitcode(self):
         # we must use a subprocess, because the normal in-memory mechanism
@@ -63,7 +61,7 @@
         self.assertEquals(out, "")
 
 
-class TestOptParseBugHandling(TestCase):
+class TestOptParseBugHandling(tests.TestCase):
     "Test that we handle http://bugs.python.org/issue2931"
 
     def test_nonascii_optparse(self):

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2011-06-16 21:23:44 +0000
+++ b/bzrlib/tests/test_selftest.py	2011-06-17 13:59:23 +0000
@@ -2506,17 +2506,24 @@
 
 
 class TestStartBzrSubProcess(tests.TestCase):
+    """Stub test start_bzr_subprocess."""
 
-    def check_popen_state(self):
-        """Replace to make assertions when popen is called."""
+    def _subprocess_log_cleanup(self):
+        """Inhibits the base version as we don't produce a log file."""
 
     def _popen(self, *args, **kwargs):
-        """Record the command that is run, so that we can ensure it is correct"""
+        """Override the base version to record the command that is run.
+
+        From there we can ensure it is correct without spawning a real process.
+        """
         self.check_popen_state()
         self._popen_args = args
         self._popen_kwargs = kwargs
         raise _DontSpawnProcess()
 
+    def check_popen_state(self):
+        """Replace to make assertions when popen is called."""
+
     def test_run_bzr_subprocess_no_plugins(self):
         self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [])
         command = self._popen_args[0]
@@ -2526,7 +2533,7 @@
 
     def test_allow_plugins(self):
         self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
-            allow_plugins=True)
+                          allow_plugins=True)
         command = self._popen_args[0]
         self.assertEqual([], command[2:])
 
@@ -2537,7 +2544,7 @@
             self.assertEqual('set variable', os.environ['EXISTANT_ENV_VAR'])
         self.check_popen_state = check_environment
         self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
-            env_changes={'EXISTANT_ENV_VAR':'set variable'})
+                          env_changes={'EXISTANT_ENV_VAR':'set variable'})
         # not set in theparent
         self.assertFalse('EXISTANT_ENV_VAR' in os.environ)
 
@@ -2549,7 +2556,7 @@
         os.environ['EXISTANT_ENV_VAR'] = 'set variable'
         self.check_popen_state = check_environment
         self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
-            env_changes={'EXISTANT_ENV_VAR':None})
+                          env_changes={'EXISTANT_ENV_VAR':None})
         # Still set in parent
         self.assertEqual('set variable', os.environ['EXISTANT_ENV_VAR'])
         del os.environ['EXISTANT_ENV_VAR']
@@ -2560,7 +2567,7 @@
             self.assertFalse('NON_EXISTANT_ENV_VAR' in os.environ)
         self.check_popen_state = check_environment
         self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
-            env_changes={'NON_EXISTANT_ENV_VAR':None})
+                          env_changes={'NON_EXISTANT_ENV_VAR':None})
 
     def test_working_dir(self):
         """Test that we can specify the working dir for the child"""
@@ -2569,18 +2576,12 @@
         chdirs = []
         def chdir(path):
             chdirs.append(path)
-        os.chdir = chdir
-        try:
-            def getcwd():
-                return 'current'
-            osutils.getcwd = getcwd
-            try:
-                self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
-                    working_dir='foo')
-            finally:
-                osutils.getcwd = orig_getcwd
-        finally:
-            os.chdir = orig_chdir
+        self.overrideAttr(os, 'chdir', chdir)
+        def getcwd():
+            return 'current'
+        self.overrideAttr(osutils, 'getcwd', getcwd)
+        self.assertRaises(_DontSpawnProcess, self.start_bzr_subprocess, [],
+                          working_dir='foo')
         self.assertEqual(['foo', 'current'], chdirs)
 
     def test_get_bzr_path_with_cwd_bzrlib(self):

=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- a/doc/en/release-notes/bzr-2.4.txt	2011-06-16 21:28:07 +0000
+++ b/doc/en/release-notes/bzr-2.4.txt	2011-06-17 15:07:25 +0000
@@ -56,6 +56,9 @@
    suite.  This can include new facilities for writing tests, fixes to 
    spurious test failures and changes to the way things should be tested.
 
+* Fix test failures when running as a homeless user (debian buildd). Tests
+  leaking into ``${HOME}/.bzr.log`` should be detected properly now.
+  (Vincent Ladeuil, #798698)
 
 bzr 2.4b4
 #########




More information about the bazaar-commits mailing list