~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Martin Pool
  • Date: 2006-01-12 06:37:23 UTC
  • mfrom: (1534.1.6 integration)
  • Revision ID: mbp@sourcefrog.net-20060112063723-4ec91b5ff30f0830
[merge] robertc-integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
import os
29
29
import re
30
30
import shutil
 
31
import stat
31
32
import sys
32
33
import tempfile
33
34
import unittest
44
45
import bzrlib.plugin
45
46
import bzrlib.store
46
47
import bzrlib.trace
 
48
from bzrlib.transport import urlescape
47
49
from bzrlib.trace import mutter
48
50
from bzrlib.tests.TestUtil import TestLoader, TestSuite
49
51
from bzrlib.tests.treeshape import build_tree_contents
163
165
    def printErrorList(self, flavour, errors):
164
166
        for test, err in errors:
165
167
            self.stream.writeln(self.separator1)
166
 
            self.stream.writeln("%s: %s" % (flavour,self.getDescription(test)))
 
168
            self.stream.writeln("%s: %s" % (flavour, self.getDescription(test)))
167
169
            if hasattr(test, '_get_log'):
168
170
                print >>self.stream
169
171
                print >>self.stream, \
170
 
                        ('vvvv[log from %s]' % test).ljust(78,'-')
 
172
                        ('vvvv[log from %s]' % test.id()).ljust(78,'-')
171
173
                print >>self.stream, test._get_log()
172
174
                print >>self.stream, \
173
 
                        ('^^^^[log from %s]' % test).ljust(78,'-')
 
175
                        ('^^^^[log from %s]' % test.id()).ljust(78,'-')
174
176
            self.stream.writeln(self.separator2)
175
177
            self.stream.writeln("%s" % err)
176
178
 
289
291
            raise AssertionError("value(s) %r not present in container %r" % 
290
292
                                 (missing, superlist))
291
293
 
 
294
    def assertTransportMode(self, transport, path, mode):
 
295
        """Fail if a path does not have mode mode.
 
296
        
 
297
        If modes are not supported on this platform, the test is skipped.
 
298
        """
 
299
        if sys.platform == 'win32':
 
300
            return
 
301
        path_stat = transport.stat(path)
 
302
        actual_mode = stat.S_IMODE(path_stat.st_mode)
 
303
        self.assertEqual(mode, actual_mode,
 
304
            'mode of %r incorrect (%o != %o)' % (path, mode, actual_mode))
 
305
 
292
306
    def _startLogFile(self):
293
307
        """Send bzr and test log messages to a temporary file.
294
308
 
562
576
            os.chdir(_currentdir)
563
577
        self.addCleanup(_leaveDirectory)
564
578
        
565
 
    def build_tree(self, shape, line_endings='native'):
 
579
    def build_tree(self, shape, line_endings='native', transport=None):
566
580
        """Build a test tree according to a pattern.
567
581
 
568
582
        shape is a sequence of file specifications.  If the final
573
587
                             in binary mode, exact contents are written
574
588
                             in native mode, the line endings match the
575
589
                             default platform endings.
 
590
 
 
591
        :param transport: A transport to write to, for building trees on 
 
592
                          VFS's. If the transport is readonly or None,
 
593
                          "." is opened automatically.
576
594
        """
577
595
        # XXX: It's OK to just create them using forward slashes on windows?
 
596
        if transport is None or transport.is_readonly():
 
597
            transport = bzrlib.transport.get_transport(".")
578
598
        for name in shape:
579
599
            self.assert_(isinstance(name, basestring))
580
600
            if name[-1] == '/':
581
 
                os.mkdir(name[:-1])
 
601
                transport.mkdir(urlescape(name[:-1]))
582
602
            else:
583
603
                if line_endings == 'binary':
584
 
                    f = file(name, 'wb')
 
604
                    end = '\n'
585
605
                elif line_endings == 'native':
586
 
                    f = file(name, 'wt')
 
606
                    end = os.linesep
587
607
                else:
588
608
                    raise BzrError('Invalid line ending request %r' % (line_endings,))
589
 
                print >>f, "contents of", name
590
 
                f.close()
 
609
                content = "contents of %s%s" % (name, end)
 
610
                transport.put(urlescape(name), StringIO(content))
591
611
 
592
612
    def build_tree_contents(self, shape):
593
613
        build_tree_contents(shape)
713
733
                   'bzrlib.tests.test_workingtree',
714
734
                   'bzrlib.tests.test_xml',
715
735
                   ]
 
736
    test_transport_implementations = [
 
737
        'bzrlib.tests.test_transport_implementations']
716
738
 
717
739
    TestCase.BZRPATH = osutils.pathjoin(
718
740
            osutils.realpath(osutils.dirname(bzrlib.__path__[0])), 'bzr')
725
747
    # actually wrong, just "no such module".  We should probably override that
726
748
    # class, but for the moment just load them ourselves. (mbp 20051202)
727
749
    loader = TestLoader()
 
750
    from bzrlib.transport import TransportTestProviderAdapter
 
751
    adapter = TransportTestProviderAdapter()
 
752
    for mod_name in test_transport_implementations:
 
753
        mod = _load_module_by_name(mod_name)
 
754
        for test in iter_suite_tests(loader.loadTestsFromModule(mod)):
 
755
            suite.addTests(adapter.adapt(test))
728
756
    for mod_name in testmod_names:
729
757
        mod = _load_module_by_name(mod_name)
730
758
        suite.addTest(loader.loadTestsFromModule(mod))