Rev 4924: Convert a bunch more features over to ModuleAvailableFeature in http://bazaar.launchpad.net/~jameinel/bzr/2.1.0rc1-module-available
John Arbash Meinel
john at arbash-meinel.com
Mon Dec 21 19:41:47 GMT 2009
At http://bazaar.launchpad.net/~jameinel/bzr/2.1.0rc1-module-available
------------------------------------------------------------
revno: 4924
revision-id: john at arbash-meinel.com-20091221194138-pmi7ygnbg69ijxcb
parent: john at arbash-meinel.com-20091221192110-lciyclb7obvnflpf
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1.0rc1-module-available
timestamp: Mon 2009-12-21 13:41:38 -0600
message:
Convert a bunch more features over to ModuleAvailableFeature
-------------- next part --------------
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2009-12-18 08:22:42 +0000
+++ b/bzrlib/tests/__init__.py 2009-12-21 19:41:38 +0000
@@ -4278,6 +4278,9 @@
return self.module_name
+ParamikoFeature = ModuleAvailableFeature('paramiko')
+
+
def probe_unicode_in_user_encoding():
"""Try to encode several unicode strings to use in unicode-aware tests.
@@ -4333,23 +4336,6 @@
HTTPSServerFeature = _HTTPSServerFeature()
-class _ParamikoFeature(Feature):
- """Is paramiko available?"""
-
- def _probe(self):
- try:
- from bzrlib.transport.sftp import SFTPAbsoluteServer
- return True
- except errors.ParamikoNotPresent:
- return False
-
- def feature_name(self):
- return "Paramiko"
-
-
-ParamikoFeature = _ParamikoFeature()
-
-
class _UnicodeFilename(Feature):
"""Does the filesystem support Unicode filenames?"""
@@ -4460,20 +4446,7 @@
CaseInsensitiveFilesystemFeature = _CaseInsensitiveFilesystemFeature()
-class _SubUnitFeature(Feature):
- """Check if subunit is available."""
-
- def _probe(self):
- try:
- import subunit
- return True
- except ImportError:
- return False
-
- def feature_name(self):
- return 'subunit'
-
-SubUnitFeature = _SubUnitFeature()
+SubUnitFeature = ModuleAvailableFeature('subunit')
# Only define SubUnitBzrRunner if subunit is available.
try:
from subunit import TestProtocolClient
=== modified file 'bzrlib/tests/blackbox/test_selftest.py'
--- a/bzrlib/tests/blackbox/test_selftest.py 2009-08-24 22:32:53 +0000
+++ b/bzrlib/tests/blackbox/test_selftest.py 2009-12-21 19:41:38 +0000
@@ -78,10 +78,7 @@
def test_transport_set_to_sftp(self):
# Test that we can pass a transport to the selftest core - sftp
# version.
- try:
- import bzrlib.transport.sftp
- except ParamikoNotPresent:
- raise TestSkipped("Paramiko not present")
+ self.requireFeature(tests.ParamikoFeature)
params = self.get_params_passed_to_core('selftest --transport=sftp')
self.assertEqual(bzrlib.transport.sftp.SFTPAbsoluteServer,
params[1]["transport"])
=== modified file 'bzrlib/tests/features.py'
--- a/bzrlib/tests/features.py 2009-08-20 04:57:58 +0000
+++ b/bzrlib/tests/features.py 2009-12-21 19:41:38 +0000
@@ -15,21 +15,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-from bzrlib.tests import Feature
-
-
-class _ApportFeature(Feature):
-
- def _probe(self):
- try:
- import apport
- except ImportError, e:
- return False
- else:
- return True
-
- def feature_name(self):
- return 'apport'
-
-
-ApportFeature = _ApportFeature()
+from bzrlib import tests
+
+
+ApportFeature = tests.ModuleAvailableFeature('apport')
+pycurl = tests.ModuleAvailableFeature('pycurl')
=== modified file 'bzrlib/tests/test_bencode.py'
--- a/bzrlib/tests/test_bencode.py 2009-06-04 17:12:29 +0000
+++ b/bzrlib/tests/test_bencode.py 2009-12-21 19:41:38 +0000
@@ -23,32 +23,19 @@
suite = loader.suiteClass()
import bzrlib.util._bencode_py as py_module
scenarios = [('python', {'bencode': py_module})]
- if CompiledBencodeFeature.available():
- import bzrlib._bencode_pyx as c_module
- scenarios.append(('C', {'bencode': c_module}))
+ if compiled_bencode.available():
+ scenarios.append(('C', {'bencode': compiled_bencode.module}))
else:
# the compiled module isn't available, so we add a failing test
class FailWithoutFeature(tests.TestCase):
def test_fail(self):
- self.requireFeature(CompiledBencodeFeature)
+ self.requireFeature(compiled_bencode)
suite.addTest(loader.loadTestsFromTestCase(FailWithoutFeature))
tests.multiply_tests(standard_tests, scenarios, suite)
return suite
-class _CompiledBencodeFeature(tests.Feature):
-
- def _probe(self):
- try:
- import bzrlib._bencode_pyx
- except ImportError:
- return False
- return True
-
- def feature_name(self):
- return 'bzrlib._bencode_pyx'
-
-CompiledBencodeFeature = _CompiledBencodeFeature()
+compiled_bencode = tests.ModuleAvailableFeature('bzrlib._bencode_pyx')
class TestBencodeDecode(tests.TestCase):
=== modified file 'bzrlib/tests/test_diff.py'
--- a/bzrlib/tests/test_diff.py 2009-12-08 21:37:36 +0000
+++ b/bzrlib/tests/test_diff.py 2009-12-21 19:41:38 +0000
@@ -63,19 +63,7 @@
AttribFeature = _AttribFeature()
-class _CompiledPatienceDiffFeature(Feature):
-
- def _probe(self):
- try:
- import bzrlib._patiencediff_c
- except ImportError:
- return False
- return True
-
- def feature_name(self):
- return 'bzrlib._patiencediff_c'
-
-CompiledPatienceDiffFeature = _CompiledPatienceDiffFeature()
+compiled_patiencediff = tests.ModuleAvailableFeature('bzrlib._patiencediff_c')
def udiff_lines(old, new, allow_binary=False):
@@ -1156,7 +1144,7 @@
class TestPatienceDiffLib_c(TestPatienceDiffLib):
- _test_needs_features = [CompiledPatienceDiffFeature]
+ _test_needs_features = [compiled_patiencediff]
def setUp(self):
super(TestPatienceDiffLib_c, self).setUp()
@@ -1252,7 +1240,7 @@
class TestPatienceDiffLibFiles_c(TestPatienceDiffLibFiles):
- _test_needs_features = [CompiledPatienceDiffFeature]
+ _test_needs_features = [compiled_patiencediff]
def setUp(self):
super(TestPatienceDiffLibFiles_c, self).setUp()
@@ -1264,7 +1252,7 @@
class TestUsingCompiledIfAvailable(TestCase):
def test_PatienceSequenceMatcher(self):
- if CompiledPatienceDiffFeature.available():
+ if compiled_patiencediff.available():
from bzrlib._patiencediff_c import PatienceSequenceMatcher_c
self.assertIs(PatienceSequenceMatcher_c,
bzrlib.patiencediff.PatienceSequenceMatcher)
@@ -1274,7 +1262,7 @@
bzrlib.patiencediff.PatienceSequenceMatcher)
def test_unique_lcs(self):
- if CompiledPatienceDiffFeature.available():
+ if compiled_patiencediff.available():
from bzrlib._patiencediff_c import unique_lcs_c
self.assertIs(unique_lcs_c,
bzrlib.patiencediff.unique_lcs)
@@ -1284,7 +1272,7 @@
bzrlib.patiencediff.unique_lcs)
def test_recurse_matches(self):
- if CompiledPatienceDiffFeature.available():
+ if compiled_patiencediff.available():
from bzrlib._patiencediff_c import recurse_matches_c
self.assertIs(recurse_matches_c,
bzrlib.patiencediff.recurse_matches)
=== modified file 'bzrlib/tests/test_http.py'
--- a/bzrlib/tests/test_http.py 2009-12-04 15:22:23 +0000
+++ b/bzrlib/tests/test_http.py 2009-12-21 19:41:38 +0000
@@ -48,6 +48,7 @@
deprecated_in,
)
from bzrlib.tests import (
+ features,
http_server,
http_utils,
)
@@ -61,11 +62,8 @@
)
-try:
+if features.pycurl.available():
from bzrlib.transport.http._pycurl import PyCurlTransport
- pycurl_present = True
-except errors.DependencyNotPresent:
- pycurl_present = False
def load_tests(standard_tests, module, loader):
@@ -84,7 +82,7 @@
_server=http_server.HttpServer_urllib,
_qualified_prefix='http+urllib',)),
]
- if pycurl_present:
+ if features.pycurl.available():
transport_scenarios.append(
('pycurl', dict(_transport=PyCurlTransport,
_server=http_server.HttpServer_PyCurl,
@@ -156,7 +154,7 @@
activity_scenarios.append(
('urllib,https', dict(_activity_server=ActivityHTTPSServer,
_transport=_urllib.HttpTransport_urllib,)),)
- if pycurl_present:
+ if features.pycurl.available():
activity_scenarios.append(
('pycurl,http', dict(_activity_server=ActivityHTTPServer,
_transport=PyCurlTransport,)),)
@@ -376,11 +374,8 @@
"""Test case to inherit from if pycurl is present"""
def _get_pycurl_maybe(self):
- try:
- from bzrlib.transport.http._pycurl import PyCurlTransport
- return PyCurlTransport
- except errors.DependencyNotPresent:
- raise tests.TestSkipped('pycurl not present')
+ self.requireFeature(features.pycurl)
+ return PyCurlTransport
_transport = property(_get_pycurl_maybe)
@@ -603,7 +598,9 @@
protocol_version=self._protocol_version)
def _testing_pycurl(self):
- return pycurl_present and self._transport == PyCurlTransport
+ # TODO: This is duplicated for lots of the classes in this file
+ return (features.pycurl.available()
+ and self._transport == PyCurlTransport)
class WallRequestHandler(http_server.TestingHTTPRequestHandler):
@@ -718,7 +715,7 @@
_req_handler_class = BadProtocolRequestHandler
def setUp(self):
- if pycurl_present and self._transport == PyCurlTransport:
+ if self._testing_pycurl():
raise tests.TestNotApplicable(
"pycurl doesn't check the protocol version")
super(TestBadProtocolServer, self).setUp()
@@ -1187,7 +1184,9 @@
self._old_env = {}
def _testing_pycurl(self):
- return pycurl_present and self._transport == PyCurlTransport
+ # TODO: This is duplicated for lots of the classes in this file
+ return (features.pycurl.available()
+ and self._transport == PyCurlTransport)
def create_transport_secondary_server(self):
"""Creates an http server that will serve files with
@@ -1389,7 +1388,8 @@
"""
def setUp(self):
- if pycurl_present and self._transport == PyCurlTransport:
+ if (features.pycurl.available()
+ and self._transport == PyCurlTransport):
raise tests.TestNotApplicable(
"pycurl doesn't redirect silently annymore")
super(TestHTTPSilentRedirections, self).setUp()
@@ -1507,7 +1507,9 @@
return self._auth_server(protocol_version=self._protocol_version)
def _testing_pycurl(self):
- return pycurl_present and self._transport == PyCurlTransport
+ # TODO: This is duplicated for lots of the classes in this file
+ return (features.pycurl.available()
+ and self._transport == PyCurlTransport)
def get_user_url(self, user, password):
"""Build an url embedding user and password"""
More information about the bazaar-commits
mailing list