Show More
@@ -9,10 +9,9 b' from kallithea.lib.vcs.nodes import Node' | |||||
9 |
|
9 | |||
10 | from kallithea.tests.vcs.conf import TEST_HG_REPO, TEST_HG_REPO_CLONE, \ |
|
10 | from kallithea.tests.vcs.conf import TEST_HG_REPO, TEST_HG_REPO_CLONE, \ | |
11 | TEST_HG_REPO_PULL, TESTS_TMP_PATH |
|
11 | TEST_HG_REPO_PULL, TESTS_TMP_PATH | |
12 | from kallithea.lib.vcs.utils.compat import unittest |
|
|||
13 |
|
12 | |||
14 |
|
13 | |||
15 |
class MercurialRepository |
|
14 | class TestMercurialRepository(object): | |
16 |
|
15 | |||
17 | def __check_for_existing_repo(self): |
|
16 | def __check_for_existing_repo(self): | |
18 | if os.path.exists(TEST_HG_REPO_CLONE): |
|
17 | if os.path.exists(TEST_HG_REPO_CLONE): | |
@@ -20,46 +19,52 b' class MercurialRepositoryTest(unittest.T' | |||||
20 | 'exists. You should manually remove it first.' |
|
19 | 'exists. You should manually remove it first.' | |
21 | % TEST_HG_REPO_CLONE) |
|
20 | % TEST_HG_REPO_CLONE) | |
22 |
|
21 | |||
23 |
def set |
|
22 | def setup_method(self): | |
24 | self.repo = MercurialRepository(safe_str(TEST_HG_REPO)) |
|
23 | self.repo = MercurialRepository(safe_str(TEST_HG_REPO)) | |
25 |
|
24 | |||
26 | def test_wrong_repo_path(self): |
|
25 | def test_wrong_repo_path(self): | |
27 | wrong_repo_path = os.path.join(TESTS_TMP_PATH, 'errorrepo') |
|
26 | wrong_repo_path = os.path.join(TESTS_TMP_PATH, 'errorrepo') | |
28 | self.assertRaises(RepositoryError, MercurialRepository, wrong_repo_path) |
|
27 | with pytest.raises(RepositoryError): | |
|
28 | MercurialRepository(wrong_repo_path) | |||
29 |
|
29 | |||
30 | def test_unicode_path_repo(self): |
|
30 | def test_unicode_path_repo(self): | |
31 | self.assertRaises(VCSError, lambda: MercurialRepository(u'iShouldFail')) |
|
31 | with pytest.raises(VCSError): | |
|
32 | MercurialRepository(u'iShouldFail') | |||
32 |
|
33 | |||
33 | def test_repo_clone(self): |
|
34 | def test_repo_clone(self): | |
34 | self.__check_for_existing_repo() |
|
35 | self.__check_for_existing_repo() | |
35 | repo = MercurialRepository(safe_str(TEST_HG_REPO)) |
|
36 | repo = MercurialRepository(safe_str(TEST_HG_REPO)) | |
36 | repo_clone = MercurialRepository(TEST_HG_REPO_CLONE, |
|
37 | repo_clone = MercurialRepository(TEST_HG_REPO_CLONE, | |
37 | src_url=TEST_HG_REPO, update_after_clone=True) |
|
38 | src_url=TEST_HG_REPO, update_after_clone=True) | |
38 |
|
|
39 | assert len(repo.revisions) == len(repo_clone.revisions) | |
39 | # Checking hashes of changesets should be enough |
|
40 | # Checking hashes of changesets should be enough | |
40 | for changeset in repo.get_changesets(): |
|
41 | for changeset in repo.get_changesets(): | |
41 | raw_id = changeset.raw_id |
|
42 | raw_id = changeset.raw_id | |
42 |
|
|
43 | assert raw_id == repo_clone.get_changeset(raw_id).raw_id | |
43 |
|
44 | |||
44 | def test_repo_clone_with_update(self): |
|
45 | def test_repo_clone_with_update(self): | |
45 | repo = MercurialRepository(safe_str(TEST_HG_REPO)) |
|
46 | repo = MercurialRepository(safe_str(TEST_HG_REPO)) | |
46 | repo_clone = MercurialRepository(TEST_HG_REPO_CLONE + '_w_update', |
|
47 | repo_clone = MercurialRepository(TEST_HG_REPO_CLONE + '_w_update', | |
47 | src_url=TEST_HG_REPO, update_after_clone=True) |
|
48 | src_url=TEST_HG_REPO, update_after_clone=True) | |
48 |
|
|
49 | assert len(repo.revisions) == len(repo_clone.revisions) | |
49 |
|
50 | |||
50 | # check if current workdir was updated |
|
51 | # check if current workdir was updated | |
51 | self.assertEqual(os.path.isfile(os.path.join(TEST_HG_REPO_CLONE \ |
|
52 | assert os.path.isfile( | |
52 | + '_w_update', |
|
53 | os.path.join( | |
53 | 'MANIFEST.in')), True,) |
|
54 | TEST_HG_REPO_CLONE + '_w_update', 'MANIFEST.in' | |
|
55 | ) | |||
|
56 | ) | |||
54 |
|
57 | |||
55 | def test_repo_clone_without_update(self): |
|
58 | def test_repo_clone_without_update(self): | |
56 | repo = MercurialRepository(safe_str(TEST_HG_REPO)) |
|
59 | repo = MercurialRepository(safe_str(TEST_HG_REPO)) | |
57 | repo_clone = MercurialRepository(TEST_HG_REPO_CLONE + '_wo_update', |
|
60 | repo_clone = MercurialRepository(TEST_HG_REPO_CLONE + '_wo_update', | |
58 | src_url=TEST_HG_REPO, update_after_clone=False) |
|
61 | src_url=TEST_HG_REPO, update_after_clone=False) | |
59 |
|
|
62 | assert len(repo.revisions) == len(repo_clone.revisions) | |
60 | self.assertEqual(os.path.isfile(os.path.join(TEST_HG_REPO_CLONE \ |
|
63 | assert not os.path.isfile( | |
61 | + '_wo_update', |
|
64 | os.path.join( | |
62 | 'MANIFEST.in')), False,) |
|
65 | TEST_HG_REPO_CLONE + '_wo_update', 'MANIFEST.in' | |
|
66 | ) | |||
|
67 | ) | |||
63 |
|
68 | |||
64 | def test_pull(self): |
|
69 | def test_pull(self): | |
65 | if os.path.exists(TEST_HG_REPO_PULL): |
|
70 | if os.path.exists(TEST_HG_REPO_PULL): | |
@@ -67,11 +72,11 b' class MercurialRepositoryTest(unittest.T' | |||||
67 | 'already exists. You should manually remove it first' |
|
72 | 'already exists. You should manually remove it first' | |
68 | % TEST_HG_REPO_PULL) |
|
73 | % TEST_HG_REPO_PULL) | |
69 | repo_new = MercurialRepository(TEST_HG_REPO_PULL, create=True) |
|
74 | repo_new = MercurialRepository(TEST_HG_REPO_PULL, create=True) | |
70 |
|
|
75 | assert len(self.repo.revisions) > len(repo_new.revisions) | |
71 |
|
76 | |||
72 | repo_new.pull(self.repo.path) |
|
77 | repo_new.pull(self.repo.path) | |
73 | repo_new = MercurialRepository(TEST_HG_REPO_PULL) |
|
78 | repo_new = MercurialRepository(TEST_HG_REPO_PULL) | |
74 |
|
|
79 | assert len(self.repo.revisions) == len(repo_new.revisions) | |
75 |
|
80 | |||
76 | def test_revisions(self): |
|
81 | def test_revisions(self): | |
77 | # there are 21 revisions at bitbucket now |
|
82 | # there are 21 revisions at bitbucket now | |
@@ -96,7 +101,7 b' class MercurialRepositoryTest(unittest.T' | |||||
96 | 'aa6a0de05b7612707db567078e130a6cd114a9a7', |
|
101 | 'aa6a0de05b7612707db567078e130a6cd114a9a7', | |
97 | 'eada5a770da98ab0dd7325e29d00e0714f228d09' |
|
102 | 'eada5a770da98ab0dd7325e29d00e0714f228d09' | |
98 | ]) |
|
103 | ]) | |
99 |
|
|
104 | assert subset.issubset(set(self.repo.revisions)) | |
100 |
|
105 | |||
101 | # check if we have the proper order of revisions |
|
106 | # check if we have the proper order of revisions | |
102 | org = ['b986218ba1c9b0d6a259fac9b050b1724ed8e545', |
|
107 | org = ['b986218ba1c9b0d6a259fac9b050b1724ed8e545', | |
@@ -130,90 +135,87 b' class MercurialRepositoryTest(unittest.T' | |||||
130 | 'ff5ab059786ebc7411e559a2cc309dfae3625a3b', |
|
135 | 'ff5ab059786ebc7411e559a2cc309dfae3625a3b', | |
131 | '6b6ad5f82ad5bb6190037671bd254bd4e1f4bf08', |
|
136 | '6b6ad5f82ad5bb6190037671bd254bd4e1f4bf08', | |
132 | 'ee87846a61c12153b51543bf860e1026c6d3dcba', ] |
|
137 | 'ee87846a61c12153b51543bf860e1026c6d3dcba', ] | |
133 |
|
|
138 | assert org == self.repo.revisions[:31] | |
134 |
|
139 | |||
135 | def test_iter_slice(self): |
|
140 | def test_iter_slice(self): | |
136 | sliced = list(self.repo[:10]) |
|
141 | sliced = list(self.repo[:10]) | |
137 | itered = list(self.repo)[:10] |
|
142 | itered = list(self.repo)[:10] | |
138 |
|
|
143 | assert sliced == itered | |
139 |
|
144 | |||
140 | def test_slicing(self): |
|
145 | def test_slicing(self): | |
141 | # 4 1 5 10 95 |
|
146 | # 4 1 5 10 95 | |
142 | for sfrom, sto, size in [(0, 4, 4), (1, 2, 1), (10, 15, 5), |
|
147 | for sfrom, sto, size in [(0, 4, 4), (1, 2, 1), (10, 15, 5), | |
143 | (10, 20, 10), (5, 100, 95)]: |
|
148 | (10, 20, 10), (5, 100, 95)]: | |
144 | revs = list(self.repo[sfrom:sto]) |
|
149 | revs = list(self.repo[sfrom:sto]) | |
145 |
|
|
150 | assert len(revs) == size | |
146 |
|
|
151 | assert revs[0] == self.repo.get_changeset(sfrom) | |
147 |
|
|
152 | assert revs[-1] == self.repo.get_changeset(sto - 1) | |
148 |
|
153 | |||
149 | def test_branches(self): |
|
154 | def test_branches(self): | |
150 | # TODO: Need more tests here |
|
155 | # TODO: Need more tests here | |
151 |
|
156 | |||
152 | # active branches |
|
157 | # active branches | |
153 |
|
|
158 | assert 'default' in self.repo.branches | |
154 |
|
|
159 | assert 'stable' in self.repo.branches | |
155 |
|
160 | |||
156 | # closed |
|
161 | # closed | |
157 |
|
|
162 | assert 'git' in self.repo._get_branches(closed=True) | |
158 |
|
|
163 | assert 'web' in self.repo._get_branches(closed=True) | |
159 |
|
164 | |||
160 | for name, id in self.repo.branches.items(): |
|
165 | for name, id in self.repo.branches.items(): | |
161 | self.assertTrue(isinstance( |
|
166 | assert isinstance(self.repo.get_changeset(id), MercurialChangeset) | |
162 | self.repo.get_changeset(id), MercurialChangeset)) |
|
|||
163 |
|
167 | |||
164 | def test_tip_in_tags(self): |
|
168 | def test_tip_in_tags(self): | |
165 | # tip is always a tag |
|
169 | # tip is always a tag | |
166 |
|
|
170 | assert 'tip' in self.repo.tags | |
167 |
|
171 | |||
168 | def test_tip_changeset_in_tags(self): |
|
172 | def test_tip_changeset_in_tags(self): | |
169 | tip = self.repo.get_changeset() |
|
173 | tip = self.repo.get_changeset() | |
170 |
|
|
174 | assert self.repo.tags['tip'] == tip.raw_id | |
171 |
|
175 | |||
172 | def test_initial_changeset(self): |
|
176 | def test_initial_changeset(self): | |
173 |
|
177 | |||
174 | init_chset = self.repo.get_changeset(0) |
|
178 | init_chset = self.repo.get_changeset(0) | |
175 |
|
|
179 | assert init_chset.message == 'initial import' | |
176 | self.assertEqual(init_chset.author, |
|
180 | assert init_chset.author == 'Marcin Kuzminski <marcin@python-blog.com>' | |
177 | 'Marcin Kuzminski <marcin@python-blog.com>') |
|
181 | assert sorted(init_chset._file_paths) == sorted([ | |
178 | self.assertEqual(sorted(init_chset._file_paths), |
|
182 | 'vcs/__init__.py', | |
179 | sorted([ |
|
183 | 'vcs/backends/BaseRepository.py', | |
180 |
|
|
184 | 'vcs/backends/__init__.py', | |
181 | 'vcs/backends/BaseRepository.py', |
|
185 | ]) | |
182 | 'vcs/backends/__init__.py', |
|
|||
183 | ]) |
|
|||
184 | ) |
|
|||
185 | self.assertEqual(sorted(init_chset._dir_paths), |
|
|||
186 | sorted(['', 'vcs', 'vcs/backends'])) |
|
|||
187 |
|
186 | |||
188 | self.assertRaises(NodeDoesNotExistError, init_chset.get_node, path='foobar') |
|
187 | assert sorted(init_chset._dir_paths) == sorted(['', 'vcs', 'vcs/backends']) | |
|
188 | ||||
|
189 | with pytest.raises(NodeDoesNotExistError): | |||
|
190 | init_chset.get_node(path='foobar') | |||
189 |
|
191 | |||
190 | node = init_chset.get_node('vcs/') |
|
192 | node = init_chset.get_node('vcs/') | |
191 |
|
|
193 | assert hasattr(node, 'kind') | |
192 |
|
|
194 | assert node.kind == NodeKind.DIR | |
193 |
|
195 | |||
194 | node = init_chset.get_node('vcs') |
|
196 | node = init_chset.get_node('vcs') | |
195 |
|
|
197 | assert hasattr(node, 'kind') | |
196 |
|
|
198 | assert node.kind == NodeKind.DIR | |
197 |
|
199 | |||
198 | node = init_chset.get_node('vcs/__init__.py') |
|
200 | node = init_chset.get_node('vcs/__init__.py') | |
199 |
|
|
201 | assert hasattr(node, 'kind') | |
200 |
|
|
202 | assert node.kind == NodeKind.FILE | |
201 |
|
203 | |||
202 | def test_not_existing_changeset(self): |
|
204 | def test_not_existing_changeset(self): | |
203 | # rawid |
|
205 | # rawid | |
204 | self.assertRaises(RepositoryError, self.repo.get_changeset, |
|
206 | with pytest.raises(RepositoryError): | |
205 | 'abcd' * 10) |
|
207 | self.repo.get_changeset('abcd' * 10) | |
206 | # shortid |
|
208 | # shortid | |
207 | self.assertRaises(RepositoryError, self.repo.get_changeset, |
|
209 | with pytest.raises(RepositoryError): | |
208 | 'erro' * 4) |
|
210 | self.repo.get_changeset('erro' * 4) | |
209 | # numeric |
|
211 | # numeric | |
210 | self.assertRaises(RepositoryError, self.repo.get_changeset, |
|
212 | with pytest.raises(RepositoryError): | |
211 | self.repo.count() + 1) |
|
213 | self.repo.get_changeset(self.repo.count() + 1) | |
212 |
|
||||
213 |
|
214 | |||
214 | # Small chance we ever get to this one |
|
215 | # Small chance we ever get to this one | |
215 | revision = pow(2, 30) |
|
216 | revision = pow(2, 30) | |
216 | self.assertRaises(RepositoryError, self.repo.get_changeset, revision) |
|
217 | with pytest.raises(RepositoryError): | |
|
218 | self.repo.get_changeset(revision) | |||
217 |
|
219 | |||
218 | def test_changeset10(self): |
|
220 | def test_changeset10(self): | |
219 |
|
221 | |||
@@ -231,21 +233,20 b' TODO: To be written...' | |||||
231 |
|
233 | |||
232 | """ |
|
234 | """ | |
233 | node = chset10.get_node('README.rst') |
|
235 | node = chset10.get_node('README.rst') | |
234 |
|
|
236 | assert node.kind == NodeKind.FILE | |
235 |
|
|
237 | assert node.content == readme | |
236 |
|
238 | |||
237 |
|
239 | |||
238 |
class MercurialChangeset |
|
240 | class TestMercurialChangeset(object): | |
239 |
|
241 | |||
240 |
def set |
|
242 | def setup_method(self): | |
241 | self.repo = MercurialRepository(safe_str(TEST_HG_REPO)) |
|
243 | self.repo = MercurialRepository(safe_str(TEST_HG_REPO)) | |
242 |
|
244 | |||
243 | def _test_equality(self, changeset): |
|
245 | def _test_equality(self, changeset): | |
244 | revision = changeset.revision |
|
246 | revision = changeset.revision | |
245 |
|
|
247 | assert changeset == self.repo.get_changeset(revision) | |
246 |
|
248 | |||
247 | def test_equality(self): |
|
249 | def test_equality(self): | |
248 | self.setUp() |
|
|||
249 | revs = [0, 10, 20] |
|
250 | revs = [0, 10, 20] | |
250 | changesets = [self.repo.get_changeset(rev) for rev in revs] |
|
251 | changesets = [self.repo.get_changeset(rev) for rev in revs] | |
251 | for changeset in changesets: |
|
252 | for changeset in changesets: | |
@@ -253,13 +254,13 b' class MercurialChangesetTest(unittest.Te' | |||||
253 |
|
254 | |||
254 | def test_default_changeset(self): |
|
255 | def test_default_changeset(self): | |
255 | tip = self.repo.get_changeset('tip') |
|
256 | tip = self.repo.get_changeset('tip') | |
256 |
|
|
257 | assert tip == self.repo.get_changeset() | |
257 |
|
|
258 | assert tip == self.repo.get_changeset(revision=None) | |
258 |
|
|
259 | assert tip == list(self.repo[-1:])[0] | |
259 |
|
260 | |||
260 | def test_root_node(self): |
|
261 | def test_root_node(self): | |
261 | tip = self.repo.get_changeset('tip') |
|
262 | tip = self.repo.get_changeset('tip') | |
262 |
|
|
263 | assert tip.root is tip.get_node('') | |
263 |
|
264 | |||
264 | def test_lazy_fetch(self): |
|
265 | def test_lazy_fetch(self): | |
265 | """ |
|
266 | """ | |
@@ -267,60 +268,56 b' class MercurialChangesetTest(unittest.Te' | |||||
267 | the revision. This test is somewhat hard to write as order of tests |
|
268 | the revision. This test is somewhat hard to write as order of tests | |
268 | is a key here. Written by running command after command in a shell. |
|
269 | is a key here. Written by running command after command in a shell. | |
269 | """ |
|
270 | """ | |
270 | self.setUp() |
|
|||
271 | chset = self.repo.get_changeset(45) |
|
271 | chset = self.repo.get_changeset(45) | |
272 |
|
|
272 | assert len(chset.nodes) == 0 | |
273 | root = chset.root |
|
273 | root = chset.root | |
274 |
|
|
274 | assert len(chset.nodes) == 1 | |
275 |
|
|
275 | assert len(root.nodes) == 8 | |
276 | # accessing root.nodes updates chset.nodes |
|
276 | # accessing root.nodes updates chset.nodes | |
277 |
|
|
277 | assert len(chset.nodes) == 9 | |
278 |
|
278 | |||
279 | docs = root.get_node('docs') |
|
279 | docs = root.get_node('docs') | |
280 | # we haven't yet accessed anything new as docs dir was already cached |
|
280 | # we haven't yet accessed anything new as docs dir was already cached | |
281 |
|
|
281 | assert len(chset.nodes) == 9 | |
282 |
|
|
282 | assert len(docs.nodes) == 8 | |
283 | # accessing docs.nodes updates chset.nodes |
|
283 | # accessing docs.nodes updates chset.nodes | |
284 |
|
|
284 | assert len(chset.nodes) == 17 | |
285 |
|
285 | |||
286 |
|
|
286 | assert docs is chset.get_node('docs') | |
287 |
|
|
287 | assert docs is root.nodes[0] | |
288 |
|
|
288 | assert docs is root.dirs[0] | |
289 |
|
|
289 | assert docs is chset.get_node('docs') | |
290 |
|
290 | |||
291 | def test_nodes_with_changeset(self): |
|
291 | def test_nodes_with_changeset(self): | |
292 | self.setUp() |
|
|||
293 | chset = self.repo.get_changeset(45) |
|
292 | chset = self.repo.get_changeset(45) | |
294 | root = chset.root |
|
293 | root = chset.root | |
295 | docs = root.get_node('docs') |
|
294 | docs = root.get_node('docs') | |
296 |
|
|
295 | assert docs is chset.get_node('docs') | |
297 | api = docs.get_node('api') |
|
296 | api = docs.get_node('api') | |
298 |
|
|
297 | assert api is chset.get_node('docs/api') | |
299 | index = api.get_node('index.rst') |
|
298 | index = api.get_node('index.rst') | |
300 |
|
|
299 | assert index is chset.get_node('docs/api/index.rst') | |
301 |
|
|
300 | assert index is chset.get_node('docs').get_node('api').get_node('index.rst') | |
302 | .get_node('api') \ |
|
|||
303 | .get_node('index.rst')) |
|
|||
304 |
|
301 | |||
305 | def test_branch_and_tags(self): |
|
302 | def test_branch_and_tags(self): | |
306 | chset0 = self.repo.get_changeset(0) |
|
303 | chset0 = self.repo.get_changeset(0) | |
307 |
|
|
304 | assert chset0.branch == 'default' | |
308 |
|
|
305 | assert chset0.tags == [] | |
309 |
|
306 | |||
310 | chset10 = self.repo.get_changeset(10) |
|
307 | chset10 = self.repo.get_changeset(10) | |
311 |
|
|
308 | assert chset10.branch == 'default' | |
312 |
|
|
309 | assert chset10.tags == [] | |
313 |
|
310 | |||
314 | chset44 = self.repo.get_changeset(44) |
|
311 | chset44 = self.repo.get_changeset(44) | |
315 |
|
|
312 | assert chset44.branch == 'web' | |
316 |
|
313 | |||
317 | tip = self.repo.get_changeset('tip') |
|
314 | tip = self.repo.get_changeset('tip') | |
318 |
|
|
315 | assert 'tip' in tip.tags | |
319 |
|
316 | |||
320 | def _test_file_size(self, revision, path, size): |
|
317 | def _test_file_size(self, revision, path, size): | |
321 | node = self.repo.get_changeset(revision).get_node(path) |
|
318 | node = self.repo.get_changeset(revision).get_node(path) | |
322 |
|
|
319 | assert node.is_file() | |
323 |
|
|
320 | assert node.size == size | |
324 |
|
321 | |||
325 | def test_file_size(self): |
|
322 | def test_file_size(self): | |
326 | to_check = ( |
|
323 | to_check = ( | |
@@ -337,8 +334,8 b' class MercurialChangesetTest(unittest.Te' | |||||
337 |
|
334 | |||
338 | def _test_dir_size(self, revision, path, size): |
|
335 | def _test_dir_size(self, revision, path, size): | |
339 | node = self.repo.get_changeset(revision).get_node(path) |
|
336 | node = self.repo.get_changeset(revision).get_node(path) | |
340 |
|
|
337 | assert not node.is_file() | |
341 |
|
|
338 | assert node.size == size | |
342 |
|
339 | |||
343 | def test_dir_size(self): |
|
340 | def test_dir_size(self): | |
344 | to_check = ( |
|
341 | to_check = ( | |
@@ -350,7 +347,7 b' class MercurialChangesetTest(unittest.Te' | |||||
350 | self._test_dir_size(revision, path, size) |
|
347 | self._test_dir_size(revision, path, size) | |
351 |
|
348 | |||
352 | def test_repo_size(self): |
|
349 | def test_repo_size(self): | |
353 |
|
|
350 | assert self.repo.size == 682421 | |
354 |
|
351 | |||
355 | def test_file_history(self): |
|
352 | def test_file_history(self): | |
356 | # we can only check if those revisions are present in the history |
|
353 | # we can only check if those revisions are present in the history | |
@@ -368,10 +365,10 b' class MercurialChangesetTest(unittest.Te' | |||||
368 | tip = self.repo.get_changeset(revs[-1]) |
|
365 | tip = self.repo.get_changeset(revs[-1]) | |
369 | node = tip.get_node(path) |
|
366 | node = tip.get_node(path) | |
370 | node_revs = [chset.revision for chset in node.history] |
|
367 | node_revs = [chset.revision for chset in node.history] | |
371 |
|
|
368 | assert set(revs).issubset(set(node_revs)), \ | |
372 | "We assumed that %s is subset of revisions for which file %s " |
|
369 | "We assumed that %s is subset of revisions for which file %s " \ | |
373 | "has been changed, and history of that node returned: %s" |
|
370 | "has been changed, and history of that node returned: %s" \ | |
374 |
% (revs, path, node_revs) |
|
371 | % (revs, path, node_revs) | |
375 |
|
372 | |||
376 | def test_file_annotate(self): |
|
373 | def test_file_annotate(self): | |
377 | files = { |
|
374 | files = { | |
@@ -410,12 +407,12 b' class MercurialChangesetTest(unittest.Te' | |||||
410 | cs = self.repo.get_changeset(rev) |
|
407 | cs = self.repo.get_changeset(rev) | |
411 | l1_1 = [x[1] for x in cs.get_file_annotate(fname)] |
|
408 | l1_1 = [x[1] for x in cs.get_file_annotate(fname)] | |
412 | l1_2 = [x[2]().raw_id for x in cs.get_file_annotate(fname)] |
|
409 | l1_2 = [x[2]().raw_id for x in cs.get_file_annotate(fname)] | |
413 |
|
|
410 | assert l1_1 == l1_2 | |
414 | l1 = l1_2 = [x[2]().revision for x in cs.get_file_annotate(fname)] |
|
411 | l1 = l1_2 = [x[2]().revision for x in cs.get_file_annotate(fname)] | |
415 | l2 = files[fname][rev]['changesets'] |
|
412 | l2 = files[fname][rev]['changesets'] | |
416 |
|
|
413 | assert l1 == l2, "The lists of revision for %s@rev%s" \ | |
417 |
|
|
414 | "from annotation list should match each other," \ | |
418 |
|
|
415 | "got \n%s \nvs \n%s " % (fname, rev, l1, l2) | |
419 |
|
416 | |||
420 | def test_changeset_state(self): |
|
417 | def test_changeset_state(self): | |
421 | """ |
|
418 | """ | |
@@ -447,9 +444,9 b' class MercurialChangesetTest(unittest.Te' | |||||
447 | removed = set(['docs/api.rst']) |
|
444 | removed = set(['docs/api.rst']) | |
448 |
|
445 | |||
449 | chset64 = self.repo.get_changeset('46ad32a4f974') |
|
446 | chset64 = self.repo.get_changeset('46ad32a4f974') | |
450 |
|
|
447 | assert set((node.path for node in chset64.added)) == added | |
451 |
|
|
448 | assert set((node.path for node in chset64.changed)) == changed | |
452 |
|
|
449 | assert set((node.path for node in chset64.removed)) == removed | |
453 |
|
450 | |||
454 | # rev b090f22d27d6: |
|
451 | # rev b090f22d27d6: | |
455 | # hg st --rev b090f22d27d6 |
|
452 | # hg st --rev b090f22d27d6 | |
@@ -457,27 +454,30 b' class MercurialChangesetTest(unittest.Te' | |||||
457 | # added: 20 |
|
454 | # added: 20 | |
458 | # removed: 1 |
|
455 | # removed: 1 | |
459 | chset88 = self.repo.get_changeset('b090f22d27d6') |
|
456 | chset88 = self.repo.get_changeset('b090f22d27d6') | |
460 |
|
|
457 | assert set((node.path for node in chset88.added)) == set() | |
461 |
|
|
458 | assert set((node.path for node in chset88.changed)) == set(['.hgignore']) | |
462 | set(['.hgignore'])) |
|
459 | assert set((node.path for node in chset88.removed)) == set() | |
463 | self.assertEqual(set((node.path for node in chset88.removed)), set()) |
|
|||
464 |
|
460 | |||
465 | # 85: |
|
461 | # 85: | |
466 | # added: 2 ['vcs/utils/diffs.py', 'vcs/web/simplevcs/views/diffs.py'] |
|
462 | # added: 2 ['vcs/utils/diffs.py', 'vcs/web/simplevcs/views/diffs.py'] | |
467 | # changed: 4 ['vcs/web/simplevcs/models.py', ...] |
|
463 | # changed: 4 ['vcs/web/simplevcs/models.py', ...] | |
468 | # removed: 1 ['vcs/utils/web.py'] |
|
464 | # removed: 1 ['vcs/utils/web.py'] | |
469 | chset85 = self.repo.get_changeset(85) |
|
465 | chset85 = self.repo.get_changeset(85) | |
470 |
|
|
466 | assert set((node.path for node in chset85.added)) == set([ | |
471 | 'vcs/utils/diffs.py', |
|
467 | 'vcs/utils/diffs.py', | |
472 |
'vcs/web/simplevcs/views/diffs.py' |
|
468 | 'vcs/web/simplevcs/views/diffs.py' | |
473 | self.assertEqual(set((node.path for node in chset85.changed)), set([ |
|
469 | ]) | |
|
470 | ||||
|
471 | assert set((node.path for node in chset85.changed)) == set([ | |||
474 | 'vcs/web/simplevcs/models.py', |
|
472 | 'vcs/web/simplevcs/models.py', | |
475 | 'vcs/web/simplevcs/utils.py', |
|
473 | 'vcs/web/simplevcs/utils.py', | |
476 | 'vcs/web/simplevcs/views/__init__.py', |
|
474 | 'vcs/web/simplevcs/views/__init__.py', | |
477 | 'vcs/web/simplevcs/views/repository.py', |
|
475 | 'vcs/web/simplevcs/views/repository.py', | |
478 |
|
|
476 | ]) | |
479 | self.assertEqual(set((node.path for node in chset85.removed)), |
|
477 | ||
480 | set(['vcs/utils/web.py'])) |
|
478 | assert set((node.path for node in chset85.removed)) == set([ | |
|
479 | 'vcs/utils/web.py' | |||
|
480 | ]) | |||
481 |
|
481 | |||
482 |
|
482 | |||
483 | def test_files_state(self): |
|
483 | def test_files_state(self): | |
@@ -486,54 +486,56 b' class MercurialChangesetTest(unittest.Te' | |||||
486 | """ |
|
486 | """ | |
487 | chset = self.repo.get_changeset(85) |
|
487 | chset = self.repo.get_changeset(85) | |
488 | node = chset.get_node('vcs/utils/diffs.py') |
|
488 | node = chset.get_node('vcs/utils/diffs.py') | |
489 |
|
|
489 | assert node.state, NodeState.ADDED | |
490 |
|
|
490 | assert node.added | |
491 |
|
|
491 | assert not node.changed | |
492 |
|
|
492 | assert not node.not_changed | |
493 |
|
|
493 | assert not node.removed | |
494 |
|
494 | |||
495 | chset = self.repo.get_changeset(88) |
|
495 | chset = self.repo.get_changeset(88) | |
496 | node = chset.get_node('.hgignore') |
|
496 | node = chset.get_node('.hgignore') | |
497 |
|
|
497 | assert node.state, NodeState.CHANGED | |
498 |
|
|
498 | assert not node.added | |
499 |
|
|
499 | assert node.changed | |
500 |
|
|
500 | assert not node.not_changed | |
501 |
|
|
501 | assert not node.removed | |
502 |
|
502 | |||
503 | chset = self.repo.get_changeset(85) |
|
503 | chset = self.repo.get_changeset(85) | |
504 | node = chset.get_node('setup.py') |
|
504 | node = chset.get_node('setup.py') | |
505 |
|
|
505 | assert node.state, NodeState.NOT_CHANGED | |
506 |
|
|
506 | assert not node.added | |
507 |
|
|
507 | assert not node.changed | |
508 |
|
|
508 | assert node.not_changed | |
509 |
|
|
509 | assert not node.removed | |
510 |
|
510 | |||
511 | # If node has REMOVED state then trying to fetch it would raise |
|
511 | # If node has REMOVED state then trying to fetch it would raise | |
512 | # ChangesetError exception |
|
512 | # ChangesetError exception | |
513 | chset = self.repo.get_changeset(2) |
|
513 | chset = self.repo.get_changeset(2) | |
514 | path = 'vcs/backends/BaseRepository.py' |
|
514 | path = 'vcs/backends/BaseRepository.py' | |
515 |
|
|
515 | with pytest.raises(NodeDoesNotExistError): | |
|
516 | chset.get_node(path) | |||
516 | # but it would be one of ``removed`` (changeset's attribute) |
|
517 | # but it would be one of ``removed`` (changeset's attribute) | |
517 |
|
|
518 | assert path in [rf.path for rf in chset.removed] | |
518 |
|
519 | |||
519 | def test_commit_message_is_unicode(self): |
|
520 | def test_commit_message_is_unicode(self): | |
520 | for cm in self.repo: |
|
521 | for cm in self.repo: | |
521 |
|
|
522 | assert type(cm.message) == unicode | |
522 |
|
523 | |||
523 | def test_changeset_author_is_unicode(self): |
|
524 | def test_changeset_author_is_unicode(self): | |
524 | for cm in self.repo: |
|
525 | for cm in self.repo: | |
525 |
|
|
526 | assert type(cm.author) == unicode | |
526 |
|
527 | |||
527 | def test_repo_files_content_is_unicode(self): |
|
528 | def test_repo_files_content_is_unicode(self): | |
528 | test_changeset = self.repo.get_changeset(100) |
|
529 | test_changeset = self.repo.get_changeset(100) | |
529 | for node in test_changeset.get_node('/'): |
|
530 | for node in test_changeset.get_node('/'): | |
530 | if node.is_file(): |
|
531 | if node.is_file(): | |
531 |
|
|
532 | assert type(node.content) == unicode | |
532 |
|
533 | |||
533 | def test_wrong_path(self): |
|
534 | def test_wrong_path(self): | |
534 | # There is 'setup.py' in the root dir but not there: |
|
535 | # There is 'setup.py' in the root dir but not there: | |
535 | path = 'foo/bar/setup.py' |
|
536 | path = 'foo/bar/setup.py' | |
536 | self.assertRaises(VCSError, self.repo.get_changeset().get_node, path) |
|
537 | with pytest.raises(VCSError): | |
|
538 | self.repo.get_changeset().get_node(path) | |||
537 |
|
539 | |||
538 | def test_archival_file(self): |
|
540 | def test_archival_file(self): | |
539 | # TODO: |
|
541 | # TODO: | |
@@ -545,24 +547,19 b' class MercurialChangesetTest(unittest.Te' | |||||
545 |
|
547 | |||
546 | def test_archival_wrong_kind(self): |
|
548 | def test_archival_wrong_kind(self): | |
547 | tip = self.repo.get_changeset() |
|
549 | tip = self.repo.get_changeset() | |
548 | self.assertRaises(VCSError, tip.fill_archive, kind='error') |
|
550 | with pytest.raises(VCSError): | |
|
551 | tip.fill_archive(kind='error') | |||
549 |
|
552 | |||
550 | def test_archival_empty_prefix(self): |
|
553 | def test_archival_empty_prefix(self): | |
551 | # TODO: |
|
554 | # TODO: | |
552 | pass |
|
555 | pass | |
553 |
|
556 | |||
554 | def test_author_email(self): |
|
557 | def test_author_email(self): | |
555 | self.assertEqual('marcin@python-blog.com', |
|
558 | assert 'marcin@python-blog.com' == self.repo.get_changeset('b986218ba1c9').author_email | |
556 | self.repo.get_changeset('b986218ba1c9').author_email) |
|
559 | assert 'lukasz.balcerzak@python-center.pl' == self.repo.get_changeset('3803844fdbd3').author_email | |
557 | self.assertEqual('lukasz.balcerzak@python-center.pl', |
|
560 | assert '' == self.repo.get_changeset('84478366594b').author_email | |
558 | self.repo.get_changeset('3803844fdbd3').author_email) |
|
|||
559 | self.assertEqual('', |
|
|||
560 | self.repo.get_changeset('84478366594b').author_email) |
|
|||
561 |
|
561 | |||
562 | def test_author_username(self): |
|
562 | def test_author_username(self): | |
563 | self.assertEqual('Marcin Kuzminski', |
|
563 | assert 'Marcin Kuzminski' == self.repo.get_changeset('b986218ba1c9').author_name | |
564 |
|
|
564 | assert 'Lukasz Balcerzak' == self.repo.get_changeset('3803844fdbd3').author_name | |
565 | self.assertEqual('Lukasz Balcerzak', |
|
565 | assert 'marcink' == self.repo.get_changeset('84478366594b').author_name | |
566 | self.repo.get_changeset('3803844fdbd3').author_name) |
|
|||
567 | self.assertEqual('marcink', |
|
|||
568 | self.repo.get_changeset('84478366594b').author_name) |
|
General Comments 0
You need to be logged in to leave comments.
Login now