~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: John Arbash Meinel
  • Date: 2006-10-16 01:50:48 UTC
  • mfrom: (2078 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2080.
  • Revision ID: john@arbash-meinel.com-20061016015048-0f22df07e38093da
[merge] bzr.dev 2078

Show diffs side-by-side

added added

removed removed

Lines of Context:
927
927
            The values must be strings. The change will only occur in the
928
928
            child, so you don't need to fix the environment after running.
929
929
        :param universal_newlines: Convert CRLF => LF
 
930
        :param allow_plugins: By default the subprocess is run with
 
931
            --no-plugins to ensure test reproducibility. Also, it is possible
 
932
            for system-wide plugins to create unexpected output on stderr,
 
933
            which can cause unnecessary test failures.
930
934
        """
931
935
        env_changes = kwargs.get('env_changes', {})
932
936
        working_dir = kwargs.get('working_dir', None)
 
937
        allow_plugins = kwargs.get('allow_plugins', False)
933
938
        process = self.start_bzr_subprocess(args, env_changes=env_changes,
934
 
                                            working_dir=working_dir)
 
939
                                            working_dir=working_dir,
 
940
                                            allow_plugins=allow_plugins)
935
941
        # We distinguish between retcode=None and retcode not passed.
936
942
        supplied_retcode = kwargs.get('retcode', 0)
937
943
        return self.finish_bzr_subprocess(process, retcode=supplied_retcode,
940
946
 
941
947
    def start_bzr_subprocess(self, process_args, env_changes=None,
942
948
                             skip_if_plan_to_signal=False,
943
 
                             working_dir=None):
 
949
                             working_dir=None,
 
950
                             allow_plugins=False):
944
951
        """Start bzr in a subprocess for testing.
945
952
 
946
953
        This starts a new Python interpreter and runs bzr in there.
957
964
            child, so you don't need to fix the environment after running.
958
965
        :param skip_if_plan_to_signal: raise TestSkipped when true and os.kill
959
966
            is not available.
 
967
        :param allow_plugins: If False (default) pass --no-plugins to bzr.
960
968
 
961
969
        :returns: Popen object for the started process.
962
970
        """
988
996
            # so we will avoid using it on all platforms, just to
989
997
            # make sure the code path is used, and we don't break on win32
990
998
            cleanup_environment()
991
 
            process = Popen([sys.executable, bzr_path] + list(process_args),
992
 
                             stdin=PIPE, stdout=PIPE, stderr=PIPE)
 
999
            command = [sys.executable, bzr_path]
 
1000
            if not allow_plugins:
 
1001
                command.append('--no-plugins')
 
1002
            command.extend(process_args)
 
1003
            process = self._popen(command, stdin=PIPE, stdout=PIPE, stderr=PIPE)
993
1004
        finally:
994
1005
            restore_environment()
995
1006
            if cwd is not None:
997
1008
 
998
1009
        return process
999
1010
 
 
1011
    def _popen(self, *args, **kwargs):
 
1012
        """Place a call to Popen.
 
1013
 
 
1014
        Allows tests to override this method to intercept the calls made to
 
1015
        Popen for introspection.
 
1016
        """
 
1017
        return Popen(*args, **kwargs)
 
1018
 
1000
1019
    def get_bzr_path(self):
1001
1020
        """Return the path of the 'bzr' executable for this test suite."""
1002
1021
        bzr_path = os.path.dirname(os.path.dirname(bzrlib.__file__))+'/bzr'
1289
1308
        made_control = self.make_bzrdir(relpath, format=format)
1290
1309
        return made_control.create_repository(shared=shared)
1291
1310
 
1292
 
    def make_branch_and_memory_tree(self, relpath):
 
1311
    def make_branch_and_memory_tree(self, relpath, format=None):
1293
1312
        """Create a branch on the default transport and a MemoryTree for it."""
1294
 
        b = self.make_branch(relpath)
 
1313
        b = self.make_branch(relpath, format=format)
1295
1314
        return memorytree.MemoryTree.create_on_branch(b)
1296
1315
 
1297
1316
    def overrideEnvironmentForTesting(self):
1633
1652
                   'bzrlib.tests.test_plugins',
1634
1653
                   'bzrlib.tests.test_progress',
1635
1654
                   'bzrlib.tests.test_reconcile',
 
1655
                   'bzrlib.tests.test_registry',
1636
1656
                   'bzrlib.tests.test_repository',
1637
1657
                   'bzrlib.tests.test_revert',
1638
1658
                   'bzrlib.tests.test_revision',