/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/test_selftest.py

  • Committer: Aaron Bentley
  • Date: 2007-03-03 17:17:53 UTC
  • mfrom: (2309 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2316.
  • Revision ID: aaron.bentley@utoronto.ca-20070303171753-o0s1yrxx5sn12p2k
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 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
27
27
import bzrlib
28
28
from bzrlib import (
29
29
    bzrdir,
 
30
    errors,
30
31
    memorytree,
31
32
    osutils,
32
33
    repository,
 
34
    symbol_versioning,
33
35
    )
34
36
from bzrlib.progress import _BaseProgressBar
 
37
from bzrlib.repofmt import weaverepo
 
38
from bzrlib.symbol_versioning import zero_ten, zero_eleven
35
39
from bzrlib.tests import (
36
40
                          ChrootedTestCase,
37
41
                          TestCase,
44
48
                          )
45
49
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
46
50
from bzrlib.tests.TestUtil import _load_module_by_name
47
 
import bzrlib.errors as errors
48
 
from bzrlib import symbol_versioning
49
 
from bzrlib.symbol_versioning import zero_ten, zero_eleven
50
51
from bzrlib.trace import note
51
52
from bzrlib.transport.memory import MemoryServer, MemoryTransport
52
53
from bzrlib.version import _get_bzr_source_tree
467
468
        a branch and checking no directory was created at its relpath.
468
469
        """
469
470
        tree = self.make_branch_and_memory_tree('dir')
470
 
        self.failIfExists('dir')
 
471
        # Guard against regression into MemoryTransport leaking
 
472
        # files to disk instead of keeping them in memory.
 
473
        self.failIf(osutils.lexists('dir'))
471
474
        self.assertIsInstance(tree, memorytree.MemoryTree)
472
475
 
473
476
    def test_make_branch_and_memory_tree_with_format(self):
474
477
        """make_branch_and_memory_tree should accept a format option."""
475
478
        format = bzrdir.BzrDirMetaFormat1()
476
 
        format.repository_format = repository.RepositoryFormat7()
 
479
        format.repository_format = weaverepo.RepositoryFormat7()
477
480
        tree = self.make_branch_and_memory_tree('dir', format=format)
478
 
        self.failIfExists('dir')
 
481
        # Guard against regression into MemoryTransport leaking
 
482
        # files to disk instead of keeping them in memory.
 
483
        self.failIf(osutils.lexists('dir'))
479
484
        self.assertIsInstance(tree, memorytree.MemoryTree)
480
485
        self.assertEqual(format.repository_format.__class__,
481
486
            tree.branch.repository._format.__class__)
501
506
        self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
502
507
 
503
508
    def test_get_readonly_url_http(self):
 
509
        from bzrlib.tests.HttpServer import HttpServer
504
510
        from bzrlib.transport import get_transport
505
511
        from bzrlib.transport.local import LocalURLServer
506
 
        from bzrlib.transport.http import HttpServer, HttpTransportBase
 
512
        from bzrlib.transport.http import HttpTransportBase
507
513
        self.transport_server = LocalURLServer
508
514
        self.transport_readonly_server = HttpServer
509
515
        # calling get_readonly_transport() gives us a HTTP server instance.
584
590
        result.extractBenchmarkTime(self)
585
591
        timed_string = result._testTimeString()
586
592
        # without explicit benchmarking, we should get a simple time.
587
 
        self.assertContainsRe(timed_string, "^         [ 1-9][0-9]ms$")
 
593
        self.assertContainsRe(timed_string, "^ *[ 1-9][0-9]ms$")
588
594
        # if a benchmark time is given, we want a x of y style result.
589
595
        self.time(time.sleep, 0.001)
590
596
        result.extractBenchmarkTime(self)
591
597
        timed_string = result._testTimeString()
592
 
        self.assertContainsRe(timed_string, "^   [ 1-9][0-9]ms/   [ 1-9][0-9]ms$")
 
598
        self.assertContainsRe(timed_string, "^ *[ 1-9][0-9]ms/ *[ 1-9][0-9]ms$")
593
599
        # extracting the time from a non-bzrlib testcase sets to None
594
600
        result._recordTestStartTime()
595
601
        result.extractBenchmarkTime(
596
602
            unittest.FunctionTestCase(self.test_elapsed_time_with_benchmarking))
597
603
        timed_string = result._testTimeString()
598
 
        self.assertContainsRe(timed_string, "^         [ 1-9][0-9]ms$")
 
604
        self.assertContainsRe(timed_string, "^ *[ 1-9][0-9]ms$")
599
605
        # cheat. Yes, wash thy mouth out with soap.
600
606
        self._benchtime = None
601
607
 
847
853
        self.assertContainsRe(
848
854
            output_stream.getvalue(),
849
855
            r"\d+ms/ +\d+ms\n$")
850
 
        
 
856
 
 
857
    def test_hooks_sanitised(self):
 
858
        """The bzrlib hooks should be sanitised by setUp."""
 
859
        self.assertEqual(bzrlib.branch.BranchHooks(),
 
860
            bzrlib.branch.Branch.hooks)
 
861
 
851
862
    def test__gather_lsprof_in_benchmarks(self):
852
863
        """When _gather_lsprof_in_benchmarks is on, accumulate profile data.
853
864
        
998
1009
        self.apply_redirected(out, err, None, bzrlib.tests.selftest, 
999
1010
            test_suite_factory=factory)
1000
1011
        self.assertEqual([True], factory_called)
 
1012
 
 
1013
 
 
1014
class TestSelftestCleanOutput(TestCaseInTempDir):
 
1015
 
 
1016
    def test_clean_output(self):
 
1017
        # test functionality of clean_selftest_output()
 
1018
        from bzrlib.tests import clean_selftest_output
 
1019
 
 
1020
        dirs = ('test0000.tmp', 'test0001.tmp', 'bzrlib', 'tests')
 
1021
        files = ('bzr', 'setup.py', 'test9999.tmp')
 
1022
        for i in dirs:
 
1023
            os.mkdir(i)
 
1024
        for i in files:
 
1025
            f = file(i, 'wb')
 
1026
            f.write('content of ')
 
1027
            f.write(i)
 
1028
            f.close()
 
1029
 
 
1030
        root = os.getcwdu()
 
1031
        before = os.listdir(root)
 
1032
        before.sort()
 
1033
        self.assertEquals(['bzr','bzrlib','setup.py',
 
1034
                           'test0000.tmp','test0001.tmp',
 
1035
                           'test9999.tmp','tests'],
 
1036
                           before)
 
1037
        clean_selftest_output(root, quiet=True)
 
1038
        after = os.listdir(root)
 
1039
        after.sort()
 
1040
        self.assertEquals(['bzr','bzrlib','setup.py',
 
1041
                           'test9999.tmp','tests'],
 
1042
                           after)