/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: Robert Collins
  • Date: 2006-03-03 02:09:49 UTC
  • mto: (1594.2.4 integration)
  • mto: This revision was merged to the branch mainline in revision 1596.
  • Revision ID: robertc@robertcollins.net-20060303020949-0ddc6f33d0a43943
Smoke test for RevisionStore factories creating revision stores.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
# little as possible, so this should be used rarely if it's added at all.
22
22
# (Suggestion from j-a-meinel, 2005-11-24)
23
23
 
24
 
# NOTE: Some classes in here use camelCaseNaming() rather than
25
 
# underscore_naming().  That's for consistency with unittest; it's not the
26
 
# general style of bzrlib.  Please continue that consistency when adding e.g.
27
 
# new assertFoo() methods.
28
 
 
29
24
import codecs
30
25
from cStringIO import StringIO
31
26
import difflib
48
43
import bzrlib.inventory
49
44
import bzrlib.iterablefile
50
45
import bzrlib.lockdir
51
 
from bzrlib.merge import merge_inner
52
46
import bzrlib.merge3
53
47
import bzrlib.osutils
54
48
import bzrlib.osutils as osutils
55
49
import bzrlib.plugin
56
 
from bzrlib.revision import common_ancestor
57
50
import bzrlib.store
58
51
import bzrlib.trace
59
52
from bzrlib.transport import urlescape, get_transport
329
322
    def assertTransportMode(self, transport, path, mode):
330
323
        """Fail if a path does not have mode mode.
331
324
        
332
 
        If modes are not supported on this transport, the assertion is ignored.
 
325
        If modes are not supported on this platform, the test is skipped.
333
326
        """
334
 
        if not transport._can_roundtrip_unix_modebits():
 
327
        if sys.platform == 'win32':
335
328
            return
336
329
        path_stat = transport.stat(path)
337
330
        actual_mode = stat.S_IMODE(path_stat.st_mode)
338
331
        self.assertEqual(mode, actual_mode,
339
332
            'mode of %r incorrect (%o != %o)' % (path, mode, actual_mode))
340
333
 
341
 
    def assertIsInstance(self, obj, kls):
342
 
        """Fail if obj is not an instance of kls"""
343
 
        if not isinstance(obj, kls):
344
 
            self.fail("%r is not an instance of %s" % (obj, kls))
345
 
 
346
334
    def _startLogFile(self):
347
335
        """Send bzr and test log messages to a temporary file.
348
336
 
551
539
            sys.stderr = real_stderr
552
540
            sys.stdin = real_stdin
553
541
 
554
 
    def merge(self, branch_from, wt_to):
555
 
        """A helper for tests to do a ui-less merge.
556
 
 
557
 
        This should move to the main library when someone has time to integrate
558
 
        it in.
559
 
        """
560
 
        # minimal ui-less merge.
561
 
        wt_to.branch.fetch(branch_from)
562
 
        base_rev = common_ancestor(branch_from.last_revision(),
563
 
                                   wt_to.branch.last_revision(),
564
 
                                   wt_to.branch.repository)
565
 
        merge_inner(wt_to.branch, branch_from.basis_tree(), 
566
 
                    wt_to.branch.repository.revision_tree(base_rev),
567
 
                    this_tree=wt_to)
568
 
        wt_to.add_pending_merge(branch_from.last_revision())
569
 
 
570
542
 
571
543
BzrTestBase = TestCase
572
544
 
621
593
        super(TestCaseInTempDir, self).setUp()
622
594
        self._make_test_root()
623
595
        _currentdir = os.getcwdu()
624
 
        # shorten the name, to avoid test failures due to path length
625
596
        short_id = self.id().replace('bzrlib.tests.', '') \
626
 
                   .replace('__main__.', '')[-100:]
627
 
        # it's possible the same test class is run several times for
628
 
        # parameterized tests, so make sure the names don't collide.  
629
 
        i = 0
630
 
        while True:
631
 
            if i > 0:
632
 
                candidate_dir = '%s/%s.%d' % (self.TEST_ROOT, short_id, i)
633
 
            else:
634
 
                candidate_dir = '%s/%s' % (self.TEST_ROOT, short_id)
635
 
            if os.path.exists(candidate_dir):
636
 
                i = i + 1
637
 
                continue
638
 
            else:
639
 
                self.test_dir = candidate_dir
640
 
                os.mkdir(self.test_dir)
641
 
                os.chdir(self.test_dir)
642
 
                break
 
597
                   .replace('__main__.', '')
 
598
        self.test_dir = osutils.pathjoin(self.TEST_ROOT, short_id)
 
599
        os.mkdir(self.test_dir)
 
600
        os.chdir(self.test_dir)
643
601
        os.environ['HOME'] = self.test_dir
644
602
        os.environ['APPDATA'] = self.test_dir
645
603
        def _leaveDirectory():
837
795
            # TODO: rbc 20060208
838
796
            return WorkingTreeFormat2().initialize(bzrdir.BzrDir.open(relpath))
839
797
 
840
 
    def assertIsDirectory(self, relpath, transport):
841
 
        """Assert that relpath within transport is a directory.
842
 
 
843
 
        This may not be possible on all transports; in that case it propagates
844
 
        a TransportNotPossible.
845
 
        """
846
 
        try:
847
 
            mode = transport.stat(relpath).st_mode
848
 
        except errors.NoSuchFile:
849
 
            self.fail("path %s is not a directory; no such file"
850
 
                      % (relpath))
851
 
        if not stat.S_ISDIR(mode):
852
 
            self.fail("path %s is not a directory; has mode %#o"
853
 
                      % (relpath, mode))
854
 
 
855
798
 
856
799
class ChrootedTestCase(TestCaseWithTransport):
857
800
    """A support class that provides readonly urls outside the local namespace.
898
841
    # This is still a little bogus, 
899
842
    # but only a little. Folk not using our testrunner will
900
843
    # have to delete their temp directories themselves.
901
 
    test_root = TestCaseInTempDir.TEST_ROOT
902
844
    if result.wasSuccessful() or not keep_output:
903
 
        if test_root is not None:
904
 
            print 'Deleting test root %s...' % test_root
905
 
            try:
906
 
                shutil.rmtree(test_root)
907
 
            finally:
908
 
                print
 
845
        if TestCaseInTempDir.TEST_ROOT is not None:
 
846
            shutil.rmtree(TestCaseInTempDir.TEST_ROOT) 
909
847
    else:
910
848
        print "Failed tests working directories are in '%s'\n" % TestCaseInTempDir.TEST_ROOT
911
849
    return result.wasSuccessful()
953
891
                   'bzrlib.tests.test_diff',
954
892
                   'bzrlib.tests.test_doc_generate',
955
893
                   'bzrlib.tests.test_errors',
956
 
                   'bzrlib.tests.test_escaped_store',
957
894
                   'bzrlib.tests.test_fetch',
958
895
                   'bzrlib.tests.test_gpg',
959
896
                   'bzrlib.tests.test_graph',
975
912
                   'bzrlib.tests.test_osutils',
976
913
                   'bzrlib.tests.test_permissions',
977
914
                   'bzrlib.tests.test_plugins',
978
 
                   'bzrlib.tests.test_progress',
979
 
                   'bzrlib.tests.test_reconcile',
980
915
                   'bzrlib.tests.test_repository',
981
916
                   'bzrlib.tests.test_revision',
982
917
                   'bzrlib.tests.test_revisionnamespaces',
997
932
                   'bzrlib.tests.test_transport',
998
933
                   'bzrlib.tests.test_tsort',
999
934
                   'bzrlib.tests.test_ui',
 
935
                   'bzrlib.tests.test_uncommit',
1000
936
                   'bzrlib.tests.test_upgrade',
1001
937
                   'bzrlib.tests.test_versionedfile',
1002
938
                   'bzrlib.tests.test_weave',