~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

Merged mailine

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
 
65
65
class TestSkippedTest(TestCase):
66
66
    """Try running a test which is skipped, make sure it's reported properly."""
 
67
 
67
68
    def test_skipped_test(self):
68
69
        # must be hidden in here so it's not run as a real test
69
70
        def skipping_test():
72
73
        test = unittest.FunctionTestCase(skipping_test)
73
74
        result = runner.run(test)
74
75
        self.assertTrue(result.wasSuccessful())
 
76
 
 
77
 
 
78
class TestTransportProviderAdapter(TestCase):
 
79
    """A group of tests that test the transport implementation adaption core.
 
80
 
 
81
    This will be generalised in the future which is why it is in this 
 
82
    test file even though it is specific to transport tests at the moment.
 
83
    """
 
84
 
 
85
    def test_get_transport_permutations(self):
 
86
        # this checks that we the module get_test_permutations call
 
87
        # is made by the adapter get_transport_test_permitations method.
 
88
        class MockModule(object):
 
89
            def get_test_permutations(self):
 
90
                return sample_permutation
 
91
        sample_permutation = [(1,2), (3,4)]
 
92
        from bzrlib.transport import TransportTestProviderAdapter
 
93
        adapter = TransportTestProviderAdapter()
 
94
        self.assertEqual(sample_permutation,
 
95
                         adapter.get_transport_test_permutations(MockModule()))
 
96
 
 
97
    def test_adapter_checks_all_modules(self):
 
98
        # this checks that the adapter returns as many permurtations as
 
99
        # there are in all the registered# transport modules for there
 
100
        # - we assume if this matches its probably doing the right thing
 
101
        # especially in combination with the tests for setting the right
 
102
        # classes below.
 
103
        from bzrlib.transport import (TransportTestProviderAdapter,
 
104
                                      _get_transport_modules
 
105
                                      )
 
106
        modules = _get_transport_modules()
 
107
        permutation_count = 0
 
108
        for module in modules:
 
109
            permutation_count += len(reduce(getattr, 
 
110
                (module + ".get_test_permutations").split('.')[1:],
 
111
                 __import__(module))())
 
112
        input_test = TestTransportProviderAdapter(
 
113
            "test_adapter_sets_transport_class")
 
114
        adapter = TransportTestProviderAdapter()
 
115
        self.assertEqual(permutation_count,
 
116
                         len(list(iter(adapter.adapt(input_test)))))
 
117
 
 
118
    def test_adapter_sets_transport_class(self):
 
119
        # when the adapter adapts a test it needs to 
 
120
        # place one of the permutations from the transport
 
121
        # providers in each test case copy. This checks
 
122
        # that it does not just use the same one all the time.
 
123
        # and that the id is set correctly so that debugging is
 
124
        # easy.
 
125
        from bzrlib.transport.local import (LocalTransport,
 
126
                                            LocalRelpathServer,
 
127
                                            LocalAbspathServer,
 
128
                                            LocalURLServer
 
129
                                            )
 
130
        from bzrlib.transport.sftp import (SFTPTransport,
 
131
                                           SFTPAbsoluteServer,
 
132
                                           SFTPHomeDirServer,
 
133
                                           SFTPSiblingAbsoluteServer,
 
134
                                           )
 
135
        from bzrlib.transport.http import (HttpTransport,
 
136
                                           HttpServer
 
137
                                           )
 
138
        from bzrlib.transport.ftp import FtpTransport
 
139
        from bzrlib.transport.memory import (MemoryTransport,
 
140
                                             MemoryServer
 
141
                                             )
 
142
        from bzrlib.transport import TransportTestProviderAdapter
 
143
        # FIXME. What we want is a factory for the things
 
144
        # needed to test the implementation. I.e. for transport we want:
 
145
        # the class that connections should get; a local server factory
 
146
        # so we would want the following permutations:
 
147
        # LocalTransport relpath-factory
 
148
        # LocalTransport abspath-factory
 
149
        # LocalTransport file://-factory
 
150
        # SFTPTransport homedir-factory
 
151
        # SFTPTransport abssolute-factory
 
152
        # HTTPTransport http-factory
 
153
        # HTTPTransport https-factory
 
154
        # etc, but we are currently lacking in this, so print out that
 
155
        # this should be fixed.
 
156
        input_test = TestTransportProviderAdapter(
 
157
            "test_adapter_sets_transport_class")
 
158
        suite = TransportTestProviderAdapter().adapt(input_test)
 
159
        test_iter = iter(suite)
 
160
        http_test = test_iter.next()
 
161
        local_relpath_test = test_iter.next()
 
162
        local_abspath_test = test_iter.next()
 
163
        local_urlpath_test = test_iter.next()
 
164
        memory_test = test_iter.next()
 
165
        sftp_abs_test = test_iter.next()
 
166
        sftp_homedir_test = test_iter.next()
 
167
        sftp_sibling_abs_test = test_iter.next()
 
168
        # ftp_test = test_iter.next()
 
169
        self.assertRaises(StopIteration, test_iter.next)
 
170
        self.assertEqual(LocalTransport, local_relpath_test.transport_class)
 
171
        self.assertEqual(LocalRelpathServer, local_relpath_test.transport_server)
 
172
        
 
173
        self.assertEqual(LocalTransport, local_abspath_test.transport_class)
 
174
        self.assertEqual(LocalAbspathServer, local_abspath_test.transport_server)
 
175
 
 
176
        self.assertEqual(LocalTransport, local_urlpath_test.transport_class)
 
177
        self.assertEqual(LocalURLServer, local_urlpath_test.transport_server)
 
178
 
 
179
        self.assertEqual(SFTPTransport, sftp_abs_test.transport_class)
 
180
        self.assertEqual(SFTPAbsoluteServer, sftp_abs_test.transport_server)
 
181
        self.assertEqual(SFTPTransport, sftp_homedir_test.transport_class)
 
182
        self.assertEqual(SFTPHomeDirServer, sftp_homedir_test.transport_server)
 
183
        self.assertEqual(SFTPTransport, sftp_sibling_abs_test.transport_class)
 
184
        self.assertEqual(SFTPSiblingAbsoluteServer,
 
185
                         sftp_sibling_abs_test.transport_server)
 
186
 
 
187
        self.assertEqual(HttpTransport, http_test.transport_class)
 
188
        self.assertEqual(HttpServer, http_test.transport_server)
 
189
        # self.assertEqual(FtpTransport, ftp_test.transport_class)
 
190
 
 
191
        self.assertEqual(MemoryTransport, memory_test.transport_class)
 
192
        self.assertEqual(MemoryServer, memory_test.transport_server)
 
193
        
 
194
        # we could test all of them for .id, but two is probably sufficient.
 
195
        self.assertEqual("bzrlib.tests.test_selftest."
 
196
                         "TestTransportProviderAdapter."
 
197
                         "test_adapter_sets_transport_class(MemoryServer)",
 
198
                         memory_test.id())
 
199
        self.assertEqual("bzrlib.tests.test_selftest."
 
200
                         "TestTransportProviderAdapter."
 
201
                         "test_adapter_sets_transport_class(LocalRelpathServer)",
 
202
                         local_relpath_test.id())