Show More
@@ -1,591 +1,597 b'' | |||
|
1 | 1 | |
|
2 | 2 | # Copyright (C) 2010-2023 RhodeCode GmbH |
|
3 | 3 | # |
|
4 | 4 | # This program is free software: you can redistribute it and/or modify |
|
5 | 5 | # it under the terms of the GNU Affero General Public License, version 3 |
|
6 | 6 | # (only), as published by the Free Software Foundation. |
|
7 | 7 | # |
|
8 | 8 | # This program is distributed in the hope that it will be useful, |
|
9 | 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | 11 | # GNU General Public License for more details. |
|
12 | 12 | # |
|
13 | 13 | # You should have received a copy of the GNU Affero General Public License |
|
14 | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 | 15 | # |
|
16 | 16 | # This program is dual-licensed. If you wish to learn more about the |
|
17 | 17 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
18 | 18 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
19 | 19 | |
|
20 | 20 | import datetime |
|
21 | 21 | import time |
|
22 | 22 | |
|
23 | 23 | import pytest |
|
24 | 24 | |
|
25 | 25 | from rhodecode.lib.str_utils import safe_bytes |
|
26 | 26 | from rhodecode.lib.vcs.backends.base import ( |
|
27 | 27 | CollectionGenerator, FILEMODE_DEFAULT, EmptyCommit) |
|
28 | 28 | from rhodecode.lib.vcs.exceptions import ( |
|
29 | 29 | BranchDoesNotExistError, CommitDoesNotExistError, |
|
30 | 30 | RepositoryError, EmptyRepositoryError) |
|
31 | 31 | from rhodecode.lib.vcs.nodes import ( |
|
32 | 32 | FileNode, AddedFileNodesGenerator, |
|
33 | 33 | ChangedFileNodesGenerator, RemovedFileNodesGenerator) |
|
34 | 34 | from rhodecode.tests import get_new_dir |
|
35 | 35 | from rhodecode.tests.vcs.conftest import BackendTestMixin |
|
36 | 36 | |
|
37 | 37 | |
|
38 | 38 | class TestBaseChangeset(object): |
|
39 | 39 | |
|
40 | 40 | def test_is_deprecated(self): |
|
41 | 41 | from rhodecode.lib.vcs.backends.base import BaseChangeset |
|
42 | 42 | pytest.deprecated_call(BaseChangeset) |
|
43 | 43 | |
|
44 | 44 | |
|
45 | 45 | class TestEmptyCommit(object): |
|
46 | 46 | |
|
47 | 47 | def test_branch_without_alias_returns_none(self): |
|
48 | 48 | commit = EmptyCommit() |
|
49 | 49 | assert commit.branch is None |
|
50 | 50 | |
|
51 | 51 | |
|
52 | 52 | @pytest.mark.usefixtures("vcs_repository_support") |
|
53 | 53 | class TestCommitsInNonEmptyRepo(BackendTestMixin): |
|
54 | 54 | recreate_repo_per_test = True |
|
55 | 55 | |
|
56 | 56 | @classmethod |
|
57 | 57 | def _get_commits(cls): |
|
58 | 58 | start_date = datetime.datetime(2010, 1, 1, 20) |
|
59 | 59 | for x in range(5): |
|
60 | 60 | yield { |
|
61 | 61 | 'message': 'Commit %d' % x, |
|
62 | 62 | 'author': 'Joe Doe <joe.doe@example.com>', |
|
63 | 63 | 'date': start_date + datetime.timedelta(hours=12 * x), |
|
64 | 64 | 'added': [ |
|
65 | 65 | FileNode(b'file_%d.txt' % x, |
|
66 | 66 | content=b'Foobar %d' % x), |
|
67 | 67 | ], |
|
68 | 68 | } |
|
69 | 69 | |
|
70 | 70 | def test_walk_returns_empty_list_in_case_of_file(self): |
|
71 | 71 | result = list(self.tip.walk('file_0.txt')) |
|
72 | 72 | assert result == [] |
|
73 | 73 | |
|
74 | 74 | @pytest.mark.backends("git", "hg") |
|
75 | 75 | def test_new_branch(self): |
|
76 | 76 | self.imc.add(FileNode(b'docs/index.txt', content=b'Documentation\n')) |
|
77 | 77 | foobar_tip = self.imc.commit( |
|
78 | 78 | message='New branch: foobar', |
|
79 | 79 | author='joe <joe@rhodecode.com>', |
|
80 | 80 | branch='foobar', |
|
81 | 81 | ) |
|
82 | 82 | assert 'foobar' in self.repo.branches |
|
83 | 83 | assert foobar_tip.branch == 'foobar' |
|
84 | 84 | # 'foobar' should be the only branch that contains the new commit |
|
85 | 85 | branch = list(self.repo.branches.values()) |
|
86 | 86 | assert branch[0] != branch[1] |
|
87 | 87 | |
|
88 | 88 | @pytest.mark.backends("git", "hg") |
|
89 | 89 | def test_new_head_in_default_branch(self): |
|
90 | 90 | tip = self.repo.get_commit() |
|
91 | self.imc.add(FileNode(b'docs/index.txt', content=b'Documentation\n')) | |
|
91 | ||
|
92 | self.imc.add( | |
|
93 | FileNode(b"docs/index.txt", content=b"Documentation\n") | |
|
94 | ) | |
|
92 | 95 | foobar_tip = self.imc.commit( |
|
93 |
message= |
|
|
94 |
author= |
|
|
95 |
branch= |
|
|
96 | message="New branch: foobar", | |
|
97 | author="joe <joe@rhodecode.com>", | |
|
98 | branch="foobar", | |
|
96 | 99 | parents=[tip], |
|
97 | 100 | ) |
|
98 | self.imc.change(FileNode(b'docs/index.txt', content=b'Documentation\nand more...\n')) | |
|
101 | self.imc.change( | |
|
102 | FileNode(b"docs/index.txt", content=b"Documentation\nand more...\n") | |
|
103 | ) | |
|
104 | assert foobar_tip.branch == "foobar" | |
|
99 | 105 | newtip = self.imc.commit( |
|
100 |
message= |
|
|
101 |
author= |
|
|
106 | message="At foobar_tip branch", | |
|
107 | author="joe <joe@rhodecode.com>", | |
|
102 | 108 | branch=foobar_tip.branch, |
|
103 | 109 | parents=[foobar_tip], |
|
104 | 110 | ) |
|
105 | 111 | |
|
106 | 112 | newest_tip = self.imc.commit( |
|
107 |
message= |
|
|
108 |
author= |
|
|
113 | message=f"Merged with {foobar_tip.raw_id}", | |
|
114 | author="joe <joe@rhodecode.com>", | |
|
109 | 115 | branch=self.backend_class.DEFAULT_BRANCH_NAME, |
|
110 |
parents=[ |
|
|
116 | parents=[tip, newtip], | |
|
111 | 117 | ) |
|
112 | 118 | |
|
113 | 119 | assert newest_tip.branch == self.backend_class.DEFAULT_BRANCH_NAME |
|
114 | 120 | |
|
115 | 121 | @pytest.mark.backends("git", "hg") |
|
116 | 122 | def test_get_commits_respects_branch_name(self): |
|
117 | 123 | """ |
|
118 | 124 | * e1930d0 (HEAD, master) Back in default branch |
|
119 | 125 | | * e1930d0 (docs) New Branch: docs2 |
|
120 | 126 | | * dcc14fa New branch: docs |
|
121 | 127 | |/ |
|
122 | 128 | * e63c41a Initial commit |
|
123 | 129 | ... |
|
124 | 130 | * 624d3db Commit 0 |
|
125 | 131 | |
|
126 | 132 | :return: |
|
127 | 133 | """ |
|
128 | 134 | DEFAULT_BRANCH = self.repo.DEFAULT_BRANCH_NAME |
|
129 | 135 | TEST_BRANCH = 'docs' |
|
130 | 136 | org_tip = self.repo.get_commit() |
|
131 | 137 | |
|
132 | 138 | self.imc.add(FileNode(b'readme.txt', content=b'Document\n')) |
|
133 | 139 | initial = self.imc.commit( |
|
134 | 140 | message='Initial commit', |
|
135 | 141 | author='joe <joe@rhodecode.com>', |
|
136 | 142 | parents=[org_tip], |
|
137 | 143 | branch=DEFAULT_BRANCH,) |
|
138 | 144 | |
|
139 | 145 | self.imc.add(FileNode(b'newdoc.txt', content=b'foobar\n')) |
|
140 | 146 | docs_branch_commit1 = self.imc.commit( |
|
141 | 147 | message='New branch: docs', |
|
142 | 148 | author='joe <joe@rhodecode.com>', |
|
143 | 149 | parents=[initial], |
|
144 | 150 | branch=TEST_BRANCH,) |
|
145 | 151 | |
|
146 | 152 | self.imc.add(FileNode(b'newdoc2.txt', content=b'foobar2\n')) |
|
147 | 153 | docs_branch_commit2 = self.imc.commit( |
|
148 | 154 | message='New branch: docs2', |
|
149 | 155 | author='joe <joe@rhodecode.com>', |
|
150 | 156 | parents=[docs_branch_commit1], |
|
151 | 157 | branch=TEST_BRANCH,) |
|
152 | 158 | |
|
153 | 159 | self.imc.add(FileNode(b'newfile', content=b'hello world\n')) |
|
154 | 160 | self.imc.commit( |
|
155 | 161 | message='Back in default branch', |
|
156 | 162 | author='joe <joe@rhodecode.com>', |
|
157 | 163 | parents=[initial], |
|
158 | 164 | branch=DEFAULT_BRANCH,) |
|
159 | 165 | |
|
160 | 166 | default_branch_commits = self.repo.get_commits(branch_name=DEFAULT_BRANCH) |
|
161 | 167 | assert docs_branch_commit1 not in list(default_branch_commits) |
|
162 | 168 | assert docs_branch_commit2 not in list(default_branch_commits) |
|
163 | 169 | |
|
164 | 170 | docs_branch_commits = self.repo.get_commits( |
|
165 | 171 | start_id=self.repo.commit_ids[0], end_id=self.repo.commit_ids[-1], |
|
166 | 172 | branch_name=TEST_BRANCH) |
|
167 | 173 | assert docs_branch_commit1 in list(docs_branch_commits) |
|
168 | 174 | assert docs_branch_commit2 in list(docs_branch_commits) |
|
169 | 175 | |
|
170 | 176 | @pytest.mark.backends("svn") |
|
171 | 177 | def test_get_commits_respects_branch_name_svn(self, vcsbackend_svn): |
|
172 | 178 | repo = vcsbackend_svn['svn-simple-layout'] |
|
173 | 179 | commits = repo.get_commits(branch_name='trunk') |
|
174 | 180 | commit_indexes = [c.idx for c in commits] |
|
175 | 181 | assert commit_indexes == [1, 2, 3, 7, 12, 15] |
|
176 | 182 | |
|
177 | 183 | def test_get_commit_by_index(self): |
|
178 | 184 | for idx in [1, 2, 3, 4]: |
|
179 | 185 | assert idx == self.repo.get_commit(commit_idx=idx).idx |
|
180 | 186 | |
|
181 | 187 | def test_get_commit_by_branch(self): |
|
182 | 188 | for branch, commit_id in self.repo.branches.items(): |
|
183 | 189 | assert commit_id == self.repo.get_commit(branch).raw_id |
|
184 | 190 | |
|
185 | 191 | def test_get_commit_by_tag(self): |
|
186 | 192 | for tag, commit_id in self.repo.tags.items(): |
|
187 | 193 | assert commit_id == self.repo.get_commit(tag).raw_id |
|
188 | 194 | |
|
189 | 195 | def test_get_commit_parents(self): |
|
190 | 196 | repo = self.repo |
|
191 | 197 | for test_idx in [1, 2, 3]: |
|
192 | 198 | commit = repo.get_commit(commit_idx=test_idx - 1) |
|
193 | 199 | assert [commit] == repo.get_commit(commit_idx=test_idx).parents |
|
194 | 200 | |
|
195 | 201 | def test_get_commit_children(self): |
|
196 | 202 | repo = self.repo |
|
197 | 203 | for test_idx in [1, 2, 3]: |
|
198 | 204 | commit = repo.get_commit(commit_idx=test_idx + 1) |
|
199 | 205 | assert [commit] == repo.get_commit(commit_idx=test_idx).children |
|
200 | 206 | |
|
201 | 207 | |
|
202 | 208 | @pytest.mark.usefixtures("vcs_repository_support") |
|
203 | 209 | class TestCommits(BackendTestMixin): |
|
204 | 210 | recreate_repo_per_test = False |
|
205 | 211 | |
|
206 | 212 | @classmethod |
|
207 | 213 | def _get_commits(cls): |
|
208 | 214 | start_date = datetime.datetime(2010, 1, 1, 20) |
|
209 | 215 | for x in range(5): |
|
210 | 216 | yield { |
|
211 | 217 | 'message': 'Commit %d' % x, |
|
212 | 218 | 'author': 'Joe Doe <joe.doe@example.com>', |
|
213 | 219 | 'date': start_date + datetime.timedelta(hours=12 * x), |
|
214 | 220 | 'added': [ |
|
215 | 221 | FileNode(b'file_%d.txt' % x, |
|
216 | 222 | content=b'Foobar %d' % x) |
|
217 | 223 | ], |
|
218 | 224 | } |
|
219 | 225 | |
|
220 | 226 | def test_simple(self): |
|
221 | 227 | tip = self.repo.get_commit() |
|
222 | 228 | assert tip.date, datetime.datetime(2010, 1, 3 == 20) |
|
223 | 229 | |
|
224 | 230 | def test_simple_serialized_commit(self): |
|
225 | 231 | tip = self.repo.get_commit() |
|
226 | 232 | # json.dumps(tip) uses .__json__() method |
|
227 | 233 | data = tip.__json__() |
|
228 | 234 | assert 'branch' in data |
|
229 | 235 | assert data['revision'] |
|
230 | 236 | |
|
231 | 237 | def test_retrieve_tip(self): |
|
232 | 238 | tip = self.repo.get_commit('tip') |
|
233 | 239 | assert tip == self.repo.get_commit() |
|
234 | 240 | |
|
235 | 241 | def test_invalid(self): |
|
236 | 242 | with pytest.raises(CommitDoesNotExistError): |
|
237 | 243 | self.repo.get_commit(commit_idx=123456789) |
|
238 | 244 | |
|
239 | 245 | def test_idx(self): |
|
240 | 246 | commit = self.repo[0] |
|
241 | 247 | assert commit.idx == 0 |
|
242 | 248 | |
|
243 | 249 | def test_negative_idx(self): |
|
244 | 250 | commit = self.repo.get_commit(commit_idx=-1) |
|
245 | 251 | assert commit.idx >= 0 |
|
246 | 252 | |
|
247 | 253 | def test_revision_is_deprecated(self): |
|
248 | 254 | def get_revision(commit): |
|
249 | 255 | return commit.revision |
|
250 | 256 | |
|
251 | 257 | commit = self.repo[0] |
|
252 | 258 | pytest.deprecated_call(get_revision, commit) |
|
253 | 259 | |
|
254 | 260 | def test_size(self): |
|
255 | 261 | tip = self.repo.get_commit() |
|
256 | 262 | size = 5 * len('Foobar N') # Size of 5 files |
|
257 | 263 | assert tip.size == size |
|
258 | 264 | |
|
259 | 265 | def test_size_at_commit(self): |
|
260 | 266 | tip = self.repo.get_commit() |
|
261 | 267 | size = 5 * len('Foobar N') # Size of 5 files |
|
262 | 268 | assert self.repo.size_at_commit(tip.raw_id) == size |
|
263 | 269 | |
|
264 | 270 | def test_size_at_first_commit(self): |
|
265 | 271 | commit = self.repo[0] |
|
266 | 272 | size = len('Foobar N') # Size of 1 file |
|
267 | 273 | assert self.repo.size_at_commit(commit.raw_id) == size |
|
268 | 274 | |
|
269 | 275 | def test_author(self): |
|
270 | 276 | tip = self.repo.get_commit() |
|
271 | 277 | assert_text_equal(tip.author, 'Joe Doe <joe.doe@example.com>') |
|
272 | 278 | |
|
273 | 279 | def test_author_name(self): |
|
274 | 280 | tip = self.repo.get_commit() |
|
275 | 281 | assert_text_equal(tip.author_name, 'Joe Doe') |
|
276 | 282 | |
|
277 | 283 | def test_author_email(self): |
|
278 | 284 | tip = self.repo.get_commit() |
|
279 | 285 | assert_text_equal(tip.author_email, 'joe.doe@example.com') |
|
280 | 286 | |
|
281 | 287 | def test_message(self): |
|
282 | 288 | tip = self.repo.get_commit() |
|
283 | 289 | assert_text_equal(tip.message, 'Commit 4') |
|
284 | 290 | |
|
285 | 291 | def test_diff(self): |
|
286 | 292 | tip = self.repo.get_commit() |
|
287 | 293 | diff = tip.diff() |
|
288 | 294 | assert b"+Foobar 4" in diff.raw.tobytes() |
|
289 | 295 | |
|
290 | 296 | def test_prev(self): |
|
291 | 297 | tip = self.repo.get_commit() |
|
292 | 298 | prev_commit = tip.prev() |
|
293 | 299 | assert prev_commit.message == 'Commit 3' |
|
294 | 300 | |
|
295 | 301 | def test_prev_raises_on_first_commit(self): |
|
296 | 302 | commit = self.repo.get_commit(commit_idx=0) |
|
297 | 303 | with pytest.raises(CommitDoesNotExistError): |
|
298 | 304 | commit.prev() |
|
299 | 305 | |
|
300 | 306 | def test_prev_works_on_second_commit_issue_183(self): |
|
301 | 307 | commit = self.repo.get_commit(commit_idx=1) |
|
302 | 308 | prev_commit = commit.prev() |
|
303 | 309 | assert prev_commit.idx == 0 |
|
304 | 310 | |
|
305 | 311 | def test_next(self): |
|
306 | 312 | commit = self.repo.get_commit(commit_idx=2) |
|
307 | 313 | next_commit = commit.next() |
|
308 | 314 | assert next_commit.message == 'Commit 3' |
|
309 | 315 | |
|
310 | 316 | def test_next_raises_on_tip(self): |
|
311 | 317 | commit = self.repo.get_commit() |
|
312 | 318 | with pytest.raises(CommitDoesNotExistError): |
|
313 | 319 | commit.next() |
|
314 | 320 | |
|
315 | 321 | def test_get_path_commit(self): |
|
316 | 322 | commit = self.repo.get_commit() |
|
317 | 323 | commit.get_path_commit('file_4.txt') |
|
318 | 324 | assert commit.message == 'Commit 4' |
|
319 | 325 | |
|
320 | 326 | def test_get_filenodes_generator(self): |
|
321 | 327 | tip = self.repo.get_commit() |
|
322 | 328 | filepaths = [node.path for node in tip.get_filenodes_generator()] |
|
323 | 329 | assert filepaths == ['file_%d.txt' % x for x in range(5)] |
|
324 | 330 | |
|
325 | 331 | def test_get_file_annotate(self): |
|
326 | 332 | file_added_commit = self.repo.get_commit(commit_idx=3) |
|
327 | 333 | annotations = list(file_added_commit.get_file_annotate('file_3.txt')) |
|
328 | 334 | |
|
329 | 335 | line_no, commit_id, commit_loader, line = annotations[0] |
|
330 | 336 | |
|
331 | 337 | assert line_no == 1 |
|
332 | 338 | assert commit_id == file_added_commit.raw_id |
|
333 | 339 | assert commit_loader() == file_added_commit |
|
334 | 340 | assert b'Foobar 3' in line |
|
335 | 341 | |
|
336 | 342 | def test_get_file_annotate_does_not_exist(self): |
|
337 | 343 | file_added_commit = self.repo.get_commit(commit_idx=2) |
|
338 | 344 | # TODO: Should use a specific exception class here? |
|
339 | 345 | with pytest.raises(Exception): |
|
340 | 346 | list(file_added_commit.get_file_annotate('file_3.txt')) |
|
341 | 347 | |
|
342 | 348 | def test_get_file_annotate_tip(self): |
|
343 | 349 | tip = self.repo.get_commit() |
|
344 | 350 | commit = self.repo.get_commit(commit_idx=3) |
|
345 | 351 | expected_values = list(commit.get_file_annotate('file_3.txt')) |
|
346 | 352 | annotations = list(tip.get_file_annotate('file_3.txt')) |
|
347 | 353 | |
|
348 | 354 | # Note: Skip index 2 because the loader function is not the same |
|
349 | 355 | for idx in (0, 1, 3): |
|
350 | 356 | assert annotations[0][idx] == expected_values[0][idx] |
|
351 | 357 | |
|
352 | 358 | def test_get_commits_is_ordered_by_date(self): |
|
353 | 359 | commits = self.repo.get_commits() |
|
354 | 360 | assert isinstance(commits, CollectionGenerator) |
|
355 | 361 | assert len(commits) == 0 or len(commits) != 0 |
|
356 | 362 | commits = list(commits) |
|
357 | 363 | ordered_by_date = sorted(commits, key=lambda commit: commit.date) |
|
358 | 364 | assert commits == ordered_by_date |
|
359 | 365 | |
|
360 | 366 | def test_get_commits_respects_start(self): |
|
361 | 367 | second_id = self.repo.commit_ids[1] |
|
362 | 368 | commits = self.repo.get_commits(start_id=second_id) |
|
363 | 369 | assert isinstance(commits, CollectionGenerator) |
|
364 | 370 | commits = list(commits) |
|
365 | 371 | assert len(commits) == 4 |
|
366 | 372 | |
|
367 | 373 | def test_get_commits_includes_start_commit(self): |
|
368 | 374 | second_id = self.repo.commit_ids[1] |
|
369 | 375 | commits = self.repo.get_commits(start_id=second_id) |
|
370 | 376 | assert isinstance(commits, CollectionGenerator) |
|
371 | 377 | commits = list(commits) |
|
372 | 378 | assert commits[0].raw_id == second_id |
|
373 | 379 | |
|
374 | 380 | def test_get_commits_respects_end(self): |
|
375 | 381 | second_id = self.repo.commit_ids[1] |
|
376 | 382 | commits = self.repo.get_commits(end_id=second_id) |
|
377 | 383 | assert isinstance(commits, CollectionGenerator) |
|
378 | 384 | commits = list(commits) |
|
379 | 385 | assert commits[-1].raw_id == second_id |
|
380 | 386 | assert len(commits) == 2 |
|
381 | 387 | |
|
382 | 388 | def test_get_commits_respects_both_start_and_end(self): |
|
383 | 389 | second_id = self.repo.commit_ids[1] |
|
384 | 390 | third_id = self.repo.commit_ids[2] |
|
385 | 391 | commits = self.repo.get_commits(start_id=second_id, end_id=third_id) |
|
386 | 392 | assert isinstance(commits, CollectionGenerator) |
|
387 | 393 | commits = list(commits) |
|
388 | 394 | assert len(commits) == 2 |
|
389 | 395 | |
|
390 | 396 | def test_get_commits_on_empty_repo_raises_EmptyRepository_error(self): |
|
391 | 397 | repo_path = get_new_dir(str(time.time())) |
|
392 | 398 | repo = self.Backend(repo_path, create=True) |
|
393 | 399 | |
|
394 | 400 | with pytest.raises(EmptyRepositoryError): |
|
395 | 401 | list(repo.get_commits(start_id='foobar')) |
|
396 | 402 | |
|
397 | 403 | def test_get_commits_respects_hidden(self): |
|
398 | 404 | commits = self.repo.get_commits(show_hidden=True) |
|
399 | 405 | assert isinstance(commits, CollectionGenerator) |
|
400 | 406 | assert len(commits) == 5 |
|
401 | 407 | |
|
402 | 408 | def test_get_commits_includes_end_commit(self): |
|
403 | 409 | second_id = self.repo.commit_ids[1] |
|
404 | 410 | commits = self.repo.get_commits(end_id=second_id) |
|
405 | 411 | assert isinstance(commits, CollectionGenerator) |
|
406 | 412 | assert len(commits) == 2 |
|
407 | 413 | commits = list(commits) |
|
408 | 414 | assert commits[-1].raw_id == second_id |
|
409 | 415 | |
|
410 | 416 | def test_get_commits_respects_start_date(self): |
|
411 | 417 | start_date = datetime.datetime(2010, 1, 2) |
|
412 | 418 | commits = self.repo.get_commits(start_date=start_date) |
|
413 | 419 | assert isinstance(commits, CollectionGenerator) |
|
414 | 420 | # Should be 4 commits after 2010-01-02 00:00:00 |
|
415 | 421 | assert len(commits) == 4 |
|
416 | 422 | for c in commits: |
|
417 | 423 | assert c.date >= start_date |
|
418 | 424 | |
|
419 | 425 | def test_get_commits_respects_start_date_with_branch(self): |
|
420 | 426 | start_date = datetime.datetime(2010, 1, 2) |
|
421 | 427 | commits = self.repo.get_commits( |
|
422 | 428 | start_date=start_date, branch_name=self.repo.DEFAULT_BRANCH_NAME) |
|
423 | 429 | assert isinstance(commits, CollectionGenerator) |
|
424 | 430 | # Should be 4 commits after 2010-01-02 00:00:00 |
|
425 | 431 | assert len(commits) == 4 |
|
426 | 432 | for c in commits: |
|
427 | 433 | assert c.date >= start_date |
|
428 | 434 | |
|
429 | 435 | def test_get_commits_respects_start_date_and_end_date(self): |
|
430 | 436 | start_date = datetime.datetime(2010, 1, 2) |
|
431 | 437 | end_date = datetime.datetime(2010, 1, 3) |
|
432 | 438 | commits = self.repo.get_commits(start_date=start_date, |
|
433 | 439 | end_date=end_date) |
|
434 | 440 | assert isinstance(commits, CollectionGenerator) |
|
435 | 441 | assert len(commits) == 2 |
|
436 | 442 | for c in commits: |
|
437 | 443 | assert c.date >= start_date |
|
438 | 444 | assert c.date <= end_date |
|
439 | 445 | |
|
440 | 446 | def test_get_commits_respects_end_date(self): |
|
441 | 447 | end_date = datetime.datetime(2010, 1, 2) |
|
442 | 448 | commits = self.repo.get_commits(end_date=end_date) |
|
443 | 449 | assert isinstance(commits, CollectionGenerator) |
|
444 | 450 | assert len(commits) == 1 |
|
445 | 451 | for c in commits: |
|
446 | 452 | assert c.date <= end_date |
|
447 | 453 | |
|
448 | 454 | def test_get_commits_respects_reverse(self): |
|
449 | 455 | commits = self.repo.get_commits() # no longer reverse support |
|
450 | 456 | assert isinstance(commits, CollectionGenerator) |
|
451 | 457 | assert len(commits) == 5 |
|
452 | 458 | commit_ids = reversed([c.raw_id for c in commits]) |
|
453 | 459 | assert list(commit_ids) == list(reversed(self.repo.commit_ids)) |
|
454 | 460 | |
|
455 | 461 | def test_get_commits_slice_generator(self): |
|
456 | 462 | commits = self.repo.get_commits( |
|
457 | 463 | branch_name=self.repo.DEFAULT_BRANCH_NAME) |
|
458 | 464 | assert isinstance(commits, CollectionGenerator) |
|
459 | 465 | commit_slice = list(commits[1:3]) |
|
460 | 466 | assert len(commit_slice) == 2 |
|
461 | 467 | |
|
462 | 468 | def test_get_commits_raise_commitdoesnotexist_for_wrong_start(self): |
|
463 | 469 | with pytest.raises(CommitDoesNotExistError): |
|
464 | 470 | list(self.repo.get_commits(start_id='foobar')) |
|
465 | 471 | |
|
466 | 472 | def test_get_commits_raise_commitdoesnotexist_for_wrong_end(self): |
|
467 | 473 | with pytest.raises(CommitDoesNotExistError): |
|
468 | 474 | list(self.repo.get_commits(end_id='foobar')) |
|
469 | 475 | |
|
470 | 476 | def test_get_commits_raise_branchdoesnotexist_for_wrong_branch_name(self): |
|
471 | 477 | with pytest.raises(BranchDoesNotExistError): |
|
472 | 478 | list(self.repo.get_commits(branch_name='foobar')) |
|
473 | 479 | |
|
474 | 480 | def test_get_commits_raise_repositoryerror_for_wrong_start_end(self): |
|
475 | 481 | start_id = self.repo.commit_ids[-1] |
|
476 | 482 | end_id = self.repo.commit_ids[0] |
|
477 | 483 | with pytest.raises(RepositoryError): |
|
478 | 484 | list(self.repo.get_commits(start_id=start_id, end_id=end_id)) |
|
479 | 485 | |
|
480 | 486 | def test_get_commits_raises_for_numerical_ids(self): |
|
481 | 487 | with pytest.raises(TypeError): |
|
482 | 488 | self.repo.get_commits(start_id=1, end_id=2) |
|
483 | 489 | |
|
484 | 490 | def test_commit_equality(self): |
|
485 | 491 | commit1 = self.repo.get_commit(self.repo.commit_ids[0]) |
|
486 | 492 | commit2 = self.repo.get_commit(self.repo.commit_ids[1]) |
|
487 | 493 | |
|
488 | 494 | assert commit1 == commit1 |
|
489 | 495 | assert commit2 == commit2 |
|
490 | 496 | assert commit1 != commit2 |
|
491 | 497 | assert commit2 != commit1 |
|
492 | 498 | assert commit1 is not None |
|
493 | 499 | assert commit2 is not None |
|
494 | 500 | assert 1 != commit1 |
|
495 | 501 | assert 'string' != commit1 |
|
496 | 502 | |
|
497 | 503 | |
|
498 | 504 | @pytest.mark.parametrize("filename, expected", [ |
|
499 | 505 | ("README.rst", False), |
|
500 | 506 | ("README", True), |
|
501 | 507 | ]) |
|
502 | 508 | def test_commit_is_link(vcsbackend, filename, expected): |
|
503 | 509 | commit = vcsbackend.repo.get_commit() |
|
504 | 510 | link_status = commit.is_link(filename) |
|
505 | 511 | assert link_status is expected |
|
506 | 512 | |
|
507 | 513 | |
|
508 | 514 | @pytest.mark.usefixtures("vcs_repository_support") |
|
509 | 515 | class TestCommitsChanges(BackendTestMixin): |
|
510 | 516 | recreate_repo_per_test = False |
|
511 | 517 | |
|
512 | 518 | @classmethod |
|
513 | 519 | def _get_commits(cls): |
|
514 | 520 | return [ |
|
515 | 521 | { |
|
516 | 522 | 'message': 'Initial', |
|
517 | 523 | 'author': 'Joe Doe <joe.doe@example.com>', |
|
518 | 524 | 'date': datetime.datetime(2010, 1, 1, 20), |
|
519 | 525 | 'added': [ |
|
520 | 526 | FileNode(b'foo/bar', content=b'foo'), |
|
521 | 527 | FileNode(safe_bytes('foo/bał'), content=b'foo'), |
|
522 | 528 | FileNode(b'foobar', content=b'foo'), |
|
523 | 529 | FileNode(b'qwe', content=b'foo'), |
|
524 | 530 | ], |
|
525 | 531 | }, |
|
526 | 532 | { |
|
527 | 533 | 'message': 'Massive changes', |
|
528 | 534 | 'author': 'Joe Doe <joe.doe@example.com>', |
|
529 | 535 | 'date': datetime.datetime(2010, 1, 1, 22), |
|
530 | 536 | 'added': [FileNode(b'fallout', content=b'War never changes')], |
|
531 | 537 | 'changed': [ |
|
532 | 538 | FileNode(b'foo/bar', content=b'baz'), |
|
533 | 539 | FileNode(b'foobar', content=b'baz'), |
|
534 | 540 | ], |
|
535 | 541 | 'removed': [FileNode(b'qwe')], |
|
536 | 542 | }, |
|
537 | 543 | ] |
|
538 | 544 | |
|
539 | 545 | def test_initial_commit(self, local_dt_to_utc): |
|
540 | 546 | commit = self.repo.get_commit(commit_idx=0) |
|
541 | 547 | assert set(commit.added) == { |
|
542 | 548 | commit.get_node('foo/bar'), |
|
543 | 549 | commit.get_node('foo/bał'), |
|
544 | 550 | commit.get_node('foobar'), |
|
545 | 551 | commit.get_node('qwe') |
|
546 | 552 | } |
|
547 | 553 | assert set(commit.changed) == set() |
|
548 | 554 | assert set(commit.removed) == set() |
|
549 | 555 | assert set(commit.affected_files) == {'foo/bar', 'foo/bał', 'foobar', 'qwe'} |
|
550 | 556 | assert commit.date == local_dt_to_utc( |
|
551 | 557 | datetime.datetime(2010, 1, 1, 20, 0)) |
|
552 | 558 | |
|
553 | 559 | def test_head_added(self): |
|
554 | 560 | commit = self.repo.get_commit() |
|
555 | 561 | assert isinstance(commit.added, AddedFileNodesGenerator) |
|
556 | 562 | assert set(commit.added) == {commit.get_node('fallout')} |
|
557 | 563 | assert isinstance(commit.changed, ChangedFileNodesGenerator) |
|
558 | 564 | assert set(commit.changed) == {commit.get_node('foo/bar'), commit.get_node('foobar')} |
|
559 | 565 | assert isinstance(commit.removed, RemovedFileNodesGenerator) |
|
560 | 566 | assert len(commit.removed) == 1 |
|
561 | 567 | assert list(commit.removed)[0].path == 'qwe' |
|
562 | 568 | |
|
563 | 569 | def test_get_filemode(self): |
|
564 | 570 | commit = self.repo.get_commit() |
|
565 | 571 | assert FILEMODE_DEFAULT == commit.get_file_mode('foo/bar') |
|
566 | 572 | |
|
567 | 573 | def test_get_filemode_non_ascii(self): |
|
568 | 574 | commit = self.repo.get_commit() |
|
569 | 575 | assert FILEMODE_DEFAULT == commit.get_file_mode('foo/bał') |
|
570 | 576 | assert FILEMODE_DEFAULT == commit.get_file_mode('foo/bał') |
|
571 | 577 | |
|
572 | 578 | def test_get_path_history(self): |
|
573 | 579 | commit = self.repo.get_commit() |
|
574 | 580 | history = commit.get_path_history('foo/bar') |
|
575 | 581 | assert len(history) == 2 |
|
576 | 582 | |
|
577 | 583 | def test_get_path_history_with_limit(self): |
|
578 | 584 | commit = self.repo.get_commit() |
|
579 | 585 | history = commit.get_path_history('foo/bar', limit=1) |
|
580 | 586 | assert len(history) == 1 |
|
581 | 587 | |
|
582 | 588 | def test_get_path_history_first_commit(self): |
|
583 | 589 | commit = self.repo[0] |
|
584 | 590 | history = commit.get_path_history('foo/bar') |
|
585 | 591 | assert len(history) == 1 |
|
586 | 592 | |
|
587 | 593 | |
|
588 | 594 | def assert_text_equal(expected, given): |
|
589 | 595 | assert expected == given |
|
590 | 596 | assert isinstance(expected, str) |
|
591 | 597 | assert isinstance(given, str) |
General Comments 0
You need to be logged in to leave comments.
Login now