bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.1
by Vincent Ladeuil
Fix assert_ being deprecated by using assertTrue. |
1 |
# Copyright (C) 2005-2009, 2016 Canonical Ltd
|
1185.16.128
by Martin Pool
Expose library API version in bzrlib.bzr_version_info |
2 |
#
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
1185.16.128
by Martin Pool
Expose library API version in bzrlib.bzr_version_info |
16 |
|
17 |
"""Tests for library API infrastructure
|
|
18 |
||
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
19 |
This is specifically for things controlling the interface, such as versioning.
|
1185.16.128
by Martin Pool
Expose library API version in bzrlib.bzr_version_info |
20 |
Tests for particular parts of the library interface should be in specific
|
21 |
relevant test modules.
|
|
22 |
"""
|
|
23 |
||
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
24 |
import breezy |
25 |
import breezy.api |
|
26 |
from breezy.errors import IncompatibleAPI |
|
27 |
from breezy.tests import TestCase |
|
1185.16.128
by Martin Pool
Expose library API version in bzrlib.bzr_version_info |
28 |
|
29 |
class APITests(TestCase): |
|
30 |
||
31 |
def test_library_version(self): |
|
32 |
"""Library API version is exposed""" |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
33 |
self.assertTrue(isinstance(breezy.__version__, str)) |
34 |
self.assertTrue(isinstance(breezy.version_string, str)) |
|
35 |
self.assertTrue(isinstance(breezy.version_info, tuple)) |
|
36 |
self.assertEqual(len(breezy.version_info), 5) |
|
2550.2.2
by Robert Collins
Add helpers to get api versions from objects. |
37 |
|
38 |
||
39 |
class TrivialObject(object): |
|
40 |
"""This class allows assignment to any attribute.""" |
|
41 |
||
42 |
||
43 |
class TestAPIVersioning(TestCase): |
|
44 |
||
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), |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
49 |
breezy.api.get_minimum_api_version(an_object)) |
2550.2.2
by Robert Collins
Add helpers to get api versions from objects. |
50 |
|
51 |
def test_get_minimum_api_version_fallsback_to_bzr_minimum_version(self): |
|
52 |
an_object = TrivialObject() |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
53 |
self.assertEqual(breezy.api_minimum_version, |
54 |
breezy.api.get_minimum_api_version(an_object)) |
|
2550.2.2
by Robert Collins
Add helpers to get api versions from objects. |
55 |
|
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), |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
61 |
breezy.api.get_current_api_version(an_object)) |
2550.2.2
by Robert Collins
Add helpers to get api versions from objects. |
62 |
|
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), |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
67 |
breezy.api.get_current_api_version(an_object)) |
2550.2.2
by Robert Collins
Add helpers to get api versions from objects. |
68 |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
69 |
def test_get_current_api_version_fallsback_to_breezy_version_info(self): |
2550.2.2
by Robert Collins
Add helpers to get api versions from objects. |
70 |
an_object = TrivialObject() |
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
71 |
self.assertEqual(breezy.version_info[0:3], |
72 |
breezy.api.get_current_api_version(an_object)) |
|
2550.2.3
by Robert Collins
Add require_api API. |
73 |
|
3766.3.1
by Robert Collins
Add bzrlib.api.require_any_api, fixing bug 279447. |
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) |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
78 |
breezy.api.require_any_api(an_object, [(1, 2, 3)]) |
3766.3.1
by Robert Collins
Add bzrlib.api.require_any_api, fixing bug 279447. |
79 |
|
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) |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
84 |
breezy.api.require_any_api(an_object, [(1, 2, 3), (5, 6, 7)]) |
3766.3.1
by Robert Collins
Add bzrlib.api.require_any_api, fixing bug 279447. |
85 |
|
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) |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
90 |
breezy.api.require_any_api(an_object, [(5, 6, 7), (1, 2, 3)]) |
3766.3.1
by Robert Collins
Add bzrlib.api.require_any_api, fixing bug 279447. |
91 |
|
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) |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
96 |
self.assertRaises(IncompatibleAPI, breezy.api.require_any_api, |
3766.3.1
by Robert Collins
Add bzrlib.api.require_any_api, fixing bug 279447. |
97 |
an_object, [(1, 2, 2), (5, 6, 7)]) |
98 |
||
2550.2.3
by Robert Collins
Add require_api API. |
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) |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
103 |
breezy.api.require_api(an_object, (1, 2, 3)) |
2550.2.3
by Robert Collins
Add require_api API. |
104 |
|
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) |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
109 |
breezy.api.require_api(an_object, (4, 5, 6)) |
2550.2.3
by Robert Collins
Add require_api API. |
110 |
|
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) |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
115 |
breezy.api.require_api(an_object, (1, 2, 4)) |
2550.2.3
by Robert Collins
Add require_api API. |
116 |
|
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) |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
121 |
breezy.api.require_api(an_object, (4, 5, 5)) |
2550.2.3
by Robert Collins
Add require_api API. |
122 |
|
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, |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
128 |
breezy.api.require_api, an_object, (1, 2, 2)) |
2550.2.3
by Robert Collins
Add require_api API. |
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)) |
|
133 |
||
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, |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
139 |
breezy.api.require_api, an_object, (4, 5, 7)) |
2550.2.3
by Robert Collins
Add require_api API. |
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)) |