bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
7408.3.2
by Jelmer Vernooij
Add some tests. |
1 |
# Copyright (C) 2019 Breezy Developers
|
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
|
|
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
16 |
||
17 |
import os |
|
18 |
||
19 |
from ..propose import ( |
|
|
7445.1.2
by Jelmer Vernooij
Add test. |
20 |
determine_title, |
|
7408.3.2
by Jelmer Vernooij
Add some tests. |
21 |
get_proposal_by_url, |
22 |
get_hoster, |
|
23 |
Hoster, |
|
24 |
MergeProposal, |
|
25 |
UnsupportedHoster, |
|
26 |
)
|
|
27 |
from .. import ( |
|
28 |
propose as _mod_propose, |
|
29 |
registry, |
|
30 |
urlutils, |
|
31 |
)
|
|
32 |
||
33 |
from .. import ( |
|
34 |
tests, |
|
35 |
)
|
|
36 |
||
37 |
||
38 |
class SampleMergeProposal(MergeProposal): |
|
39 |
"""Sample merge proposal.""" |
|
40 |
||
41 |
||
42 |
class SampleHoster(Hoster): |
|
43 |
||
44 |
_locations = [] |
|
45 |
||
46 |
@classmethod
|
|
47 |
def _add_location(cls, url): |
|
48 |
cls._locations.append(url) |
|
49 |
||
50 |
@classmethod
|
|
51 |
def probe_from_url(cls, url, possible_transports=None): |
|
52 |
for b in cls._locations: |
|
53 |
if url.startswith(b): |
|
54 |
return cls() |
|
55 |
raise UnsupportedHoster(url) |
|
56 |
||
57 |
def hosts(self, branch): |
|
58 |
for b in self._locations: |
|
59 |
if branch.user_url.startswith(b): |
|
60 |
return True |
|
61 |
return False |
|
62 |
||
63 |
@classmethod
|
|
64 |
def iter_instances(cls): |
|
65 |
return iter([cls()]) |
|
66 |
||
67 |
def get_proposal_by_url(self, url): |
|
68 |
for b in self._locations: |
|
69 |
if url.startswith(b): |
|
70 |
return MergeProposal() |
|
71 |
raise UnsupportedHoster(url) |
|
72 |
||
73 |
||
74 |
class SampleHosterTestCase(tests.TestCaseWithTransport): |
|
75 |
||
76 |
def setUp(self): |
|
77 |
super(SampleHosterTestCase, self).setUp() |
|
78 |
self._old_hosters = _mod_propose.hosters |
|
79 |
_mod_propose.hosters = registry.Registry() |
|
80 |
self.hoster = SampleHoster() |
|
81 |
os.mkdir('hosted') |
|
82 |
SampleHoster._add_location( |
|
83 |
urlutils.local_path_to_url(os.path.join(self.test_dir, 'hosted'))) |
|
84 |
_mod_propose.hosters.register('sample', self.hoster) |
|
85 |
||
86 |
def tearDown(self): |
|
87 |
super(SampleHosterTestCase, self).tearDown() |
|
88 |
_mod_propose.hosters = self._old_hosters |
|
89 |
SampleHoster._locations = [] |
|
90 |
||
91 |
||
92 |
class TestGetHosterTests(SampleHosterTestCase): |
|
93 |
||
94 |
def test_get_hoster(self): |
|
95 |
tree = self.make_branch_and_tree('hosted/branch') |
|
96 |
self.assertIs(self.hoster, get_hoster(tree.branch, [self.hoster])) |
|
97 |
self.assertIsInstance(get_hoster(tree.branch), SampleHoster) |
|
98 |
||
99 |
tree = self.make_branch_and_tree('blah') |
|
100 |
self.assertRaises(UnsupportedHoster, get_hoster, tree.branch) |
|
101 |
||
102 |
||
103 |
class TestGetProposal(SampleHosterTestCase): |
|
104 |
||
105 |
def test_get_proposal_by_url(self): |
|
106 |
self.assertRaises(UnsupportedHoster, get_proposal_by_url, 'blah') |
|
107 |
||
108 |
url = urlutils.local_path_to_url(os.path.join(self.test_dir, 'hosted', 'proposal')) |
|
109 |
self.assertIsInstance(get_proposal_by_url(url), MergeProposal) |
|
|
7445.1.2
by Jelmer Vernooij
Add test. |
110 |
|
111 |
||
112 |
class DetermineTitleTests(tests.TestCase): |
|
113 |
||
114 |
def test_determine_title(self): |
|
115 |
self.assertEqual('Make some change', determine_title("""\ |
|
116 |
Make some change.
|
|
117 |
||
118 |
And here are some more details.
|
|
119 |
""")) |
|
|
7490.146.1
by Jelmer Vernooij
Don't split at simply the first dot. |
120 |
self.assertEqual('Make some change', determine_title("""\ |
121 |
Make some change. And another one.
|
|
122 |
||
123 |
With details.
|
|
124 |
""")) |
|
125 |
self.assertEqual('Release version 5.1', determine_title("""\ |
|
126 |
Release version 5.1
|
|
127 |
||
128 |
And here are some more details.
|
|
129 |
""")) |