~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

transport implementations now tested consistently.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
import bzrlib.plugin
38
38
import bzrlib.store
39
39
import bzrlib.trace
 
40
from bzrlib.transport import urlescape
40
41
from bzrlib.trace import mutter
41
42
from bzrlib.tests.TestUtil import TestLoader, TestSuite
42
43
from bzrlib.tests.treeshape import build_tree_contents
156
157
    def printErrorList(self, flavour, errors):
157
158
        for test, err in errors:
158
159
            self.stream.writeln(self.separator1)
159
 
            self.stream.writeln("%s: %s" % (flavour,self.getDescription(test)))
 
160
            self.stream.writeln("%s: %s" % (flavour, self.getDescription(test)))
160
161
            if hasattr(test, '_get_log'):
161
162
                print >>self.stream
162
163
                print >>self.stream, \
163
 
                        ('vvvv[log from %s]' % test).ljust(78,'-')
 
164
                        ('vvvv[log from %s]' % test.id()).ljust(78,'-')
164
165
                print >>self.stream, test._get_log()
165
166
                print >>self.stream, \
166
 
                        ('^^^^[log from %s]' % test).ljust(78,'-')
 
167
                        ('^^^^[log from %s]' % test.id()).ljust(78,'-')
167
168
            self.stream.writeln(self.separator2)
168
169
            self.stream.writeln("%s" % err)
169
170
 
544
545
            os.chdir(_currentdir)
545
546
        self.addCleanup(_leaveDirectory)
546
547
        
547
 
    def build_tree(self, shape, line_endings='native'):
 
548
    def build_tree(self, shape, line_endings='native', transport=None):
548
549
        """Build a test tree according to a pattern.
549
550
 
550
551
        shape is a sequence of file specifications.  If the final
555
556
                             in binary mode, exact contents are written
556
557
                             in native mode, the line endings match the
557
558
                             default platform endings.
 
559
 
 
560
        :param transport: A transport to write to, for building trees on 
 
561
                          VFS's. If the transport is readonly or None,
 
562
                          "." is opened automatically.
558
563
        """
559
564
        # XXX: It's OK to just create them using forward slashes on windows?
 
565
        if transport is None or transport.is_readonly():
 
566
            transport = bzrlib.transport.get_transport(".")
560
567
        for name in shape:
561
568
            self.assert_(isinstance(name, basestring))
562
569
            if name[-1] == '/':
563
 
                os.mkdir(name[:-1])
 
570
                transport.mkdir(urlescape(name[:-1]))
564
571
            else:
565
572
                if line_endings == 'binary':
566
 
                    f = file(name, 'wb')
 
573
                    end = '\n'
567
574
                elif line_endings == 'native':
568
 
                    f = file(name, 'wt')
 
575
                    end = os.linesep
569
576
                else:
570
577
                    raise BzrError('Invalid line ending request %r' % (line_endings,))
571
 
                print >>f, "contents of", name
572
 
                f.close()
 
578
                content = "contents of %s%s" % (name, end)
 
579
                transport.put(urlescape(name), StringIO(content))
573
580
 
574
581
    def build_tree_contents(self, shape):
575
582
        build_tree_contents(shape)
688
695
                   'bzrlib.tests.test_workingtree',
689
696
                   'bzrlib.tests.test_xml',
690
697
                   ]
 
698
    test_transport_implementations = [
 
699
        'bzrlib.tests.test_transport_implementations']
691
700
 
692
701
    print '%10s: %s' % ('bzr', os.path.realpath(sys.argv[0]))
693
702
    print '%10s: %s' % ('bzrlib', bzrlib.__path__[0])
698
707
    # actually wrong, just "no such module".  We should probably override that
699
708
    # class, but for the moment just load them ourselves. (mbp 20051202)
700
709
    loader = TestLoader()
 
710
    from bzrlib.transport import TransportTestProviderAdapter
 
711
    adapter = TransportTestProviderAdapter()
 
712
    for mod_name in test_transport_implementations:
 
713
        mod = _load_module_by_name(mod_name)
 
714
        for test in iter_suite_tests(loader.loadTestsFromModule(mod)):
 
715
            suite.addTests(adapter.adapt(test))
701
716
    for mod_name in testmod_names:
702
717
        mod = _load_module_by_name(mod_name)
703
718
        suite.addTest(loader.loadTestsFromModule(mod))