/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: John Arbash Meinel
  • Date: 2011-01-10 22:20:12 UTC
  • mfrom: (5582 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5599.
  • Revision ID: john@arbash-meinel.com-20110110222012-mtcqudkvmzwiufuc
Merge in the bzr.dev 5582

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
60
60
        % (testtools.__file__, _testtools_version))
61
61
from testtools import content
62
62
 
 
63
import bzrlib
63
64
from bzrlib import (
64
65
    branchbuilder,
65
66
    bzrdir,
66
67
    chk_map,
 
68
    commands as _mod_commands,
67
69
    config,
68
70
    debug,
69
71
    errors,
70
72
    hooks,
71
73
    lock as _mod_lock,
 
74
    lockdir,
72
75
    memorytree,
73
76
    osutils,
 
77
    plugin as _mod_plugin,
74
78
    pyutils,
75
79
    ui,
76
80
    urlutils,
77
81
    registry,
 
82
    symbol_versioning,
 
83
    trace,
78
84
    transport as _mod_transport,
79
85
    workingtree,
80
86
    )
81
 
import bzrlib.branch
82
 
import bzrlib.commands
83
 
import bzrlib.timestamp
84
 
import bzrlib.export
85
 
import bzrlib.inventory
86
 
import bzrlib.iterablefile
87
 
import bzrlib.lockdir
88
87
try:
89
88
    import bzrlib.lsprof
90
89
except ImportError:
91
90
    # lsprof not available
92
91
    pass
93
 
import bzrlib.merge3
94
 
import bzrlib.plugin
95
92
from bzrlib.smart import client, request
96
 
import bzrlib.store
97
 
from bzrlib import symbol_versioning
98
 
from bzrlib.symbol_versioning import (
99
 
    DEPRECATED_PARAMETER,
100
 
    deprecated_function,
101
 
    deprecated_in,
102
 
    deprecated_method,
103
 
    deprecated_passed,
104
 
    )
105
 
import bzrlib.trace
106
93
from bzrlib.transport import (
107
94
    memory,
108
95
    pathfilter,
109
96
    )
110
 
from bzrlib.trace import mutter, note
111
97
from bzrlib.tests import (
112
98
    test_server,
113
99
    TestUtil,
115
101
    )
116
102
from bzrlib.ui import NullProgressView
117
103
from bzrlib.ui.text import TextUIFactory
118
 
import bzrlib.version_info_formats.format_custom
119
104
 
120
105
# Mark this python module as being part of the implementation
121
106
# of unittest: this gives us better tracebacks where the last
301
286
        addOnException = getattr(test, "addOnException", None)
302
287
        if addOnException is not None:
303
288
            addOnException(self._record_traceback_from_test)
304
 
        # Only check for thread leaks if the test case supports cleanups
305
 
        addCleanup = getattr(test, "addCleanup", None)
306
 
        if addCleanup is not None:
307
 
            addCleanup(self._check_leaked_threads, test)
 
289
        # Only check for thread leaks on bzrlib derived test cases
 
290
        if isinstance(test, TestCase):
 
291
            test.addCleanup(self._check_leaked_threads, test)
308
292
 
309
293
    def startTests(self):
310
294
        self.report_tests_starting()
851
835
        self.addDetail("log", content.Content(content.ContentType("text",
852
836
            "plain", {"charset": "utf8"}),
853
837
            lambda:[self._get_log(keep_log_file=True)]))
 
838
        self._old_env = {}
854
839
        self._cleanEnvironment()
855
840
        self._silenceUI()
856
841
        self._startLogFile()
1126
1111
        except UnicodeError, e:
1127
1112
            # If we can't compare without getting a UnicodeError, then
1128
1113
            # obviously they are different
1129
 
            mutter('UnicodeError: %s', e)
 
1114
            trace.mutter('UnicodeError: %s', e)
1130
1115
        if message:
1131
1116
            message += '\n'
1132
1117
        raise AssertionError("%snot equal:\na = %s\nb = %s\n"
1192
1177
    def assertLogsError(self, exception_class, func, *args, **kwargs):
1193
1178
        """Assert that func(*args, **kwargs) quietly logs a specific exception.
1194
1179
        """
1195
 
        from bzrlib import trace
1196
1180
        captured = []
1197
1181
        orig_log_exception_quietly = trace.log_exception_quietly
1198
1182
        try:
1492
1476
        The file is removed as the test is torn down.
1493
1477
        """
1494
1478
        self._log_file = StringIO()
1495
 
        self._log_memento = bzrlib.trace.push_log_file(self._log_file)
 
1479
        self._log_memento = trace.push_log_file(self._log_file)
1496
1480
        self.addCleanup(self._finishLogFile)
1497
1481
 
1498
1482
    def _finishLogFile(self):
1500
1484
 
1501
1485
        Close the file and delete it, unless setKeepLogfile was called.
1502
1486
        """
1503
 
        if bzrlib.trace._trace_file:
 
1487
        if trace._trace_file:
1504
1488
            # flush the log file, to get all content
1505
 
            bzrlib.trace._trace_file.flush()
1506
 
        bzrlib.trace.pop_log_file(self._log_memento)
 
1489
            trace._trace_file.flush()
 
1490
        trace.pop_log_file(self._log_memento)
1507
1491
        # Cache the log result and delete the file on disk
1508
1492
        self._get_log(False)
1509
1493
 
1539
1523
            setattr(obj, attr_name, new)
1540
1524
        return value
1541
1525
 
 
1526
    def overrideEnv(self, name, new):
 
1527
        """Set an environment variable, and reset it after the test.
 
1528
 
 
1529
        :param name: The environment variable name.
 
1530
 
 
1531
        :param new: The value to set the variable to. If None, the 
 
1532
            variable is deleted from the environment.
 
1533
 
 
1534
        :returns: The actual variable value.
 
1535
        """
 
1536
        value = osutils.set_or_unset_env(name, new)
 
1537
        self.addCleanup(osutils.set_or_unset_env, name, value)
 
1538
        return value
 
1539
 
1542
1540
    def _cleanEnvironment(self):
1543
1541
        new_env = {
1544
1542
            'BZR_HOME': None, # Don't inherit BZR_HOME to all the tests.
1588
1586
            # use an env var so it propagates to subprocesses.
1589
1587
            'APPORT_DISABLE': '1',
1590
1588
        }
1591
 
        self._old_env = {}
1592
 
        self.addCleanup(self._restoreEnvironment)
1593
1589
        for name, value in new_env.iteritems():
1594
 
            self._captureVar(name, value)
 
1590
            self.overrideEnv(name, value)
1595
1591
 
1596
1592
    def _captureVar(self, name, newvalue):
1597
1593
        """Set an environment variable, and reset it when finished."""
1598
1594
        self._old_env[name] = osutils.set_or_unset_env(name, newvalue)
1599
1595
 
1600
 
    def _restoreEnvironment(self):
1601
 
        for name, value in self._old_env.iteritems():
1602
 
            osutils.set_or_unset_env(name, value)
1603
 
 
1604
1596
    def _restoreHooks(self):
1605
1597
        for klass, (name, hooks) in self._preserved_hooks.items():
1606
1598
            setattr(klass, name, hooks)
1699
1691
            self._benchtime += time.time() - start
1700
1692
 
1701
1693
    def log(self, *args):
1702
 
        mutter(*args)
 
1694
        trace.mutter(*args)
1703
1695
 
1704
1696
    def _get_log(self, keep_log_file=False):
1705
1697
        """Internal helper to get the log from bzrlib.trace for this test.
1790
1782
 
1791
1783
        try:
1792
1784
            try:
1793
 
                result = self.apply_redirected(ui.ui_factory.stdin,
 
1785
                result = self.apply_redirected(
 
1786
                    ui.ui_factory.stdin,
1794
1787
                    stdout, stderr,
1795
 
                    bzrlib.commands.run_bzr_catch_user_errors,
 
1788
                    _mod_commands.run_bzr_catch_user_errors,
1796
1789
                    args)
1797
1790
            except KeyboardInterrupt:
1798
1791
                # Reraise KeyboardInterrupt with contents of redirected stdout
2048
2041
        if retcode is not None and retcode != process.returncode:
2049
2042
            if process_args is None:
2050
2043
                process_args = "(unknown args)"
2051
 
            mutter('Output of bzr %s:\n%s', process_args, out)
2052
 
            mutter('Error for bzr %s:\n%s', process_args, err)
 
2044
            trace.mutter('Output of bzr %s:\n%s', process_args, out)
 
2045
            trace.mutter('Error for bzr %s:\n%s', process_args, err)
2053
2046
            self.fail('Command bzr %s failed with retcode %s != %s'
2054
2047
                      % (process_args, retcode, process.returncode))
2055
2048
        return [out, err]
2112
2105
 
2113
2106
        Tests that expect to provoke LockContention errors should call this.
2114
2107
        """
2115
 
        self.overrideAttr(bzrlib.lockdir, '_DEFAULT_TIMEOUT_SECONDS', 0)
 
2108
        self.overrideAttr(lockdir, '_DEFAULT_TIMEOUT_SECONDS', 0)
2116
2109
 
2117
2110
    def make_utf8_encoded_stringio(self, encoding_type=None):
2118
2111
        """Return a StringIOWrapper instance, that will encode Unicode
2442
2435
        test_home_dir = self.test_home_dir
2443
2436
        if isinstance(test_home_dir, unicode):
2444
2437
            test_home_dir = test_home_dir.encode(sys.getfilesystemencoding())
2445
 
        os.environ['HOME'] = test_home_dir
2446
 
        os.environ['BZR_HOME'] = test_home_dir
 
2438
        self.overrideEnv('HOME', test_home_dir)
 
2439
        self.overrideEnv('BZR_HOME', test_home_dir)
2447
2440
 
2448
2441
    def setUp(self):
2449
2442
        super(TestCaseWithMemoryTransport, self).setUp()
3599
3592
                key, obj, help=help, info=info, override_existing=False)
3600
3593
        except KeyError:
3601
3594
            actual = self.get(key)
3602
 
            note('Test prefix alias %s is already used for %s, ignoring %s'
3603
 
                 % (key, actual, obj))
 
3595
            trace.note(
 
3596
                'Test prefix alias %s is already used for %s, ignoring %s'
 
3597
                % (key, actual, obj))
3604
3598
 
3605
3599
    def resolve_alias(self, id_start):
3606
3600
        """Replace the alias by the prefix in the given string.
3842
3836
        return []
3843
3837
    return [
3844
3838
        'bzrlib',
3845
 
        'bzrlib.branchbuilder',
 
3839
        # FIXME: Fixing bug #690563 revealed an isolation problem in the single
 
3840
        # doctest for branchbuilder. Uncomment this when bug #321320 is fixed
 
3841
        # to ensure the issue is addressed (note that to reproduce the bug in
 
3842
        # the doctest below, one should comment the 'email' config var in
 
3843
        # bazaar.conf (or anywhere else). This means an setup where *no* user
 
3844
        # is being set at all in the environment.
 
3845
#       'bzrlib.branchbuilder',
3846
3846
        'bzrlib.decorators',
3847
3847
        'bzrlib.export',
3848
3848
        'bzrlib.inventory',
3924
3924
        suite.addTest(doc_suite)
3925
3925
 
3926
3926
    default_encoding = sys.getdefaultencoding()
3927
 
    for name, plugin in bzrlib.plugin.plugins().items():
 
3927
    for name, plugin in _mod_plugin.plugins().items():
3928
3928
        if not interesting_module(plugin.module.__name__):
3929
3929
            continue
3930
3930
        plugin_suite = plugin.test_suite()
3936
3936
        if plugin_suite is not None:
3937
3937
            suite.addTest(plugin_suite)
3938
3938
        if default_encoding != sys.getdefaultencoding():
3939
 
            bzrlib.trace.warning(
 
3939
            trace.warning(
3940
3940
                'Plugin "%s" tried to reset default encoding to: %s', name,
3941
3941
                sys.getdefaultencoding())
3942
3942
            reload(sys)
3957
3957
            # Some tests mentioned in the list are not in the test suite. The
3958
3958
            # list may be out of date, report to the tester.
3959
3959
            for id in not_found:
3960
 
                bzrlib.trace.warning('"%s" not found in the test suite', id)
 
3960
                trace.warning('"%s" not found in the test suite', id)
3961
3961
        for id in duplicates:
3962
 
            bzrlib.trace.warning('"%s" is used as an id by several tests', id)
 
3962
            trace.warning('"%s" is used as an id by several tests', id)
3963
3963
 
3964
3964
    return suite
3965
3965
 
4303
4303
        return self.module_name
4304
4304
 
4305
4305
 
4306
 
# This is kept here for compatibility, it is recommended to use
4307
 
# 'bzrlib.tests.feature.paramiko' instead
4308
 
ParamikoFeature = _CompatabilityThunkFeature(
4309
 
    deprecated_in((2,1,0)),
4310
 
    'bzrlib.tests.features', 'ParamikoFeature', 'paramiko')
4311
 
 
4312
 
 
4313
4306
def probe_unicode_in_user_encoding():
4314
4307
    """Try to encode several unicode strings to use in unicode-aware tests.
4315
4308
    Return first successfull match.
4502
4495
case_sensitive_filesystem_feature = _CaseSensitiveFilesystemFeature()
4503
4496
 
4504
4497
 
4505
 
# Kept for compatibility, use bzrlib.tests.features.subunit instead
4506
 
SubUnitFeature = _CompatabilityThunkFeature(
4507
 
    deprecated_in((2,1,0)),
4508
 
    'bzrlib.tests.features', 'SubUnitFeature', 'subunit')
4509
4498
# Only define SubUnitBzrRunner if subunit is available.
4510
4499
try:
4511
4500
    from subunit import TestProtocolClient