/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: Jelmer Vernooij
  • Date: 2010-03-13 02:49:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5089.
  • Revision ID: jelmer@samba.org-20100313024914-rpuoguinoxpxt05b
Allow merge directives to output multiple patch files. 

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):
1528
1519
            'BZR_PROGRESS_BAR': None,
1529
1520
            'BZR_LOG': None,
1530
1521
            'BZR_PLUGIN_PATH': None,
1531
 
            'BZR_DISABLE_PLUGINS': None,
1532
 
            'BZR_PLUGINS_AT': None,
1533
1522
            'BZR_CONCURRENCY': None,
1534
1523
            # Make sure that any text ui tests are consistent regardless of
1535
1524
            # the environment the test case is run in; you may want tests that
3201
3190
    return result
3202
3191
 
3203
3192
 
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
3193
def fork_for_tests(suite):
3218
3194
    """Take suite and start up one runner per CPU by forking()
3219
3195
 
3234
3210
            try:
3235
3211
                ProtocolTestCase.run(self, result)
3236
3212
            finally:
3237
 
                os.waitpid(self.pid, 0)
 
3213
                os.waitpid(self.pid, os.WNOHANG)
3238
3214
 
3239
3215
    test_blocks = partition_tests(suite, concurrency)
3240
3216
    for process_tests in test_blocks:
3243
3219
        c2pread, c2pwrite = os.pipe()
3244
3220
        pid = os.fork()
3245
3221
        if pid == 0:
3246
 
            workaround_zealous_crypto_random()
3247
3222
            try:
3248
3223
                os.close(c2pread)
3249
3224
                # Leave stderr and stdout open so we can see test noise
3634
3609
        'bzrlib.tests.commands',
3635
3610
        'bzrlib.tests.per_branch',
3636
3611
        'bzrlib.tests.per_bzrdir',
3637
 
        'bzrlib.tests.per_bzrdir_colo',
3638
3612
        'bzrlib.tests.per_foreign_vcs',
3639
3613
        'bzrlib.tests.per_interrepository',
3640
3614
        'bzrlib.tests.per_intertree',
3734
3708
        'bzrlib.tests.test_lru_cache',
3735
3709
        'bzrlib.tests.test_lsprof',
3736
3710
        'bzrlib.tests.test_mail_client',
3737
 
        'bzrlib.tests.test_matchers',
3738
3711
        'bzrlib.tests.test_memorytree',
3739
3712
        'bzrlib.tests.test_merge',
3740
3713
        'bzrlib.tests.test_merge3',
3820
3793
 
3821
3794
 
3822
3795
def _test_suite_modules_to_doctest():
3823
 
    """Return the list of modules to doctest."""
3824
 
    if __doc__ is None:
3825
 
        # GZ 2009-03-31: No docstrings with -OO so there's nothing to doctest
3826
 
        return []
 
3796
    """Return the list of modules to doctest."""   
3827
3797
    return [
3828
3798
        'bzrlib',
3829
3799
        'bzrlib.branchbuilder',
4462
4432
            return result
4463
4433
except ImportError:
4464
4434
    pass
4465
 
 
4466
 
class _PosixPermissionsFeature(Feature):
4467
 
 
4468
 
    def _probe(self):
4469
 
        def has_perms():
4470
 
            # create temporary file and check if specified perms are maintained.
4471
 
            import tempfile
4472
 
 
4473
 
            write_perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
4474
 
            f = tempfile.mkstemp(prefix='bzr_perms_chk_')
4475
 
            fd, name = f
4476
 
            os.close(fd)
4477
 
            os.chmod(name, write_perms)
4478
 
 
4479
 
            read_perms = os.stat(name).st_mode & 0777
4480
 
            os.unlink(name)
4481
 
            return (write_perms == read_perms)
4482
 
 
4483
 
        return (os.name == 'posix') and has_perms()
4484
 
 
4485
 
    def feature_name(self):
4486
 
        return 'POSIX permissions support'
4487
 
 
4488
 
posix_permissions_feature = _PosixPermissionsFeature()