Rev 3117: Begin refactoring test_http.py into parameterized tests. in file:///v/home/vila/src/bzr/bugs/175524/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Dec 19 07:46:33 GMT 2007
At file:///v/home/vila/src/bzr/bugs/175524/
------------------------------------------------------------
revno: 3117
revision-id:v.ladeuil+lp at free.fr-20071219074629-nu5z8y56lp9o3m7f
parent: v.ladeuil+lp at free.fr-20071218213144-h276togzls9mi4g4
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 175524
timestamp: Wed 2007-12-19 08:46:29 +0100
message:
Begin refactoring test_http.py into parameterized tests.
added:
bzrlib/tests/test_http_implementations.py test_http_implementa-20071218210003-65nh81gglcfvurw6-1
modified:
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/http_server.py httpserver.py-20061012142527-m1yxdj1xazsf8d7s-1
bzrlib/tests/test_http.py testhttp.py-20051018020158-b2eef6e867c514d9
-------------- next part --------------
=== added file 'bzrlib/tests/test_http_implementations.py'
--- a/bzrlib/tests/test_http_implementations.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/test_http_implementations.py 2007-12-19 07:46:29 +0000
@@ -0,0 +1,107 @@
+# Copyright (C) 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+"""Tests for HTTP transports and servers implementations.
+
+(transport, server) implementations tested here are supplied by
+HTTPTestProviderAdapter. Note that a server is characterized by a request
+handler class.
+
+Transport implementations are normally tested via
+test_transport_implementations. The tests here are about the variations in HTTP
+protocol implementation to guarantee the robustness of our transports.
+"""
+
+from bzrlib import (
+ errors,
+ tests,
+ )
+from bzrlib.tests import (
+ http_server,
+ )
+from bzrlib.transport.http._urllib import HttpTransport_urllib
+
+
+try:
+ from bzrlib.transport.http._pycurl import PyCurlTransport
+ pycurl_present = True
+except errors.DependencyNotPresent:
+ pycurl_present = False
+
+class HTTPImplementationsTestProviderAdapter(tests.TestScenarioApplier):
+
+ def __init__(self):
+ transport_scenarios = [('urllib',
+ dict(_transport=HttpTransport_urllib,
+ _server=http_server.HttpServer_urllib,
+ _qualified_prefix='http+urllib',
+ )),]
+ if pycurl_present:
+ transport_scenarios.append(
+ ('pycurl', dict(_transport=PyCurlTransport,
+ _server=http_server.HttpServer_PyCurl,
+ _qualified_prefix='http+pycurl',
+ )))
+ self.scenarios = transport_scenarios
+
+
+def load_tests(standard_tests, module, loader):
+ """Multiply tests for http clients and protocol versions."""
+ adapter = HTTPImplementationsTestProviderAdapter()
+ result = loader.suiteClass()
+ for test in tests.iter_suite_tests(standard_tests):
+ result.addTests(adapter.adapt(test))
+ return result
+
+
+class TestHttpTransportUrls(tests.TestCase):
+ """Test the http urls."""
+
+ def test_abs_url(self):
+ """Construction of absolute http URLs"""
+ t = self._transport('http://bazaar-vcs.org/bzr/bzr.dev/')
+ eq = self.assertEqualDiff
+ eq(t.abspath('.'), 'http://bazaar-vcs.org/bzr/bzr.dev')
+ eq(t.abspath('foo/bar'), 'http://bazaar-vcs.org/bzr/bzr.dev/foo/bar')
+ eq(t.abspath('.bzr'), 'http://bazaar-vcs.org/bzr/bzr.dev/.bzr')
+ eq(t.abspath('.bzr/1//2/./3'),
+ 'http://bazaar-vcs.org/bzr/bzr.dev/.bzr/1/2/3')
+
+ def test_invalid_http_urls(self):
+ """Trap invalid construction of urls"""
+ t = self._transport('http://bazaar-vcs.org/bzr/bzr.dev/')
+ self.assertRaises(errors.InvalidURL,
+ self._transport,
+ 'http://http://bazaar-vcs.org/bzr/bzr.dev/')
+
+ def test_http_root_urls(self):
+ """Construction of URLs from server root"""
+ t = self._transport('http://bzr.ozlabs.org/')
+ eq = self.assertEqualDiff
+ eq(t.abspath('.bzr/tree-version'),
+ 'http://bzr.ozlabs.org/.bzr/tree-version')
+
+ def test_http_impl_urls(self):
+ """There are servers which ask for particular clients to connect"""
+ server = self._server()
+ try:
+ server.setUp()
+ url = server.get_url()
+ self.assertTrue(url.startswith('%s://' % self._qualified_prefix))
+ finally:
+ server.tearDown()
+
+
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2007-12-11 14:26:18 +0000
+++ b/bzrlib/tests/__init__.py 2007-12-19 07:46:29 +0000
@@ -2435,6 +2435,7 @@
'bzrlib.tests.test_help',
'bzrlib.tests.test_hooks',
'bzrlib.tests.test_http',
+ 'bzrlib.tests.test_http_implementations',
'bzrlib.tests.test_http_response',
'bzrlib.tests.test_https_ca_bundle',
'bzrlib.tests.test_identitymap',
=== modified file 'bzrlib/tests/http_server.py'
--- a/bzrlib/tests/http_server.py 2007-12-18 13:53:04 +0000
+++ b/bzrlib/tests/http_server.py 2007-12-19 07:46:29 +0000
@@ -445,6 +445,7 @@
self._local_path_parts = self._home_dir.split(os.path.sep)
self._http_base_url = None
+ # Create the server thread
self._http_starting = threading.Lock()
self._http_starting.acquire()
self._http_thread = threading.Thread(target=self._http_start)
=== modified file 'bzrlib/tests/test_http.py'
--- a/bzrlib/tests/test_http.py 2007-12-18 13:53:04 +0000
+++ b/bzrlib/tests/test_http.py 2007-12-19 07:46:29 +0000
@@ -226,62 +226,7 @@
f.credentials[0])
-class TestHttpTransportUrls(object):
- """Test the http urls.
-
- This MUST be used by daughter classes that also inherit from
- TestCase.
-
- We can't inherit directly from TestCase or the
- test framework will try to create an instance which cannot
- run, its implementation being incomplete.
- """
-
- def test_abs_url(self):
- """Construction of absolute http URLs"""
- t = self._transport('http://bazaar-vcs.org/bzr/bzr.dev/')
- eq = self.assertEqualDiff
- eq(t.abspath('.'), 'http://bazaar-vcs.org/bzr/bzr.dev')
- eq(t.abspath('foo/bar'), 'http://bazaar-vcs.org/bzr/bzr.dev/foo/bar')
- eq(t.abspath('.bzr'), 'http://bazaar-vcs.org/bzr/bzr.dev/.bzr')
- eq(t.abspath('.bzr/1//2/./3'),
- 'http://bazaar-vcs.org/bzr/bzr.dev/.bzr/1/2/3')
-
- def test_invalid_http_urls(self):
- """Trap invalid construction of urls"""
- t = self._transport('http://bazaar-vcs.org/bzr/bzr.dev/')
- self.assertRaises(errors.InvalidURL,
- self._transport,
- 'http://http://bazaar-vcs.org/bzr/bzr.dev/')
-
- def test_http_root_urls(self):
- """Construction of URLs from server root"""
- t = self._transport('http://bzr.ozlabs.org/')
- eq = self.assertEqualDiff
- eq(t.abspath('.bzr/tree-version'),
- 'http://bzr.ozlabs.org/.bzr/tree-version')
-
- def test_http_impl_urls(self):
- """There are servers which ask for particular clients to connect"""
- server = self._server()
- try:
- server.setUp()
- url = server.get_url()
- self.assertTrue(url.startswith('%s://' % self._qualified_prefix))
- finally:
- server.tearDown()
-
-
-class TestHttpUrls_urllib(TestHttpTransportUrls, tests.TestCase):
- """Test http urls with urllib"""
-
- _transport = HttpTransport_urllib
- _server = http_server.HttpServer_urllib
- _qualified_prefix = 'http+urllib'
-
-
-class TestHttpUrls_pycurl(TestWithTransport_pycurl, TestHttpTransportUrls,
- tests.TestCase):
+class TestHttpUrls_pycurl(TestWithTransport_pycurl, tests.TestCase):
"""Test http urls with pycurl"""
_server = http_server.HttpServer_PyCurl
More information about the bazaar-commits
mailing list