~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Robert Collins
  • Date: 2010-04-08 04:34:03 UTC
  • mfrom: (5138 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5139.
  • Revision ID: robertc@robertcollins.net-20100408043403-56z0d07vdqrx7f3t
Update bugfix for 528114 to trunk.

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"""
18
17
 
19
18
# TODO: Perhaps there should be an API to find out if bzr running under the
20
19
# test suite -- some plugins might want to avoid making intrusive changes if
490
489
        return self._shortened_test_description(test)
491
490
 
492
491
    def report_error(self, test, err):
493
 
        self.stream.write('ERROR: %s\n    %s\n' % (
 
492
        self.ui.note('ERROR: %s\n    %s\n' % (
494
493
            self._test_description(test),
495
494
            err[1],
496
495
            ))
497
496
 
498
497
    def report_failure(self, test, err):
499
 
        self.stream.write('FAIL: %s\n    %s\n' % (
 
498
        self.ui.note('FAIL: %s\n    %s\n' % (
500
499
            self._test_description(test),
501
500
            err[1],
502
501
            ))
1313
1312
            f.close()
1314
1313
        self.assertEqualDiff(content, s)
1315
1314
 
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
 
 
1324
1315
    def failUnlessExists(self, path):
1325
1316
        """Fail unless path or paths, which may be abs or relative, exist."""
1326
1317
        if not isinstance(path, basestring):
3201
3192
    return result
3202
3193
 
3203
3194
 
3204
 
def workaround_zealous_crypto_random():
3205
 
    """Crypto.Random want to help us being secure, but we don't care here.
3206
 
 
3207
 
    This workaround some test failure related to the sftp server. Once paramiko
3208
 
    stop using the controversial API in Crypto.Random, we may get rid of it.
3209
 
    """
3210
 
    try:
3211
 
        from Crypto.Random import atfork
3212
 
        atfork()
3213
 
    except ImportError:
3214
 
        pass
3215
 
 
3216
 
 
3217
3195
def fork_for_tests(suite):
3218
3196
    """Take suite and start up one runner per CPU by forking()
3219
3197
 
3234
3212
            try:
3235
3213
                ProtocolTestCase.run(self, result)
3236
3214
            finally:
3237
 
                os.waitpid(self.pid, 0)
 
3215
                os.waitpid(self.pid, os.WNOHANG)
3238
3216
 
3239
3217
    test_blocks = partition_tests(suite, concurrency)
3240
3218
    for process_tests in test_blocks:
3243
3221
        c2pread, c2pwrite = os.pipe()
3244
3222
        pid = os.fork()
3245
3223
        if pid == 0:
3246
 
            workaround_zealous_crypto_random()
3247
3224
            try:
3248
3225
                os.close(c2pread)
3249
3226
                # Leave stderr and stdout open so we can see test noise
3634
3611
        'bzrlib.tests.commands',
3635
3612
        'bzrlib.tests.per_branch',
3636
3613
        'bzrlib.tests.per_bzrdir',
3637
 
        'bzrlib.tests.per_bzrdir_colo',
3638
3614
        'bzrlib.tests.per_foreign_vcs',
3639
3615
        'bzrlib.tests.per_interrepository',
3640
3616
        'bzrlib.tests.per_intertree',
3819
3795
 
3820
3796
 
3821
3797
def _test_suite_modules_to_doctest():
3822
 
    """Return the list of modules to doctest."""
3823
 
    if __doc__ is None:
3824
 
        # GZ 2009-03-31: No docstrings with -OO so there's nothing to doctest
3825
 
        return []
 
3798
    """Return the list of modules to doctest."""   
3826
3799
    return [
3827
3800
        'bzrlib',
3828
3801
        'bzrlib.branchbuilder',
4461
4434
            return result
4462
4435
except ImportError:
4463
4436
    pass
4464
 
 
4465
 
class _PosixPermissionsFeature(Feature):
4466
 
 
4467
 
    def _probe(self):
4468
 
        def has_perms():
4469
 
            # create temporary file and check if specified perms are maintained.
4470
 
            import tempfile
4471
 
 
4472
 
            write_perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
4473
 
            f = tempfile.mkstemp(prefix='bzr_perms_chk_')
4474
 
            fd, name = f
4475
 
            os.close(fd)
4476
 
            os.chmod(name, write_perms)
4477
 
 
4478
 
            read_perms = os.stat(name).st_mode & 0777
4479
 
            os.unlink(name)
4480
 
            return (write_perms == read_perms)
4481
 
 
4482
 
        return (os.name == 'posix') and has_perms()
4483
 
 
4484
 
    def feature_name(self):
4485
 
        return 'POSIX permissions support'
4486
 
 
4487
 
posix_permissions_feature = _PosixPermissionsFeature()