15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
18
from bzrlib import errors
21
from bzrlib.tests import TestCase
19
from bzrlib.tests import ModuleAvailableFeature, TestCase
22
launchpadlib_feature = ModuleAvailableFeature('launchpadlib')
24
25
class TestDependencyManagement(TestCase):
25
26
"""Tests for managing the dependency on launchpadlib."""
27
def test_launchpadlib_not_available(self):
28
# We raise an error if you try to get the launchpadlib api wrapper
29
# when launchpadlib itself is not available.
31
from bzrlib.plugins.launchpad import lp_api
33
real_launchpadlib = sys.modules.get('launchpadlib', None)
34
sys.modules['launchpadlib'] = None
36
sys.modules.__setitem__, 'launchpadlib', real_launchpadlib)
28
_test_needs_features = [launchpadlib_feature]
32
from bzrlib.plugins.launchpad import lp_api
35
def patch(self, obj, name, value):
36
"""Temporarily set the 'name' attribute of 'obj' to 'value'."""
37
real_value = getattr(obj, name)
38
setattr(obj, name, value)
39
self.addCleanup(setattr, obj, name, real_value)
41
def test_get_launchpadlib_version(self):
42
# parse_launchpadlib_version returns a tuple of a version number of
43
# the style used by launchpadlib.
44
version_info = self.lp_api.parse_launchpadlib_version('1.5.1')
45
self.assertEqual((1, 5, 1), version_info)
47
def test_supported_launchpadlib_version(self):
48
launchpadlib = launchpadlib_feature.module
49
self.patch(launchpadlib, '__version__', '1.5.1')
50
self.lp_api.MINIMUM_LAUNCHPADLIB_VERSION = (1, 5, 1)
51
# Doesn't raise an exception.
52
self.lp_api.check_launchpadlib_compatibility()
54
def test_unsupported_launchpadlib_version(self):
55
launchpadlib = launchpadlib_feature.module
56
self.patch(launchpadlib, '__version__', '1.5.0')
57
self.lp_api.MINIMUM_LAUNCHPADLIB_VERSION = (1, 5, 1)
38
errors.DependencyNotPresent, import_lp_api)
59
errors.IncompatibleAPI,
60
self.lp_api.check_launchpadlib_compatibility)