/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: Canonical.com Patch Queue Manager
  • Date: 2010-02-17 17:42:03 UTC
  • mfrom: (5035.2.4 nomoreserialiseinv)
  • Revision ID: pqm@pqm.ubuntu.com-20100217174203-bd8elqnhq6w48xb2
(Jelmer) Remove Repository._serialise_inventory_to_{lines,string}.

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
1682
1671
                unicodestr = log_contents.decode('utf8', 'replace')
1683
1672
                log_contents = unicodestr.encode('utf8')
1684
1673
            if not keep_log_file:
1685
 
                close_attempts = 0
1686
 
                max_close_attempts = 100
1687
 
                first_close_error = None
1688
 
                while close_attempts < max_close_attempts:
1689
 
                    close_attempts += 1
1690
 
                    try:
1691
 
                        self._log_file.close()
1692
 
                    except IOError, ioe:
1693
 
                        if ioe.errno is None:
1694
 
                            # No errno implies 'close() called during
1695
 
                            # concurrent operation on the same file object', so
1696
 
                            # retry.  Probably a thread is trying to write to
1697
 
                            # the log file.
1698
 
                            if first_close_error is None:
1699
 
                                first_close_error = ioe
1700
 
                            continue
1701
 
                        raise
1702
 
                    else:
1703
 
                        break
1704
 
                if close_attempts > 1:
1705
 
                    sys.stderr.write(
1706
 
                        'Unable to close log file on first attempt, '
1707
 
                        'will retry: %s\n' % (first_close_error,))
1708
 
                    if close_attempts == max_close_attempts:
1709
 
                        sys.stderr.write(
1710
 
                            'Unable to close log file after %d attempts.\n'
1711
 
                            % (max_close_attempts,))
 
1674
                self._log_file.close()
1712
1675
                self._log_file = None
1713
1676
                # Permit multiple calls to get_log until we clean it up in
1714
1677
                # finishLogFile
3201
3164
    return result
3202
3165
 
3203
3166
 
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
3167
def fork_for_tests(suite):
3218
3168
    """Take suite and start up one runner per CPU by forking()
3219
3169
 
3234
3184
            try:
3235
3185
                ProtocolTestCase.run(self, result)
3236
3186
            finally:
3237
 
                os.waitpid(self.pid, 0)
 
3187
                os.waitpid(self.pid, os.WNOHANG)
3238
3188
 
3239
3189
    test_blocks = partition_tests(suite, concurrency)
3240
3190
    for process_tests in test_blocks:
3243
3193
        c2pread, c2pwrite = os.pipe()
3244
3194
        pid = os.fork()
3245
3195
        if pid == 0:
3246
 
            workaround_zealous_crypto_random()
3247
3196
            try:
3248
3197
                os.close(c2pread)
3249
3198
                # Leave stderr and stdout open so we can see test noise
3634
3583
        'bzrlib.tests.commands',
3635
3584
        'bzrlib.tests.per_branch',
3636
3585
        'bzrlib.tests.per_bzrdir',
3637
 
        'bzrlib.tests.per_bzrdir_colo',
3638
3586
        'bzrlib.tests.per_foreign_vcs',
3639
3587
        'bzrlib.tests.per_interrepository',
3640
3588
        'bzrlib.tests.per_intertree',
3680
3628
        'bzrlib.tests.test_chunk_writer',
3681
3629
        'bzrlib.tests.test_clean_tree',
3682
3630
        'bzrlib.tests.test_cleanup',
3683
 
        'bzrlib.tests.test_cmdline',
3684
3631
        'bzrlib.tests.test_commands',
3685
3632
        'bzrlib.tests.test_commit',
3686
3633
        'bzrlib.tests.test_commit_merge',
3819
3766
 
3820
3767
 
3821
3768
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 []
 
3769
    """Return the list of modules to doctest."""   
3826
3770
    return [
3827
3771
        'bzrlib',
3828
3772
        'bzrlib.branchbuilder',
4461
4405
            return result
4462
4406
except ImportError:
4463
4407
    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()