34
35
self.assert_(isinstance(bzrlib.version_string, str))
35
36
self.assert_(isinstance(bzrlib.version_info, tuple))
36
37
self.assertEqual(len(bzrlib.version_info), 5)
39
class TrivialObject(object):
40
"""This class allows assignment to any attribute."""
43
class TestAPIVersioning(TestCase):
45
def test_get_minimum_api_version_reads_api_minimum_version(self):
46
an_object = TrivialObject()
47
an_object.api_minimum_version = (0, 1, 2)
48
self.assertEqual((0, 1, 2),
49
bzrlib.api.get_minimum_api_version(an_object))
51
def test_get_minimum_api_version_fallsback_to_bzr_minimum_version(self):
52
an_object = TrivialObject()
53
self.assertEqual(bzrlib.api_minimum_version,
54
bzrlib.api.get_minimum_api_version(an_object))
56
def test_get_current_api_version_reads_api_current_version(self):
57
an_object = TrivialObject()
58
an_object.api_current_version = (3, 2, 1)
59
an_object.version_info = (1, 2, 3, "final", 0)
60
self.assertEqual((3, 2, 1),
61
bzrlib.api.get_current_api_version(an_object))
63
def test_get_current_api_version_fallsback_to_version_info(self):
64
an_object = TrivialObject()
65
an_object.version_info = (1, 2, 3, "final", 0)
66
self.assertEqual((1, 2, 3),
67
bzrlib.api.get_current_api_version(an_object))
69
def test_get_current_api_version_fallsback_to_bzrlib_version_info(self):
70
an_object = TrivialObject()
71
self.assertEqual(bzrlib.version_info[0:3],
72
bzrlib.api.get_current_api_version(an_object))
74
def test_require_any_api_wanted_one(self):
75
an_object = TrivialObject()
76
an_object.api_minimum_version = (1, 2, 3)
77
an_object.api_current_version = (4, 5, 6)
78
bzrlib.api.require_any_api(an_object, [(1, 2, 3)])
80
def test_require_any_api_wanted_first_compatible(self):
81
an_object = TrivialObject()
82
an_object.api_minimum_version = (1, 2, 3)
83
an_object.api_current_version = (4, 5, 6)
84
bzrlib.api.require_any_api(an_object, [(1, 2, 3), (5, 6, 7)])
86
def test_require_any_api_wanted_second_compatible(self):
87
an_object = TrivialObject()
88
an_object.api_minimum_version = (1, 2, 3)
89
an_object.api_current_version = (4, 5, 6)
90
bzrlib.api.require_any_api(an_object, [(5, 6, 7), (1, 2, 3)])
92
def test_require_any_api_wanted_none_compatible(self):
93
an_object = TrivialObject()
94
an_object.api_minimum_version = (1, 2, 3)
95
an_object.api_current_version = (4, 5, 6)
96
self.assertRaises(IncompatibleAPI, bzrlib.api.require_any_api,
97
an_object, [(1, 2, 2), (5, 6, 7)])
99
def test_require_api_wanted_is_minimum_is_ok(self):
100
an_object = TrivialObject()
101
an_object.api_minimum_version = (1, 2, 3)
102
an_object.api_current_version = (4, 5, 6)
103
bzrlib.api.require_api(an_object, (1, 2, 3))
105
def test_require_api_wanted_is_current_is_ok(self):
106
an_object = TrivialObject()
107
an_object.api_minimum_version = (1, 2, 3)
108
an_object.api_current_version = (4, 5, 6)
109
bzrlib.api.require_api(an_object, (4, 5, 6))
111
def test_require_api_wanted_is_above_minimum_is_ok(self):
112
an_object = TrivialObject()
113
an_object.api_minimum_version = (1, 2, 3)
114
an_object.api_current_version = (4, 5, 6)
115
bzrlib.api.require_api(an_object, (1, 2, 4))
117
def test_require_api_wanted_is_below_current_is_ok(self):
118
an_object = TrivialObject()
119
an_object.api_minimum_version = (1, 2, 3)
120
an_object.api_current_version = (4, 5, 6)
121
bzrlib.api.require_api(an_object, (4, 5, 5))
123
def test_require_api_wanted_is_below_minimum_raises(self):
124
an_object = TrivialObject()
125
an_object.api_minimum_version = (1, 2, 3)
126
an_object.api_current_version = (4, 5, 6)
127
err = self.assertRaises(IncompatibleAPI,
128
bzrlib.api.require_api, an_object, (1, 2, 2))
129
self.assertEqual(err.api, an_object)
130
self.assertEqual(err.wanted, (1, 2, 2))
131
self.assertEqual(err.minimum, (1, 2, 3))
132
self.assertEqual(err.current, (4, 5, 6))
134
def test_require_api_wanted_is_above_current_raises(self):
135
an_object = TrivialObject()
136
an_object.api_minimum_version = (1, 2, 3)
137
an_object.api_current_version = (4, 5, 6)
138
err = self.assertRaises(IncompatibleAPI,
139
bzrlib.api.require_api, an_object, (4, 5, 7))
140
self.assertEqual(err.api, an_object)
141
self.assertEqual(err.wanted, (4, 5, 7))
142
self.assertEqual(err.minimum, (1, 2, 3))
143
self.assertEqual(err.current, (4, 5, 6))