/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Vincent Ladeuil
  • Date: 2007-10-04 17:10:53 UTC
  • mfrom: (2875.1.2 147986)
  • mto: This revision was merged to the branch mainline in revision 2887.
  • Revision ID: v.ladeuil+lp@free.fr-20071004171053-rxtb0dwigygsany3
Fix #147986 by monitoring a safety .bzr directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
161
161
class ExtendedTestResult(unittest._TextTestResult):
162
162
    """Accepts, reports and accumulates the results of running tests.
163
163
 
164
 
    Compared to this unittest version this class adds support for
 
164
    Compared to the unittest version this class adds support for
165
165
    profiling, benchmarking, stopping as soon as a test fails,  and
166
166
    skipping tests.  There are further-specialized subclasses for
167
167
    different types of display.
342
342
        except KeyboardInterrupt:
343
343
            raise
344
344
        except:
345
 
            self.addError(test, test.__exc_info())
 
345
            self.addError(test, test._exc_info())
346
346
        else:
347
347
            # seems best to treat this as success from point-of-view of unittest
348
348
            # -- it actually does nothing so it barely matters :)
1835
1835
        base = self.get_vfs_only_server().get_url()
1836
1836
        return self._adjust_url(base, relpath)
1837
1837
 
 
1838
    def _create_safety_net(self):
 
1839
        """Make a fake bzr directory.
 
1840
 
 
1841
        This prevents any tests propagating up onto the TEST_ROOT directory's
 
1842
        real branch.
 
1843
        """
 
1844
        root = TestCaseWithMemoryTransport.TEST_ROOT
 
1845
        bzrdir.BzrDir.create_standalone_workingtree(root)
 
1846
 
 
1847
    def _check_safety_net(self):
 
1848
        """Check that the safety .bzr directory have not been touched.
 
1849
 
 
1850
        _make_test_root have created a .bzr directory to prevent tests from
 
1851
        propagating. This method ensures than a test did not leaked.
 
1852
        """
 
1853
        root = TestCaseWithMemoryTransport.TEST_ROOT
 
1854
        wt = workingtree.WorkingTree.open(root)
 
1855
        last_rev = wt.last_revision()
 
1856
        if last_rev != 'null:':
 
1857
            # The current test have modified the /bzr directory, we need to
 
1858
            # recreate a new one or all the followng tests will fail.
 
1859
            # If you need to inspect its content uncomment the following line
 
1860
            # import pdb; pdb.set_trace()
 
1861
            _rmtree_temp_dir(root + '/.bzr')
 
1862
            self._create_safety_net()
 
1863
            raise AssertionError('%s/.bzr should not be modified' % root)
 
1864
 
1838
1865
    def _make_test_root(self):
1839
 
        if TestCaseWithMemoryTransport.TEST_ROOT is not None:
1840
 
            return
1841
 
        root = osutils.mkdtemp(prefix='testbzr-', suffix='.tmp')
1842
 
        TestCaseWithMemoryTransport.TEST_ROOT = root
1843
 
        
1844
 
        # make a fake bzr directory there to prevent any tests propagating
1845
 
        # up onto the source directory's real branch
1846
 
        bzrdir.BzrDir.create_standalone_workingtree(root)
1847
 
 
1848
 
        # The same directory is used by all tests, and we're not specifically
1849
 
        # told when all tests are finished.  This will do.
1850
 
        atexit.register(_rmtree_temp_dir, root)
 
1866
        if TestCaseWithMemoryTransport.TEST_ROOT is None:
 
1867
            root = osutils.mkdtemp(prefix='testbzr-', suffix='.tmp')
 
1868
            TestCaseWithMemoryTransport.TEST_ROOT = root
 
1869
 
 
1870
            self._create_safety_net()
 
1871
 
 
1872
            # The same directory is used by all tests, and we're not
 
1873
            # specifically told when all tests are finished.  This will do.
 
1874
            atexit.register(_rmtree_temp_dir, root)
 
1875
 
 
1876
        self.addCleanup(self._check_safety_net)
1851
1877
 
1852
1878
    def makeAndChdirToTestDir(self):
1853
1879
        """Create a temporary directories for this one test.