test_commits.py
583 lines
| 21.3 KiB
| text/x-python
|
PythonLexer
r5608 | # Copyright (C) 2010-2024 RhodeCode GmbH | |||
r1 | # | |||
# This program is free software: you can redistribute it and/or modify | ||||
# it under the terms of the GNU Affero General Public License, version 3 | ||||
# (only), as published by the Free Software Foundation. | ||||
# | ||||
# This program is distributed in the hope that it will be useful, | ||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
# GNU General Public License for more details. | ||||
# | ||||
# You should have received a copy of the GNU Affero General Public License | ||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
# | ||||
# This program is dual-licensed. If you wish to learn more about the | ||||
# RhodeCode Enterprise Edition, including its added features, Support services, | ||||
# and proprietary license terms, please see https://rhodecode.com/licenses/ | ||||
import datetime | ||||
import time | ||||
import pytest | ||||
r5087 | from rhodecode.lib.str_utils import safe_bytes | |||
r5647 | from rhodecode.lib.vcs.backends.base import CollectionGenerator, EmptyCommit | |||
r1 | from rhodecode.lib.vcs.exceptions import ( | |||
r5607 | BranchDoesNotExistError, | |||
CommitDoesNotExistError, | ||||
RepositoryError, | ||||
EmptyRepositoryError, | ||||
) | ||||
r5647 | from rhodecode.lib.vcs.nodes import FileNode | |||
r1 | from rhodecode.tests import get_new_dir | |||
r2453 | from rhodecode.tests.vcs.conftest import BackendTestMixin | |||
r5647 | from rhodecode.lib.vcs_common import NodeKind, FILEMODE_EXECUTABLE, FILEMODE_DEFAULT, FILEMODE_LINK | |||
r1 | ||||
r3742 | class TestBaseChangeset(object): | |||
r1 | def test_is_deprecated(self): | |||
from rhodecode.lib.vcs.backends.base import BaseChangeset | ||||
r5607 | ||||
r1 | pytest.deprecated_call(BaseChangeset) | |||
r2453 | class TestEmptyCommit(object): | |||
r1 | def test_branch_without_alias_returns_none(self): | |||
commit = EmptyCommit() | ||||
assert commit.branch is None | ||||
r2453 | @pytest.mark.usefixtures("vcs_repository_support") | |||
r1 | class TestCommitsInNonEmptyRepo(BackendTestMixin): | |||
recreate_repo_per_test = True | ||||
@classmethod | ||||
def _get_commits(cls): | ||||
start_date = datetime.datetime(2010, 1, 1, 20) | ||||
r4906 | for x in range(5): | |||
r1 | yield { | |||
r5607 | "message": "Commit %d" % x, | |||
"author": "Joe Doe <joe.doe@example.com>", | ||||
"date": start_date + datetime.timedelta(hours=12 * x), | ||||
"added": [ | ||||
FileNode(b"file_%d.txt" % x, content=b"Foobar %d" % x), | ||||
r1 | ], | |||
} | ||||
def test_walk_returns_empty_list_in_case_of_file(self): | ||||
r5647 | result = list(self.tip.walk(b"file_0.txt")) | |||
r1 | assert result == [] | |||
@pytest.mark.backends("git", "hg") | ||||
def test_new_branch(self): | ||||
r5607 | self.imc.add(FileNode(b"docs/index.txt", content=b"Documentation\n")) | |||
r1 | foobar_tip = self.imc.commit( | |||
r5607 | message="New branch: foobar", | |||
author="joe <joe@rhodecode.com>", | ||||
branch="foobar", | ||||
r1 | ) | |||
r5607 | assert "foobar" in self.repo.branches | |||
assert foobar_tip.branch == "foobar" | ||||
r1 | # 'foobar' should be the only branch that contains the new commit | |||
r5087 | branch = list(self.repo.branches.values()) | |||
r1 | assert branch[0] != branch[1] | |||
@pytest.mark.backends("git", "hg") | ||||
def test_new_head_in_default_branch(self): | ||||
tip = self.repo.get_commit() | ||||
r5225 | ||||
r5607 | self.imc.add(FileNode(b"docs/index.txt", content=b"Documentation\n")) | |||
r1 | foobar_tip = self.imc.commit( | |||
r5225 | message="New branch: foobar", | |||
author="joe <joe@rhodecode.com>", | ||||
branch="foobar", | ||||
r1 | parents=[tip], | |||
) | ||||
r5607 | self.imc.change(FileNode(b"docs/index.txt", content=b"Documentation\nand more...\n")) | |||
r5225 | assert foobar_tip.branch == "foobar" | |||
r1 | newtip = self.imc.commit( | |||
r5225 | message="At foobar_tip branch", | |||
author="joe <joe@rhodecode.com>", | ||||
r1 | branch=foobar_tip.branch, | |||
parents=[foobar_tip], | ||||
) | ||||
newest_tip = self.imc.commit( | ||||
r5225 | message=f"Merged with {foobar_tip.raw_id}", | |||
author="joe <joe@rhodecode.com>", | ||||
r1 | branch=self.backend_class.DEFAULT_BRANCH_NAME, | |||
r5225 | parents=[tip, newtip], | |||
r1 | ) | |||
assert newest_tip.branch == self.backend_class.DEFAULT_BRANCH_NAME | ||||
@pytest.mark.backends("git", "hg") | ||||
def test_get_commits_respects_branch_name(self): | ||||
""" | ||||
* e1930d0 (HEAD, master) Back in default branch | ||||
| * e1930d0 (docs) New Branch: docs2 | ||||
| * dcc14fa New branch: docs | ||||
|/ | ||||
* e63c41a Initial commit | ||||
... | ||||
* 624d3db Commit 0 | ||||
:return: | ||||
""" | ||||
DEFAULT_BRANCH = self.repo.DEFAULT_BRANCH_NAME | ||||
r5607 | TEST_BRANCH = "docs" | |||
r1 | org_tip = self.repo.get_commit() | |||
r5607 | self.imc.add(FileNode(b"readme.txt", content=b"Document\n")) | |||
r1 | initial = self.imc.commit( | |||
r5607 | message="Initial commit", | |||
author="joe <joe@rhodecode.com>", | ||||
r1 | parents=[org_tip], | |||
r5607 | branch=DEFAULT_BRANCH, | |||
) | ||||
r1 | ||||
r5607 | self.imc.add(FileNode(b"newdoc.txt", content=b"foobar\n")) | |||
r1 | docs_branch_commit1 = self.imc.commit( | |||
r5607 | message="New branch: docs", | |||
author="joe <joe@rhodecode.com>", | ||||
r1 | parents=[initial], | |||
r5607 | branch=TEST_BRANCH, | |||
) | ||||
r1 | ||||
r5607 | self.imc.add(FileNode(b"newdoc2.txt", content=b"foobar2\n")) | |||
r1 | docs_branch_commit2 = self.imc.commit( | |||
r5607 | message="New branch: docs2", | |||
author="joe <joe@rhodecode.com>", | ||||
r1 | parents=[docs_branch_commit1], | |||
r5607 | branch=TEST_BRANCH, | |||
) | ||||
r1 | ||||
r5607 | self.imc.add(FileNode(b"newfile", content=b"hello world\n")) | |||
r1 | self.imc.commit( | |||
r5607 | message="Back in default branch", | |||
author="joe <joe@rhodecode.com>", | ||||
r1 | parents=[initial], | |||
r5607 | branch=DEFAULT_BRANCH, | |||
) | ||||
r1 | ||||
r3740 | default_branch_commits = self.repo.get_commits(branch_name=DEFAULT_BRANCH) | |||
r1 | assert docs_branch_commit1 not in list(default_branch_commits) | |||
assert docs_branch_commit2 not in list(default_branch_commits) | ||||
docs_branch_commits = self.repo.get_commits( | ||||
r5607 | start_id=self.repo.commit_ids[0], end_id=self.repo.commit_ids[-1], branch_name=TEST_BRANCH | |||
) | ||||
r1 | assert docs_branch_commit1 in list(docs_branch_commits) | |||
assert docs_branch_commit2 in list(docs_branch_commits) | ||||
@pytest.mark.backends("svn") | ||||
def test_get_commits_respects_branch_name_svn(self, vcsbackend_svn): | ||||
r5607 | repo = vcsbackend_svn["svn-simple-layout"] | |||
commits = repo.get_commits(branch_name="trunk") | ||||
r1 | commit_indexes = [c.idx for c in commits] | |||
assert commit_indexes == [1, 2, 3, 7, 12, 15] | ||||
r3742 | def test_get_commit_by_index(self): | |||
for idx in [1, 2, 3, 4]: | ||||
assert idx == self.repo.get_commit(commit_idx=idx).idx | ||||
r1 | def test_get_commit_by_branch(self): | |||
r4932 | for branch, commit_id in self.repo.branches.items(): | |||
r1 | assert commit_id == self.repo.get_commit(branch).raw_id | |||
def test_get_commit_by_tag(self): | ||||
r4932 | for tag, commit_id in self.repo.tags.items(): | |||
r1 | assert commit_id == self.repo.get_commit(tag).raw_id | |||
def test_get_commit_parents(self): | ||||
repo = self.repo | ||||
for test_idx in [1, 2, 3]: | ||||
commit = repo.get_commit(commit_idx=test_idx - 1) | ||||
assert [commit] == repo.get_commit(commit_idx=test_idx).parents | ||||
def test_get_commit_children(self): | ||||
repo = self.repo | ||||
for test_idx in [1, 2, 3]: | ||||
commit = repo.get_commit(commit_idx=test_idx + 1) | ||||
assert [commit] == repo.get_commit(commit_idx=test_idx).children | ||||
r2453 | @pytest.mark.usefixtures("vcs_repository_support") | |||
r1 | class TestCommits(BackendTestMixin): | |||
recreate_repo_per_test = False | ||||
@classmethod | ||||
def _get_commits(cls): | ||||
start_date = datetime.datetime(2010, 1, 1, 20) | ||||
r4906 | for x in range(5): | |||
r1 | yield { | |||
r5607 | "message": "Commit %d" % x, | |||
"author": "Joe Doe <joe.doe@example.com>", | ||||
"date": start_date + datetime.timedelta(hours=12 * x), | ||||
"added": [FileNode(b"file_%d.txt" % x, content=b"Foobar %d" % x)], | ||||
r1 | } | |||
def test_simple(self): | ||||
tip = self.repo.get_commit() | ||||
assert tip.date, datetime.datetime(2010, 1, 3 == 20) | ||||
def test_simple_serialized_commit(self): | ||||
tip = self.repo.get_commit() | ||||
# json.dumps(tip) uses .__json__() method | ||||
data = tip.__json__() | ||||
r5607 | assert "branch" in data | |||
assert data["revision"] | ||||
r1 | ||||
def test_retrieve_tip(self): | ||||
r5607 | tip = self.repo.get_commit("tip") | |||
r1 | assert tip == self.repo.get_commit() | |||
def test_invalid(self): | ||||
with pytest.raises(CommitDoesNotExistError): | ||||
self.repo.get_commit(commit_idx=123456789) | ||||
def test_idx(self): | ||||
commit = self.repo[0] | ||||
assert commit.idx == 0 | ||||
def test_negative_idx(self): | ||||
commit = self.repo.get_commit(commit_idx=-1) | ||||
assert commit.idx >= 0 | ||||
def test_revision_is_deprecated(self): | ||||
def get_revision(commit): | ||||
return commit.revision | ||||
commit = self.repo[0] | ||||
pytest.deprecated_call(get_revision, commit) | ||||
def test_size(self): | ||||
tip = self.repo.get_commit() | ||||
r5607 | size = 5 * len("Foobar N") # Size of 5 files | |||
r1 | assert tip.size == size | |||
def test_size_at_commit(self): | ||||
tip = self.repo.get_commit() | ||||
r5607 | size = 5 * len("Foobar N") # Size of 5 files | |||
r1 | assert self.repo.size_at_commit(tip.raw_id) == size | |||
def test_size_at_first_commit(self): | ||||
commit = self.repo[0] | ||||
r5607 | size = len("Foobar N") # Size of 1 file | |||
r1 | assert self.repo.size_at_commit(commit.raw_id) == size | |||
def test_author(self): | ||||
tip = self.repo.get_commit() | ||||
r5607 | assert_text_equal(tip.author, "Joe Doe <joe.doe@example.com>") | |||
r1 | ||||
def test_author_name(self): | ||||
tip = self.repo.get_commit() | ||||
r5607 | assert_text_equal(tip.author_name, "Joe Doe") | |||
r1 | ||||
def test_author_email(self): | ||||
tip = self.repo.get_commit() | ||||
r5607 | assert_text_equal(tip.author_email, "joe.doe@example.com") | |||
r1 | ||||
def test_message(self): | ||||
tip = self.repo.get_commit() | ||||
r5607 | assert_text_equal(tip.message, "Commit 4") | |||
r1 | ||||
def test_diff(self): | ||||
tip = self.repo.get_commit() | ||||
diff = tip.diff() | ||||
r5087 | assert b"+Foobar 4" in diff.raw.tobytes() | |||
r1 | ||||
def test_prev(self): | ||||
tip = self.repo.get_commit() | ||||
prev_commit = tip.prev() | ||||
r5607 | assert prev_commit.message == "Commit 3" | |||
r1 | ||||
def test_prev_raises_on_first_commit(self): | ||||
commit = self.repo.get_commit(commit_idx=0) | ||||
with pytest.raises(CommitDoesNotExistError): | ||||
commit.prev() | ||||
def test_prev_works_on_second_commit_issue_183(self): | ||||
commit = self.repo.get_commit(commit_idx=1) | ||||
prev_commit = commit.prev() | ||||
assert prev_commit.idx == 0 | ||||
def test_next(self): | ||||
commit = self.repo.get_commit(commit_idx=2) | ||||
next_commit = commit.next() | ||||
r5607 | assert next_commit.message == "Commit 3" | |||
r1 | ||||
def test_next_raises_on_tip(self): | ||||
commit = self.repo.get_commit() | ||||
with pytest.raises(CommitDoesNotExistError): | ||||
commit.next() | ||||
r3275 | def test_get_path_commit(self): | |||
r1 | commit = self.repo.get_commit() | |||
r5647 | commit.get_path_commit(b"file_4.txt") | |||
r5607 | assert commit.message == "Commit 4" | |||
r1 | ||||
def test_get_filenodes_generator(self): | ||||
tip = self.repo.get_commit() | ||||
filepaths = [node.path for node in tip.get_filenodes_generator()] | ||||
r5607 | assert filepaths == ["file_%d.txt" % x for x in range(5)] | |||
r1 | ||||
def test_get_file_annotate(self): | ||||
file_added_commit = self.repo.get_commit(commit_idx=3) | ||||
r5607 | annotations = list(file_added_commit.get_file_annotate("file_3.txt")) | |||
r1351 | ||||
r1 | line_no, commit_id, commit_loader, line = annotations[0] | |||
r1351 | ||||
r1 | assert line_no == 1 | |||
assert commit_id == file_added_commit.raw_id | ||||
assert commit_loader() == file_added_commit | ||||
r5607 | assert b"Foobar 3" in line | |||
r1 | ||||
def test_get_file_annotate_does_not_exist(self): | ||||
file_added_commit = self.repo.get_commit(commit_idx=2) | ||||
# TODO: Should use a specific exception class here? | ||||
with pytest.raises(Exception): | ||||
r5607 | list(file_added_commit.get_file_annotate("file_3.txt")) | |||
r1 | ||||
def test_get_file_annotate_tip(self): | ||||
tip = self.repo.get_commit() | ||||
commit = self.repo.get_commit(commit_idx=3) | ||||
r5607 | expected_values = list(commit.get_file_annotate("file_3.txt")) | |||
annotations = list(tip.get_file_annotate("file_3.txt")) | ||||
r1 | ||||
# Note: Skip index 2 because the loader function is not the same | ||||
for idx in (0, 1, 3): | ||||
assert annotations[0][idx] == expected_values[0][idx] | ||||
def test_get_commits_is_ordered_by_date(self): | ||||
commits = self.repo.get_commits() | ||||
assert isinstance(commits, CollectionGenerator) | ||||
assert len(commits) == 0 or len(commits) != 0 | ||||
commits = list(commits) | ||||
ordered_by_date = sorted(commits, key=lambda commit: commit.date) | ||||
assert commits == ordered_by_date | ||||
def test_get_commits_respects_start(self): | ||||
second_id = self.repo.commit_ids[1] | ||||
commits = self.repo.get_commits(start_id=second_id) | ||||
assert isinstance(commits, CollectionGenerator) | ||||
commits = list(commits) | ||||
assert len(commits) == 4 | ||||
def test_get_commits_includes_start_commit(self): | ||||
second_id = self.repo.commit_ids[1] | ||||
commits = self.repo.get_commits(start_id=second_id) | ||||
assert isinstance(commits, CollectionGenerator) | ||||
commits = list(commits) | ||||
assert commits[0].raw_id == second_id | ||||
def test_get_commits_respects_end(self): | ||||
second_id = self.repo.commit_ids[1] | ||||
commits = self.repo.get_commits(end_id=second_id) | ||||
assert isinstance(commits, CollectionGenerator) | ||||
commits = list(commits) | ||||
assert commits[-1].raw_id == second_id | ||||
assert len(commits) == 2 | ||||
def test_get_commits_respects_both_start_and_end(self): | ||||
second_id = self.repo.commit_ids[1] | ||||
third_id = self.repo.commit_ids[2] | ||||
commits = self.repo.get_commits(start_id=second_id, end_id=third_id) | ||||
assert isinstance(commits, CollectionGenerator) | ||||
commits = list(commits) | ||||
assert len(commits) == 2 | ||||
def test_get_commits_on_empty_repo_raises_EmptyRepository_error(self): | ||||
repo_path = get_new_dir(str(time.time())) | ||||
repo = self.Backend(repo_path, create=True) | ||||
with pytest.raises(EmptyRepositoryError): | ||||
r5607 | list(repo.get_commits(start_id="foobar")) | |||
r1 | ||||
r2144 | def test_get_commits_respects_hidden(self): | |||
commits = self.repo.get_commits(show_hidden=True) | ||||
assert isinstance(commits, CollectionGenerator) | ||||
assert len(commits) == 5 | ||||
r1 | def test_get_commits_includes_end_commit(self): | |||
second_id = self.repo.commit_ids[1] | ||||
commits = self.repo.get_commits(end_id=second_id) | ||||
assert isinstance(commits, CollectionGenerator) | ||||
assert len(commits) == 2 | ||||
commits = list(commits) | ||||
assert commits[-1].raw_id == second_id | ||||
def test_get_commits_respects_start_date(self): | ||||
start_date = datetime.datetime(2010, 1, 2) | ||||
commits = self.repo.get_commits(start_date=start_date) | ||||
assert isinstance(commits, CollectionGenerator) | ||||
# Should be 4 commits after 2010-01-02 00:00:00 | ||||
assert len(commits) == 4 | ||||
for c in commits: | ||||
assert c.date >= start_date | ||||
r2144 | def test_get_commits_respects_start_date_with_branch(self): | |||
start_date = datetime.datetime(2010, 1, 2) | ||||
r5607 | commits = self.repo.get_commits(start_date=start_date, branch_name=self.repo.DEFAULT_BRANCH_NAME) | |||
r2144 | assert isinstance(commits, CollectionGenerator) | |||
# Should be 4 commits after 2010-01-02 00:00:00 | ||||
assert len(commits) == 4 | ||||
for c in commits: | ||||
assert c.date >= start_date | ||||
r1 | def test_get_commits_respects_start_date_and_end_date(self): | |||
start_date = datetime.datetime(2010, 1, 2) | ||||
end_date = datetime.datetime(2010, 1, 3) | ||||
r5607 | commits = self.repo.get_commits(start_date=start_date, end_date=end_date) | |||
r1 | assert isinstance(commits, CollectionGenerator) | |||
assert len(commits) == 2 | ||||
for c in commits: | ||||
assert c.date >= start_date | ||||
assert c.date <= end_date | ||||
def test_get_commits_respects_end_date(self): | ||||
end_date = datetime.datetime(2010, 1, 2) | ||||
commits = self.repo.get_commits(end_date=end_date) | ||||
assert isinstance(commits, CollectionGenerator) | ||||
assert len(commits) == 1 | ||||
for c in commits: | ||||
assert c.date <= end_date | ||||
def test_get_commits_respects_reverse(self): | ||||
commits = self.repo.get_commits() # no longer reverse support | ||||
assert isinstance(commits, CollectionGenerator) | ||||
assert len(commits) == 5 | ||||
commit_ids = reversed([c.raw_id for c in commits]) | ||||
assert list(commit_ids) == list(reversed(self.repo.commit_ids)) | ||||
def test_get_commits_slice_generator(self): | ||||
r5607 | commits = self.repo.get_commits(branch_name=self.repo.DEFAULT_BRANCH_NAME) | |||
r1 | assert isinstance(commits, CollectionGenerator) | |||
commit_slice = list(commits[1:3]) | ||||
assert len(commit_slice) == 2 | ||||
def test_get_commits_raise_commitdoesnotexist_for_wrong_start(self): | ||||
with pytest.raises(CommitDoesNotExistError): | ||||
r5607 | list(self.repo.get_commits(start_id="foobar")) | |||
r1 | ||||
def test_get_commits_raise_commitdoesnotexist_for_wrong_end(self): | ||||
with pytest.raises(CommitDoesNotExistError): | ||||
r5607 | list(self.repo.get_commits(end_id="foobar")) | |||
r1 | ||||
def test_get_commits_raise_branchdoesnotexist_for_wrong_branch_name(self): | ||||
with pytest.raises(BranchDoesNotExistError): | ||||
r5607 | list(self.repo.get_commits(branch_name="foobar")) | |||
r1 | ||||
def test_get_commits_raise_repositoryerror_for_wrong_start_end(self): | ||||
start_id = self.repo.commit_ids[-1] | ||||
end_id = self.repo.commit_ids[0] | ||||
with pytest.raises(RepositoryError): | ||||
list(self.repo.get_commits(start_id=start_id, end_id=end_id)) | ||||
def test_get_commits_raises_for_numerical_ids(self): | ||||
with pytest.raises(TypeError): | ||||
self.repo.get_commits(start_id=1, end_id=2) | ||||
r985 | def test_commit_equality(self): | |||
commit1 = self.repo.get_commit(self.repo.commit_ids[0]) | ||||
commit2 = self.repo.get_commit(self.repo.commit_ids[1]) | ||||
assert commit1 == commit1 | ||||
assert commit2 == commit2 | ||||
assert commit1 != commit2 | ||||
assert commit2 != commit1 | ||||
r5087 | assert commit1 is not None | |||
assert commit2 is not None | ||||
r985 | assert 1 != commit1 | |||
r5607 | assert "string" != commit1 | |||
r985 | ||||
r1 | ||||
r5607 | @pytest.mark.parametrize( | |||
"filename, expected", | ||||
[ | ||||
r5647 | (b"README.rst", False), | |||
(b"README", True), | ||||
r5607 | ], | |||
) | ||||
r1 | def test_commit_is_link(vcsbackend, filename, expected): | |||
commit = vcsbackend.repo.get_commit() | ||||
link_status = commit.is_link(filename) | ||||
assert link_status is expected | ||||
r2453 | @pytest.mark.usefixtures("vcs_repository_support") | |||
r1 | class TestCommitsChanges(BackendTestMixin): | |||
recreate_repo_per_test = False | ||||
@classmethod | ||||
def _get_commits(cls): | ||||
return [ | ||||
{ | ||||
r5607 | "message": "Initial", | |||
"author": "Joe Doe <joe.doe@example.com>", | ||||
"date": datetime.datetime(2010, 1, 1, 20), | ||||
"added": [ | ||||
FileNode(b"foo/bar", content=b"foo"), | ||||
FileNode(safe_bytes("foo/bał"), content=b"foo"), | ||||
FileNode(b"foobar", content=b"foo"), | ||||
FileNode(b"qwe", content=b"foo"), | ||||
r1 | ], | |||
}, | ||||
{ | ||||
r5607 | "message": "Massive changes", | |||
"author": "Joe Doe <joe.doe@example.com>", | ||||
"date": datetime.datetime(2010, 1, 1, 22), | ||||
"added": [FileNode(b"fallout", content=b"War never changes")], | ||||
"changed": [ | ||||
FileNode(b"foo/bar", content=b"baz"), | ||||
FileNode(b"foobar", content=b"baz"), | ||||
r1 | ], | |||
r5607 | "removed": [FileNode(b"qwe")], | |||
r1 | }, | |||
] | ||||
r1351 | def test_initial_commit(self, local_dt_to_utc): | |||
r1 | commit = self.repo.get_commit(commit_idx=0) | |||
r5647 | assert sorted(commit.added_paths) == sorted([b"foo/bar", b"foo/ba\xc5\x82", b"foobar", b"qwe"]) | |||
assert commit.changed_paths == [] | ||||
assert commit.removed_paths == [] | ||||
assert sorted(commit.affected_files) == sorted([b"foo/bar", b"foo/ba\xc5\x82", b"foobar", b"qwe"]) | ||||
r5607 | assert commit.date == local_dt_to_utc(datetime.datetime(2010, 1, 1, 20, 0)) | |||
r1 | ||||
def test_head_added(self): | ||||
commit = self.repo.get_commit() | ||||
r5647 | ||||
assert commit.added_paths == [b"fallout"] | ||||
assert commit.changed_paths == [b"foo/bar", b"foobar"] | ||||
assert commit.removed_paths == [b"qwe"] | ||||
r1 | ||||
def test_get_filemode(self): | ||||
commit = self.repo.get_commit() | ||||
r5647 | assert FILEMODE_DEFAULT == commit.get_file_mode(b"foo/bar") | |||
r1 | ||||
def test_get_filemode_non_ascii(self): | ||||
commit = self.repo.get_commit() | ||||
r5647 | assert FILEMODE_DEFAULT == commit.get_file_mode(b"foo/ba\xc5\x82") | |||
assert FILEMODE_DEFAULT == commit.get_file_mode(b"foo/ba\xc5\x82") | ||||
r1 | ||||
r3275 | def test_get_path_history(self): | |||
r1 | commit = self.repo.get_commit() | |||
r5647 | history = commit.get_path_history(b"foo/bar") | |||
r1 | assert len(history) == 2 | |||
r3275 | def test_get_path_history_with_limit(self): | |||
r1 | commit = self.repo.get_commit() | |||
r5647 | history = commit.get_path_history(b"foo/bar", limit=1) | |||
r1 | assert len(history) == 1 | |||
r3275 | def test_get_path_history_first_commit(self): | |||
r1 | commit = self.repo[0] | |||
r5647 | history = commit.get_path_history(b"foo/bar") | |||
r1 | assert len(history) == 1 | |||
def assert_text_equal(expected, given): | ||||
assert expected == given | ||||
r4952 | assert isinstance(expected, str) | |||
assert isinstance(given, str) | ||||