Rev 3989: Workaround SSLFile wrong readline prototype and fix bogus tests. in file:///net/bigmamac/Volumes/home/vila/src/bzr/bugs/httplib-broken-readline/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Mon Feb 9 18:25:46 GMT 2009
At file:///net/bigmamac/Volumes/home/vila/src/bzr/bugs/httplib-broken-readline/
------------------------------------------------------------
revno: 3989
revision-id: v.ladeuil+lp at free.fr-20090209182543-nb0220ksr5xa20pg
parent: pqm at pqm.ubuntu.com-20090209040048-4w0lmgdasmdw5xdn
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: httplib-broken-readline
timestamp: Mon 2009-02-09 19:25:43 +0100
message:
Workaround SSLFile wrong readline prototype and fix bogus tests.
* bzrlib/tests/test_read_bundle.py:
(load_tests): Not all tests are parametrized.
(TestDeprecations): Deprecate read_bundle_from_url.
(TestReadBundleFromURL.test_read_mergeable_from_url): Test
read_mergeable_from_url instead of read_bundle_from_url which has
no possible_transports parameter and is deprecated.
(TestReadBundleFromURL.test_read_mergeable_respects_possible_transports):
Fix the test so that it respects the transport class it's supposed
to use.
* bzrlib/transport/http/_urllib2_wrappers.py:
(_ReportingFileSocket.readline): Workaround bug in httplib for
python-2.4 and 2.5.
-------------- next part --------------
=== modified file 'bzrlib/bundle/__init__.py'
--- a/bzrlib/bundle/__init__.py 2008-10-01 05:40:45 +0000
+++ b/bzrlib/bundle/__init__.py 2009-02-09 18:25:43 +0000
@@ -14,6 +14,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+from bzrlib.symbol_versioning import deprecated_function, deprecated_in
from bzrlib.lazy_import import lazy_import
lazy_import(globals(), """
from bzrlib import (
@@ -29,6 +30,7 @@
from bzrlib.trace import note
+ at deprecated_function(deprecated_in((1, 12, 0)))
def read_bundle_from_url(url):
return read_mergeable_from_url(url, _do_directive=False)
=== modified file 'bzrlib/tests/test_read_bundle.py'
--- a/bzrlib/tests/test_read_bundle.py 2008-04-01 19:30:25 +0000
+++ b/bzrlib/tests/test_read_bundle.py 2009-02-09 18:25:43 +0000
@@ -23,6 +23,7 @@
from bzrlib.bundle.serializer import write_bundle
import bzrlib.bzrdir
import bzrlib.errors as errors
+from bzrlib.symbol_versioning import deprecated_in
from bzrlib import tests
from bzrlib.tests.test_transport import TestTransportImplementation
from bzrlib.tests.test_transport_implementations import TransportTestProviderAdapter
@@ -34,9 +35,15 @@
def load_tests(standard_tests, module, loader):
"""Multiply tests for tranport implementations."""
result = loader.suiteClass()
+ transport_tests, remaining_tests = tests.split_suite_by_condition(
+ standard_tests, tests.condition_isinstance((TestReadBundleFromURL)))
+
adapter = TransportTestProviderAdapter()
- for test in tests.iter_suite_tests(standard_tests):
- result.addTests(adapter.adapt(test))
+ tests.adapt_tests(transport_tests, adapter, result)
+
+ # No parametrization for the remaining tests
+ result.addTests(remaining_tests)
+
return result
@@ -60,6 +67,25 @@
return out, wt
+class TestDeprecations(tests.TestCaseInTempDir):
+
+ def create_test_bundle(self):
+ out, wt = create_bundle_file(self)
+ f = open('test_bundle', 'wb')
+ f.write(out.getvalue())
+ f.close()
+ return wt
+
+ def test_read_bundle_from_url_deprecated(self):
+ wt = self.create_test_bundle()
+ t = bzrlib.transport.get_transport(self.test_dir)
+ url = t.abspath('test_bundle')
+ self.callDeprecated([deprecated_in((1, 12, 0))
+ % 'bzrlib.bundle.read_bundle_from_url'],
+ bzrlib.bundle.read_bundle_from_url,
+ url)
+
+
class TestReadBundleFromURL(TestTransportImplementation):
"""Test that read_bundle works properly across multiple transports"""
@@ -77,13 +103,20 @@
self.log('Put to: %s', self.get_url('test_bundle'))
return wt
- def test_read_bundle_from_url(self):
+ def test_read_mergeable_from_url(self):
self._captureVar('BZR_NO_SMART_VFS', None)
wt = self.create_test_bundle()
if wt is None:
return
- info = bzrlib.bundle.read_bundle_from_url(
- unicode(self.get_url('test_bundle')))
+ # read_mergeable_from_url will invoke get_transport which may *not*
+ # respect self._transport (i.e. returns a transport that is different
+ # from the one we want to test, so we must inject a correct transport
+ # into possible_transports first.
+ t = self.get_transport('test_bundle')
+ possible_transports = [t]
+ info = bzrlib.bundle.read_mergeable_from_url(
+ unicode(self.get_url('test_bundle')),
+ possible_transports=possible_transports)
revision = info.real_revisions[-1]
self.assertEqual('commit-1', revision.revision_id)
@@ -95,19 +128,28 @@
if wt is None:
return
- self.assertRaises(errors.NotABundle,
- bzrlib.bundle.read_bundle_from_url,
+ self.assertRaises(errors.NotABundle,
+ bzrlib.bundle.read_mergeable_from_url,
self.get_url('tree'))
- self.assertRaises(errors.NotABundle,
- bzrlib.bundle.read_bundle_from_url,
+ self.assertRaises(errors.NotABundle,
+ bzrlib.bundle.read_mergeable_from_url,
self.get_url('tree/a'))
- def test_read_mergeable_populates_possible_transports(self):
+ def test_read_mergeable_respects_possible_transports(self):
+ t = self.get_transport('test_bundle')
+ if not isinstance(t, bzrlib.transport.ConnectedTransport):
+ # There is no point testing transport reuse for not connected
+ # transports (the test will fail even).
+ return
self._captureVar('BZR_NO_SMART_VFS', None)
wt = self.create_test_bundle()
if wt is None:
return
- possible_transports = []
+ # read_mergeable_from_url will invoke get_transport which may *not*
+ # respect self._transport (i.e. returns a transport that is different
+ # from the one we want to test, so we must inject a correct transport
+ # into possible_transports first.
+ possible_transports = [t]
url = unicode(self.get_url('test_bundle'))
info = bzrlib.bundle.read_mergeable_from_url(url,
possible_transports=possible_transports)
=== modified file 'bzrlib/transport/http/_urllib2_wrappers.py'
--- a/bzrlib/transport/http/_urllib2_wrappers.py 2009-01-29 14:27:28 +0000
+++ b/bzrlib/transport/http/_urllib2_wrappers.py 2009-02-09 18:25:43 +0000
@@ -79,8 +79,13 @@
self._report_activity(len(s), 'read')
return s
- def readline(self, size=-1):
- s = self.filesock.readline(size)
+ def readline(self):
+ # This should be readline(self, size=-1), but httplib in python 2.4 and
+ # 2.5 defines a SSLFile wrapper whose readline method lacks the size
+ # parameter. So until we drop support for 2.4 and 2.5 and since we
+ # don't *need* the size parameter we'll stay with readline(self)
+ # -- vila 20090209
+ s = self.filesock.readline()
self._report_activity(len(s), 'read')
return s
More information about the bazaar-commits
mailing list