~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Aaron Bentley
  • Date: 2010-05-10 11:34:20 UTC
  • mfrom: (5218 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5221.
  • Revision ID: aaron@aaronbentley.com-20100510113420-toh2d5yioobb5uq1
Merged bzr.dev into transform-commit-full.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
"""Testing framework extensions"""
17
18
 
18
19
# TODO: Perhaps there should be an API to find out if bzr running under the
19
20
# test suite -- some plugins might want to avoid making intrusive changes if
111
112
from bzrlib.tests import (
112
113
    test_server,
113
114
    TestUtil,
 
115
    treeshape,
114
116
    )
115
117
from bzrlib.tests.http_server import HttpServer
116
118
from bzrlib.tests.TestUtil import (
117
119
                          TestSuite,
118
120
                          TestLoader,
119
121
                          )
120
 
from bzrlib.tests.treeshape import build_tree_contents
121
122
from bzrlib.ui import NullProgressView
122
123
from bzrlib.ui.text import TextUIFactory
123
124
import bzrlib.version_info_formats.format_custom
489
490
        return self._shortened_test_description(test)
490
491
 
491
492
    def report_error(self, test, err):
492
 
        self.ui.note('ERROR: %s\n    %s\n' % (
 
493
        self.stream.write('ERROR: %s\n    %s\n' % (
493
494
            self._test_description(test),
494
495
            err[1],
495
496
            ))
496
497
 
497
498
    def report_failure(self, test, err):
498
 
        self.ui.note('FAIL: %s\n    %s\n' % (
 
499
        self.stream.write('FAIL: %s\n    %s\n' % (
499
500
            self._test_description(test),
500
501
            err[1],
501
502
            ))
1312
1313
            f.close()
1313
1314
        self.assertEqualDiff(content, s)
1314
1315
 
 
1316
    def assertDocstring(self, expected_docstring, obj):
 
1317
        """Fail if obj does not have expected_docstring"""
 
1318
        if __doc__ is None:
 
1319
            # With -OO the docstring should be None instead
 
1320
            self.assertIs(obj.__doc__, None)
 
1321
        else:
 
1322
            self.assertEqual(expected_docstring, obj.__doc__)
 
1323
 
1315
1324
    def failUnlessExists(self, path):
1316
1325
        """Fail unless path or paths, which may be abs or relative, exist."""
1317
1326
        if not isinstance(path, basestring):
1515
1524
            'EDITOR': None,
1516
1525
            'BZR_EMAIL': None,
1517
1526
            'BZREMAIL': None, # may still be present in the environment
1518
 
            'EMAIL': None,
 
1527
            'EMAIL': 'jrandom@example.com', # set EMAIL as bzr does not guess
1519
1528
            'BZR_PROGRESS_BAR': None,
1520
1529
            'BZR_LOG': None,
1521
1530
            'BZR_PLUGIN_PATH': None,
2569
2578
                content = "contents of %s%s" % (name.encode('utf-8'), end)
2570
2579
                transport.put_bytes_non_atomic(urlutils.escape(name), content)
2571
2580
 
2572
 
    def build_tree_contents(self, shape):
2573
 
        build_tree_contents(shape)
 
2581
    build_tree_contents = staticmethod(treeshape.build_tree_contents)
2574
2582
 
2575
2583
    def assertInWorkingTree(self, path, root_path='.', tree=None):
2576
2584
        """Assert whether path or paths are in the WorkingTree"""
3192
3200
    return result
3193
3201
 
3194
3202
 
 
3203
def workaround_zealous_crypto_random():
 
3204
    """Crypto.Random want to help us being secure, but we don't care here.
 
3205
 
 
3206
    This workaround some test failure related to the sftp server. Once paramiko
 
3207
    stop using the controversial API in Crypto.Random, we may get rid of it.
 
3208
    """
 
3209
    try:
 
3210
        from Crypto.Random import atfork
 
3211
        atfork()
 
3212
    except ImportError:
 
3213
        pass
 
3214
 
 
3215
 
3195
3216
def fork_for_tests(suite):
3196
3217
    """Take suite and start up one runner per CPU by forking()
3197
3218
 
3212
3233
            try:
3213
3234
                ProtocolTestCase.run(self, result)
3214
3235
            finally:
3215
 
                os.waitpid(self.pid, os.WNOHANG)
 
3236
                os.waitpid(self.pid, 0)
3216
3237
 
3217
3238
    test_blocks = partition_tests(suite, concurrency)
3218
3239
    for process_tests in test_blocks:
3221
3242
        c2pread, c2pwrite = os.pipe()
3222
3243
        pid = os.fork()
3223
3244
        if pid == 0:
 
3245
            workaround_zealous_crypto_random()
3224
3246
            try:
3225
3247
                os.close(c2pread)
3226
3248
                # Leave stderr and stdout open so we can see test noise
3796
3818
 
3797
3819
 
3798
3820
def _test_suite_modules_to_doctest():
3799
 
    """Return the list of modules to doctest."""   
 
3821
    """Return the list of modules to doctest."""
 
3822
    if __doc__ is None:
 
3823
        # GZ 2009-03-31: No docstrings with -OO so there's nothing to doctest
 
3824
        return []
3800
3825
    return [
3801
3826
        'bzrlib',
3802
3827
        'bzrlib.branchbuilder',