def test_detail_rename(repo: Git): commit = repo.get_commit('f0dd1308bd904a9b108a6a40865166ee962af3d4') assert commit.author.name == "MaurĂcio Aniche" assert commit.author.email == "*****@*****.**" assert commit.modified_files[0].new_path == "Matricula.javax" assert commit.modified_files[0].old_path == "Matricula.java"
def test_get_commits_last_modified_lines_hyper_blame_unblamable(tmp_path, repo: Git): p = tmp_path / "ignore.txt" p.write_text("540c7f31c18664a38190fafb6721b5174ff4a166") buggy_commits = repo.get_commits_last_modified_lines(repo.get_commit( 'e6d3b38a9ef683e8184eac10a0471075c2808bbd'), hashes_to_ignore_path=str(p)) assert len(buggy_commits) == 0
def test_get_commits_last_modified_lines_hyper_blame_with_renaming(repo: Git): buggy_commits = repo.get_commits_last_modified_lines(repo.get_commit( 'be0772cbaa2eba32bf97aae885199d1a357ddc93')) assert len(buggy_commits) == 2 assert '9568d20856728304ab0b4d2d02fb9e81d0e5156d' in buggy_commits[ 'A.java'] assert '9568d20856728304ab0b4d2d02fb9e81d0e5156d' in buggy_commits[ 'H.java']
def test_get_commits_last_modified_lines_multiple(repo: Git): buggy_commits = repo.get_commits_last_modified_lines(repo.get_commit('9942ee9dcdd1103e5808d544a84e6bc8cade0e54')) assert len(buggy_commits) == 1 assert '2eb905e5e7be414fd184d6b4f1571b142621f4de' in buggy_commits[ 'A.java'] assert '20a40688521c1802569e60f9d55342c3bfdd772c' in buggy_commits[ 'A.java'] assert '22505e97dca6f843549b3a484b3609be4e3acf17' in buggy_commits[ 'A.java']
def test_modification_dictset(repo: Git): c1 = repo.get_commit("e7d13b0511f8a176284ce4f92ed8c6e8d09c77f2") c2 = repo.get_commit(c1.parents[0]) m1 = c1.modified_files[0] m2s = c2.modified_files mod_dict = {m1: c1, m2s[0]: c2, m2s[1]: c2} assert type(mod_dict) == dict assert mod_dict[m1].hash == "e7d13b0511f8a176284ce4f92ed8c6e8d09c77f2" assert mod_dict[m2s[0]].hash == c1.parents[0] assert mod_dict[m2s[1]].hash == c1.parents[0] assert m1 != m2s[0] mod_set = {m1}.union(set(m2s)) assert type(mod_set) == set assert m1 in mod_set assert mod_set - {m1} == set(m2s)
def test_get_commits_last_modified_lines_hyper_blame_ignore_hash(tmp_path, repo: Git): p = tmp_path / "ignore.txt" p.write_text("5cb9e9ae44a0949ec91d06a955975289be766f34") buggy_commits = repo.get_commits_last_modified_lines(repo.get_commit( 'c7002fb321a8ba32a28fac200538f7c2ba76f175'), hashes_to_ignore_path=str(p)) assert len(buggy_commits) == 1 assert 'c41d270f8abc203c895309235adbd5f3f81d4a45' in buggy_commits[ 'A.java']
def test_get_commits_last_modified_lines_for_single_file(repo: Git): commit = repo.get_commit('0f726924f96621e4965039123098ba83e39ffba6') buggy_commits = None for mod in commit.modified_files: if mod.filename == 'A.java': buggy_commits = repo.get_commits_last_modified_lines(commit, mod) assert buggy_commits assert len(buggy_commits) == 1 assert 'e2ed043eb96c05ebde653a44ae733ded9ef90750' in buggy_commits['A.java'] assert 1 == len(buggy_commits['A.java'])
def test_commit_in_master_branch(repo: Git): assert repo.get_head().hash == '29e929fbc5dc6a2e9c620069b24e2a143af4285f' repo.checkout('8986af2a679759e5a15794f6d56e6d46c3f302f1') git_to_change_head = Git('test-repos/branches_merged') commit = git_to_change_head.get_commit('8169f76a3d7add54b4fc7bca7160d1f1eede6eda') assert commit.in_main_branch is False repo.reset() assert repo.get_head().hash == '29e929fbc5dc6a2e9c620069b24e2a143af4285f'
def test_should_detail_a_commit(repo: Git): commit = repo.get_commit('866e997a9e44cb4ddd9e00efe49361420aff2559') assert commit.author.name == "MaurĂcio Aniche" assert commit.author.email == "*****@*****.**" assert commit.msg == "Matricula adicionada" assert len(commit.modified_files) == 1 assert commit.modified_files[0].new_path == "Matricula.java" assert commit.modified_files[0].diff.startswith("@@ -0,0 +1,62 @@\n+package model;") is True assert commit.modified_files[0].source_code.startswith("package model;") is True
def test_diffs(repo: Git): commit = repo.get_commit('93b4b18673ca6fb5d563bbf930c45cd1198e979b') assert len(commit.modified_files) == 2 for mod in commit.modified_files: if mod.filename == 'file4.java': assert mod.deleted_lines == 8 assert mod.added_lines == 0 if mod.filename == 'file2.java': assert mod.deleted_lines == 12 assert mod.added_lines == 0
def test_get_commit(repo: Git): c = repo.get_commit('09f6182cef737db02a085e1d018963c7a29bde5a') to_zone = timezone(timedelta(hours=1)) assert c.hash == '09f6182cef737db02a085e1d018963c7a29bde5a' assert c.author.name == 'ishepard' assert c.committer.name == 'ishepard' assert c.author_date.timestamp() == datetime(2018, 3, 22, 10, 42, 3, tzinfo=to_zone).timestamp() assert len(c.modified_files) == 1 assert c.msg == 'Ooops file2' assert c.in_main_branch is True assert c.insertions == 4 assert c.deletions == 0 assert c.lines == 4 assert c.files == 1
def test_get_first_commit(repo: Git): c = repo.get_commit('a88c84ddf42066611e76e6cb690144e5357d132c') to_zone = timezone(timedelta(hours=1)) assert c.hash == 'a88c84ddf42066611e76e6cb690144e5357d132c' assert c.author.name == 'ishepard' assert c.committer.name == 'ishepard' assert c.author_date.timestamp() == datetime(2018, 3, 22, 10, 41, 11, tzinfo=to_zone).timestamp() assert c.committer_date.timestamp() == datetime(2018, 3, 22, 10, 41, 11, tzinfo=to_zone).timestamp() assert len(c.modified_files) == 2 assert c.msg == 'First commit adding 2 files' assert c.in_main_branch is True assert c.modified_files[0].change_type == ModificationType.ADD assert c.modified_files[1].change_type == ModificationType.ADD
def test_tzoffset_plus_hours(repo: Git): tz1 = repo.get_commit('da39b1326dbc2edfe518b90672734a08f3c13458').author_timezone tz2 = repo.get_commit('da39b1326dbc2edfe518b90672734a08f3c13458').committer_timezone assert tz1 == -7200 # +2 hours assert tz2 == -7200 # +2 hours
def test_tzoffset_minus_hours(repo: Git): tz1 = repo.get_commit('e7d13b0511f8a176284ce4f92ed8c6e8d09c77f2').author_timezone tz2 = repo.get_commit('e7d13b0511f8a176284ce4f92ed8c6e8d09c77f2').committer_timezone assert tz1 == 10800 # -3 hours assert tz2 == 10800 # -3 hours
def test_modification_with_more_parents(repo: Git): c = repo.get_commit('ce6bcd987a6a53cc55da7cef9f8bb128adf68741') assert len(c.modified_files) == 0 c = repo.get_commit('1b03d13c816f576eb82a8c3e935fbcacff6c2e8d') assert len(c.modified_files) == 0
def test_modification_type_unknown(repo: Git): c = repo.get_commit('1734d6da01378bad3aade12b52bb4aa8954835dc') mod0 = c.modified_files[0] assert mod0.change_type.name == 'UNKNOWN'
def test_projectpath(repo: Git): c = repo.get_commit('f0f8aea2db50ed9f16332d86af3629ff7780583e') assert c.project_path.endswith('files_in_directories') is True
def test_projectname(repo: Git): c = repo.get_commit('f0f8aea2db50ed9f16332d86af3629ff7780583e') assert c.project_name == 'files_in_directories'
def test_get_commits_last_modified_lines_rename(repo: Git): buggy_commits = repo.get_commits_last_modified_lines(repo.get_commit('2f2d0dec7cd06de4c2ed11ed010727a54af8ebf8')) assert len(buggy_commits) == 1 assert '00e61714fd76ff110d8da953aa1179809591f5aa' in buggy_commits[ str(Path('myfolder/Z.java'))]
def test_source_code_before(repo: Git): m1 = repo.get_commit('ffccf1e7497eb8136fd66ed5e42bef29677c4b71').modified_files[0] assert m1.source_code is None assert m1.source_code_before is not None
def test_get_commits_last_modified_lines_useless_lines(repo: Git): buggy_commits = repo.get_commits_last_modified_lines(repo.get_commit('3bc7295c16b7dfc15d5f82eb6962a2774e1b8420')) assert len(buggy_commits) == 1 assert 'c7fc2e870ce03b0b8dc29ed0eeb26d14e235ea3b' in buggy_commits[ 'H.java']
def test_get_commits_last_modified_lines_useless_lines2(repo: Git): buggy_commits = repo.get_commits_last_modified_lines(repo.get_commit('4155c421ee5cbb3c34feee7b68aa78a2ee1bbeae')) assert len(buggy_commits) == 0
def test_get_commits_last_modified_lines_simple(repo: Git): buggy_commits = repo.get_commits_last_modified_lines(repo.get_commit('e6d3b38a9ef683e8184eac10a0471075c2808bbd')) assert len(buggy_commits) == 1 assert '540c7f31c18664a38190fafb6721b5174ff4a166' in buggy_commits[ 'B.java']
def test_get_commits_last_modified_lines_with_more_modification(repo: Git): buggy_commits = repo.get_commits_last_modified_lines(repo.get_commit('c7002fb321a8ba32a28fac200538f7c2ba76f175')) assert len(buggy_commits) == 1 assert '5cb9e9ae44a0949ec91d06a955975289be766f34' in buggy_commits[ 'A.java']
def test_detached_head(repo: Git): c = repo.get_commit('56c5ef54d9d16d2b2255412f9479830b5b97cb99') assert c.in_main_branch is False
def test_get_commits_last_modified_lines_rename_and_fix(repo: Git): buggy_commits = repo.get_commits_last_modified_lines(repo.get_commit('4e287ab8e6dba110219404fb8a43993f3dda674c')) assert len(buggy_commits) == 1 assert '06b9ff31cd3475d9fd9ef668cc0844ab169da726' in buggy_commits[ 'H.java']