/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1185.51.1 by Martin Pool
Better message when failing to import a test suite.
1
# Copyright (C) 2005 by Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License version 2 as published by
5
# the Free Software Foundation.
6
#
7
# This program is distributed in the hope that it will be useful,
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
# GNU General Public License for more details.
11
#
12
# You should have received a copy of the GNU General Public License
13
# along with this program; if not, write to the Free Software
14
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
16
"""Tests for the test framework
17
"""
18
19
import os
20
import sys
1185.33.95 by Martin Pool
New TestSkipped facility, and tests for it.
21
import unittest
1185.51.1 by Martin Pool
Better message when failing to import a test suite.
22
1526.1.3 by Robert Collins
Merge from upstream.
23
from bzrlib.tests import (
24
                          _load_module_by_name,
25
                          TestCase,
26
                          TestCaseInTempDir,
27
                          TestSkipped,
28
                          TextTestRunner,
29
                          )
1185.51.1 by Martin Pool
Better message when failing to import a test suite.
30
31
32
class SelftestTests(TestCase):
33
34
    def test_import_tests(self):
35
        mod = _load_module_by_name('bzrlib.tests.test_selftest')
36
        self.assertEqual(mod.SelftestTests, SelftestTests)
37
38
    def test_import_test_failure(self):
39
        self.assertRaises(ImportError,
40
                          _load_module_by_name,
41
                          'bzrlib.no-name-yet')
42
43
44
class MetaTestLog(TestCase):
1526.1.1 by Robert Collins
Run the test suite with no locale as well as the default locale. Also add a test for build_tree_shape to selftest.
45
1185.51.1 by Martin Pool
Better message when failing to import a test suite.
46
    def test_logging(self):
47
        """Test logs are captured when a test fails."""
48
        self.log('a test message')
49
        self._log_file.flush()
50
        self.assertContainsRe(self._get_log(), 'a test message\n')
1185.33.95 by Martin Pool
New TestSkipped facility, and tests for it.
51
52
1526.1.1 by Robert Collins
Run the test suite with no locale as well as the default locale. Also add a test for build_tree_shape to selftest.
53
class TestTreeShape(TestCaseInTempDir):
54
55
    def test_unicode_paths(self):
56
        filename = u'hell\u00d8'
1526.1.4 by Robert Collins
forgot my self.
57
        try:
58
            self.build_tree_contents([(filename, 'contents of hello')])
59
        except UnicodeEncodeError:
60
            raise TestSkipped("can't build unicode working tree in "
61
                "filesystem encoding %s" % sys.getfilesystemencoding())
1526.1.1 by Robert Collins
Run the test suite with no locale as well as the default locale. Also add a test for build_tree_shape to selftest.
62
        self.failUnlessExists(filename)
1526.1.3 by Robert Collins
Merge from upstream.
63
64
1185.33.95 by Martin Pool
New TestSkipped facility, and tests for it.
65
class TestSkippedTest(TestCase):
66
    """Try running a test which is skipped, make sure it's reported properly."""
1530.1.1 by Robert Collins
Minimal infrastructure to test TransportTestProviderAdapter.
67
1185.33.95 by Martin Pool
New TestSkipped facility, and tests for it.
68
    def test_skipped_test(self):
69
        # must be hidden in here so it's not run as a real test
70
        def skipping_test():
71
            raise TestSkipped('test intentionally skipped')
1526.1.3 by Robert Collins
Merge from upstream.
72
        runner = TextTestRunner(stream=self._log_file)
1185.33.95 by Martin Pool
New TestSkipped facility, and tests for it.
73
        test = unittest.FunctionTestCase(skipping_test)
74
        result = runner.run(test)
75
        self.assertTrue(result.wasSuccessful())
1530.1.1 by Robert Collins
Minimal infrastructure to test TransportTestProviderAdapter.
76
77
78
class TestTransportProviderAdapter(TestCase):
79
80
    def test_adapter_sets_transport_class(self):
81
        from bzrlib.transport.local import (LocalTransport,
82
                                            LocalRelpathServer,
83
                                            LocalAbspathServer,
84
                                            LocalURLServer
85
                                            )
86
        from bzrlib.transport.sftp import (SFTPTransport,
87
                                           SFTPAbsoluteServer,
88
                                           SFTPHomeDirServer
89
                                           )
90
        from bzrlib.transport.http import (HttpTransport,
91
                                           HttpServer
92
                                           )
93
        from bzrlib.transport.ftp import FtpTransport
1530.1.3 by Robert Collins
transport implementations now tested consistently.
94
        from bzrlib.transport.memory import (MemoryTransport,
95
                                             MemoryServer
96
                                             )
1530.1.1 by Robert Collins
Minimal infrastructure to test TransportTestProviderAdapter.
97
        from bzrlib.transport import TransportTestProviderAdapter
98
        # FIXME. What we want is a factory for the things
99
        # needed to test the implementation. I.e. for transport we want:
100
        # the class that connections should get; a local server factory
101
        # so we would want the following permutations:
102
        # LocalTransport relpath-factory
103
        # LocalTransport abspath-factory
104
        # LocalTransport file://-factory
105
        # SFTPTransport homedir-factory
106
        # SFTPTransport abssolute-factory
107
        # HTTPTransport http-factory
108
        # HTTPTransport https-factory
109
        # etc, but we are currently lacking in this, so print out that
110
        # this should be fixed.
111
        print "TODO: test servers for all local permutations."
112
        print "Currently missing: FTP, HTTPS."
113
        input_test = TestTransportProviderAdapter(
114
            "test_adapter_sets_transport_class")
115
        suite = TransportTestProviderAdapter().adapt(input_test)
116
        test_iter = iter(suite)
117
        local_relpath_test = test_iter.next()
118
        local_abspath_test = test_iter.next()
119
        local_urlpath_test = test_iter.next()
120
        sftp_abs_test = test_iter.next()
121
        sftp_homedir_test = test_iter.next()
122
        http_test = test_iter.next()
1530.1.3 by Robert Collins
transport implementations now tested consistently.
123
        memory_test = test_iter.next()
1530.1.1 by Robert Collins
Minimal infrastructure to test TransportTestProviderAdapter.
124
        # ftp_test = test_iter.next()
125
        self.assertRaises(StopIteration, test_iter.next)
126
        self.assertEqual(LocalTransport, local_relpath_test.transport_class)
127
        self.assertEqual(LocalRelpathServer, local_relpath_test.transport_server)
128
        
129
        self.assertEqual(LocalTransport, local_abspath_test.transport_class)
130
        self.assertEqual(LocalAbspathServer, local_abspath_test.transport_server)
131
132
        self.assertEqual(LocalTransport, local_urlpath_test.transport_class)
133
        self.assertEqual(LocalURLServer, local_urlpath_test.transport_server)
134
135
        self.assertEqual(SFTPTransport, sftp_abs_test.transport_class)
136
        self.assertEqual(SFTPAbsoluteServer, sftp_abs_test.transport_server)
137
        self.assertEqual(SFTPTransport, sftp_homedir_test.transport_class)
138
        self.assertEqual(SFTPHomeDirServer, sftp_homedir_test.transport_server)
1530.1.3 by Robert Collins
transport implementations now tested consistently.
139
1530.1.1 by Robert Collins
Minimal infrastructure to test TransportTestProviderAdapter.
140
        self.assertEqual(HttpTransport, http_test.transport_class)
141
        self.assertEqual(HttpServer, http_test.transport_server)
142
        # self.assertEqual(FtpTransport, ftp_test.transport_class)
1530.1.3 by Robert Collins
transport implementations now tested consistently.
143
144
        self.assertEqual(MemoryTransport, memory_test.transport_class)
145
        self.assertEqual(MemoryServer, memory_test.transport_server)
1530.1.1 by Robert Collins
Minimal infrastructure to test TransportTestProviderAdapter.
146
        
1530.1.3 by Robert Collins
transport implementations now tested consistently.
147
        # we could test all of them for .id, but two is probably sufficient.
148
        self.assertEqual("bzrlib.tests.test_selftest."
149
                         "TestTransportProviderAdapter."
150
                         "test_adapter_sets_transport_class(MemoryServer)",
151
                         memory_test.id())
152
        self.assertEqual("bzrlib.tests.test_selftest."
153
                         "TestTransportProviderAdapter."
154
                         "test_adapter_sets_transport_class(LocalRelpathServer)",
155
                         local_relpath_test.id())