~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/launchpad/test_lp_api.py

  • Committer: Jonathan Lange
  • Date: 2009-12-17 03:40:41 UTC
  • mto: This revision was merged to the branch mainline in revision 4907.
  • Revision ID: jml@canonical.com-20091217034041-4mnvvzzikgt3u47k
Add some tests to check for version compatibility. Drop tests for
absence of bzrlib.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
 
import sys
19
 
 
20
18
from bzrlib import errors
21
 
from bzrlib.tests import TestCase
 
19
from bzrlib.tests import ModuleAvailableFeature, TestCase
 
20
 
 
21
 
 
22
launchpadlib_feature = ModuleAvailableFeature('launchpadlib')
22
23
 
23
24
 
24
25
class TestDependencyManagement(TestCase):
25
26
    """Tests for managing the dependency on launchpadlib."""
26
27
 
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.
30
 
        def import_lp_api():
31
 
            from bzrlib.plugins.launchpad import lp_api
32
 
            return lp_api
33
 
        real_launchpadlib = sys.modules.get('launchpadlib', None)
34
 
        sys.modules['launchpadlib'] = None
35
 
        self.addCleanup(
36
 
            sys.modules.__setitem__, 'launchpadlib', real_launchpadlib)
 
28
    _test_needs_features = [launchpadlib_feature]
 
29
 
 
30
    def setUp(self):
 
31
        TestCase.setUp(self)
 
32
        from bzrlib.plugins.launchpad import lp_api
 
33
        self.lp_api = lp_api
 
34
 
 
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)
 
40
 
 
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)
 
46
 
 
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()
 
53
 
 
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)
37
58
        self.assertRaises(
38
 
            errors.DependencyNotPresent, import_lp_api)
39
 
 
 
59
            errors.IncompatibleAPI,
 
60
            self.lp_api.check_launchpadlib_compatibility)