def test_tzoffset_plus_hours(repo: GitRepository): 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_source_code_before_complete(): gr = GitRepository('test-repos/test12') m1 = gr.get_commit('ca1f75455f064410360bc56218d0418221cf9484' '').modifications[0] with open('test-repos/test12/sc_A_ca1f75455f064410360bc56218d0418221cf9484' '.txt') as f: sc = f.read() assert m1.source_code == sc assert m1.source_code_before is None old_sc = sc with open('test-repos/test12/sc_A_022ebf5fba835c6d95e99eaccc2d85b3db5a2ec0' '.txt') as f: sc = f.read() m1 = gr.get_commit('022ebf5fba835c6d95e99eaccc2d85b3db5a2ec0' '').modifications[0] assert m1.source_code == sc assert m1.source_code_before == old_sc old_sc = sc m1 = gr.get_commit('ecd6780457835a2fc85c532338a29f2c98a6cfeb' '').modifications[0] assert m1.source_code is None assert m1.source_code_before == old_sc
def test_modification_with_more_parents(): gr = GitRepository('test-repos/test11') c = gr.get_commit('ce6bcd987a6a53cc55da7cef9f8bb128adf68741') assert len(c.modifications) == 0 c = gr.get_commit('1b03d13c816f576eb82a8c3e935fbcacff6c2e8d') assert len(c.modifications) == 0
def test_tzoffset_minus_hours(repo: GitRepository): 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_equal(repo: GitRepository): c1 = repo.get_commit('e7d13b0511f8a176284ce4f92ed8c6e8d09c77f2') c2 = repo.get_commit(c1.parents[0]) c3 = repo.get_commit('a4ece0762e797d2e2dcbd471115108dd6e05ff58') assert c1.parents[0] == 'a4ece0762e797d2e2dcbd471115108dd6e05ff58' assert c3 == c2 assert c1 != c3
def test_number_of_modifications(repo: GitRepository): commit = repo.get_commit('866e997a9e44cb4ddd9e00efe49361420aff2559') assert commit.modifications[0].added == 62 assert commit.modifications[0].removed == 0 commit = repo.get_commit('d11dd6734ff4e60cac3a7b58d9267f138c9e05c7') assert commit.modifications[0].added == 1 assert commit.modifications[0].removed == 1
def test_number_of_modifications(): gr = GitRepository('test-repos/git-1/') commit = gr.get_commit('866e997a9e44cb4ddd9e00efe49361420aff2559') assert 62 == commit.modifications[0].added assert 0 == commit.modifications[0].removed commit = gr.get_commit('d11dd6734ff4e60cac3a7b58d9267f138c9e05c7') assert 1 == commit.modifications[0].added assert 1 == commit.modifications[0].removed
def test_parent_commits(repo: GitRepository): merge_commit = repo.get_commit('29e929fbc5dc6a2e9c620069b24e2a143af4285f') assert len(merge_commit.parents) == 2 assert '8986af2a679759e5a15794f6d56e6d46c3f302f1' in merge_commit.parents assert '8169f76a3d7add54b4fc7bca7160d1f1eede6eda' in merge_commit.parents normal_commit = repo.get_commit('8169f76a3d7add54b4fc7bca7160d1f1eede6eda') assert len(normal_commit.parents) == 1 assert '168b3aab057ed61a769acf336a4ef5e64f76c9fd' in normal_commit.parents
def test_merge_commits(repo: GitRepository): commit = repo.get_commit("168b3aab057ed61a769acf336a4ef5e64f76c9fd") assert commit.merge is False commit = repo.get_commit("8169f76a3d7add54b4fc7bca7160d1f1eede6eda") assert commit.merge is False commit = repo.get_commit("29e929fbc5dc6a2e9c620069b24e2a143af4285f") assert commit.merge is True
def test_modification_status(): gr = GitRepository('test-repos/git-1/') commit = gr.get_commit('866e997a9e44cb4ddd9e00efe49361420aff2559') assert ModificationType.ADD == commit.modifications[0].change_type commit = gr.get_commit('57dbd017d1a744b949e7ca0b1c1a3b3dd4c1cbc1') assert ModificationType.MODIFY == commit.modifications[0].change_type commit = gr.get_commit('ffccf1e7497eb8136fd66ed5e42bef29677c4b71') assert ModificationType.DELETE == commit.modifications[0].change_type
def test_merge_commits(): gr = GitRepository('test-repos/git-2/') commit = gr.get_commit("168b3aab057ed61a769acf336a4ef5e64f76c9fd") assert False == commit.merge commit = gr.get_commit("8169f76a3d7add54b4fc7bca7160d1f1eede6eda") assert False == commit.merge commit = gr.get_commit("29e929fbc5dc6a2e9c620069b24e2a143af4285f") assert True == commit.merge
def test_parent_commits(): gr = GitRepository('test-repos/git-5/') merge_commit = gr.get_commit('5d9d79607d7e82b6f236aa29be4ba89a28fb4f15') assert len(merge_commit.parents) == 2 assert 'fa8217c324e7fb46c80e1ddf907f4e141449637e' in merge_commit.parents assert 'ff663cf1931a67d5e47b75fc77dcea432c728052' in merge_commit.parents normal_commit = gr.get_commit('ff663cf1931a67d5e47b75fc77dcea432c728052') assert len(normal_commit.parents) == 1 assert '4a17f31c0d1285477a3a467d0bc3cb38e775097d' in normal_commit.parents
def test_branches_from_commit(repo: GitRepository): commit = repo.get_commit('a997e9d400f742003dea601bb05a9315d14d1124') assert len(commit.branches) == 1 assert 'b2' in commit.branches commit = repo.get_commit('866e997a9e44cb4ddd9e00efe49361420aff2559') assert len(commit.branches) == 2 assert 'master' in commit.branches assert 'b2' in commit.branches
def test_branches_from_commit(): gr = GitRepository('test-repos/git-1/') commit = gr.get_commit('a997e9d400f742003dea601bb05a9315d14d1124') assert 1 == len(commit.branches) assert 'b2' in commit.branches commit = gr.get_commit('866e997a9e44cb4ddd9e00efe49361420aff2559') assert 2 == len(commit.branches) assert 'master' in commit.branches assert 'b2' in commit.branches
def test_eq_commit(): gr = GitRepository('test-repos/git-11') c1 = gr.get_commit('1734d6da01378bad3aade12b52bb4aa8954835dc') c2 = gr.get_commit('2c1327f957ba3b2a5e86eaed097b0a425236719e') c3 = gr.get_commit('1734d6da01378bad3aade12b52bb4aa8954835dc') m1 = gr.get_commit('1734d6da01378bad3aade12b52bb4aa8954835dc' '').modifications[0] assert c1 == c3 assert c1 == c1 assert c1 != m1 assert c1 != c2
def test_eq_commit(repo: GitRepository): c1 = repo.get_commit('6411e3096dd2070438a17b225f44475136e54e3a') c2 = repo.get_commit('09f6182cef737db02a085e1d018963c7a29bde5a') c3 = repo.get_commit('6411e3096dd2070438a17b225f44475136e54e3a') c4 = repo.get_commit('09f6182cef737db02a085e1d018963c7a29bde5a') assert c1 == c3 assert c1 == c1 assert c2 == c4 assert c2 == c2 assert c1 != c2 assert c3 != c4
def test_modification_status(repo: GitRepository): commit = repo.get_commit('866e997a9e44cb4ddd9e00efe49361420aff2559') assert commit.modifications[0].change_type == ModificationType.ADD assert commit.modifications[0].old_path is None commit = repo.get_commit('57dbd017d1a744b949e7ca0b1c1a3b3dd4c1cbc1') assert commit.modifications[0].change_type == ModificationType.MODIFY assert commit.modifications[0].new_path == commit.modifications[0].old_path commit = repo.get_commit('ffccf1e7497eb8136fd66ed5e42bef29677c4b71') assert commit.modifications[0].change_type == ModificationType.DELETE assert commit.modifications[0].new_path is None
def test_other_branches_with_merge(repo: GitRepository): commit = repo.get_commit('7203c0b8220dcc7a59614bc7549799cd203ac072') assert commit.in_main_branch is False commit = repo.get_commit('87a31153090808f1e6f679a14ea28729a0b74f4d') assert commit.in_main_branch is False commit = repo.get_commit('b197ef4f0b4bc5b7d55c8949ecb1c861731f0b9d') assert commit.in_main_branch is True commit = repo.get_commit('e51421e0beae6a3c20bdcdfc21066e05db675e03') assert commit.in_main_branch is True
def test_eq_modifications(repo: GitRepository): m1 = repo.get_commit('e7d13b0511f8a176284ce4f92ed8c6e8d09c77f2' '').modifications[0] m2 = repo.get_commit('e7d13b0511f8a176284ce4f92ed8c6e8d09c77f2' '').modifications[0] m3 = repo.get_commit('a4ece0762e797d2e2dcbd471115108dd6e05ff58' '').modifications[0] c1 = repo.get_commit('a4ece0762e797d2e2dcbd471115108dd6e05ff58') assert m1 == m2 assert m1 == m1 assert m1 != m3 assert m1 != c1
def test_commit_in_master_branch(repo): assert repo.get_head().hash == '29e929fbc5dc6a2e9c620069b24e2a143af4285f' repo.checkout('8986af2a679759e5a15794f6d56e6d46c3f302f1') git_to_change_head = GitRepository('test-repos/branches_merged') commit = git_to_change_head.get_commit('8169f76a3d7add54b4fc7bca7160d1f1eede6eda') assert commit.in_main_branch is False commit = git_to_change_head.get_commit('168b3aab057ed61a769acf336a4ef5e64f76c9fd') assert commit.in_main_branch is True repo.reset() assert repo.get_head().hash == '29e929fbc5dc6a2e9c620069b24e2a143af4285f'
def test_eq_modifications(): gr = GitRepository('test-repos/git-1') m1 = gr.get_commit('e7d13b0511f8a176284ce4f92ed8c6e8d09c77f2' '').modifications[0] m2 = gr.get_commit('e7d13b0511f8a176284ce4f92ed8c6e8d09c77f2' '').modifications[0] m3 = gr.get_commit('a4ece0762e797d2e2dcbd471115108dd6e05ff58' '').modifications[0] c1 = gr.get_commit('a4ece0762e797d2e2dcbd471115108dd6e05ff58') assert m1 == m2 assert m1 == m1 assert m1 != m3 assert m1 != c1
def test_other_branches_with_merge(): gr = GitRepository('test-repos/test3/') commit = gr.get_commit('8cdf925bde3be3a21490d75686116b88b8263e82') assert commit.in_main_branch is False commit = gr.get_commit('189988aa490b0e5f14ed0ecb155e0e2901425d05') assert commit.in_main_branch is True commit = gr.get_commit('17bfb3f02331a7ce770e0a6b90584cdd473c6993') assert commit.in_main_branch is True commit = gr.get_commit('b5c103c7f61d05b9a35364f1923ceacc9afe7ed9') assert commit.in_main_branch is True assert commit.merge is True
def test_commit_in_master_branch(): gr = GitRepository('test-repos/git-2/') assert '29e929fbc5dc6a2e9c620069b24e2a143af4285f' == gr.get_head().id gr.checkout('8986af2a679759e5a15794f6d56e6d46c3f302f1') git_to_change_head = GitRepository('test-repos/git-2/') commit = git_to_change_head.get_commit('8169f76a3d7add54b4fc7bca7160d1f1eede6eda') assert False == commit.in_main_branch commit = git_to_change_head.get_commit('168b3aab057ed61a769acf336a4ef5e64f76c9fd') assert True == commit.in_main_branch gr.reset() assert '29e929fbc5dc6a2e9c620069b24e2a143af4285f' == gr.get_head().id
def test_shortstats_add_and_del(repo: GitRepository): c1 = repo.get_commit('e7d13b0511f8a176284ce4f92ed8c6e8d09c77f2') assert c1.insertions == 1 assert c1.lines == 2 assert c1.files == 1 assert c1.deletions == 1
def test_source_code_before(): gr = GitRepository('test-repos/git-1') m1 = gr.get_commit('ffccf1e7497eb8136fd66ed5e42bef29677c4b71' '').modifications[0] assert m1.source_code is None assert m1.source_code_before is not None
def test_tzoffset(): gr = GitRepository('test-repos/git-1') tz1 = gr.get_commit( 'e7d13b0511f8a176284ce4f92ed8c6e8d09c77f2').author_timezone tz2 = gr.get_commit( 'e7d13b0511f8a176284ce4f92ed8c6e8d09c77f2').committer_timezone assert tz1 == 10800 # -3 hours assert tz2 == 10800 # -3 hours gr = GitRepository('test-repos/test1') tz1 = gr.get_commit( 'da39b1326dbc2edfe518b90672734a08f3c13458').author_timezone tz2 = gr.get_commit( 'da39b1326dbc2edfe518b90672734a08f3c13458').committer_timezone assert tz1 == -7200 # +2 hours assert tz2 == -7200 # +2 hours
def test_shortstats_all_additions(repo: GitRepository): c1 = repo.get_commit('a88c84ddf42066611e76e6cb690144e5357d132c') assert c1.insertions == 191 assert c1.lines == 191 assert c1.files == 2 assert c1.deletions == 0
def test_modification_type_unknown(): gr = GitRepository('test-repos/git-11') c = gr.get_commit('1734d6da01378bad3aade12b52bb4aa8954835dc') mod0 = c.modifications[0] assert mod0.change_type.name == 'UNKNOWN'
def test_shortstats_all_deletions(repo: GitRepository): c1 = repo.get_commit('6411e3096dd2070438a17b225f44475136e54e3a') assert c1.insertions == 0 assert c1.lines == 4 assert c1.files == 1 assert c1.deletions == 4
def test_shortstats_rename(repo: GitRepository): c1 = repo.get_commit('da39b1326dbc2edfe518b90672734a08f3c13458') assert c1.insertions == 0 assert c1.lines == 3 assert c1.files == 1 assert c1.deletions == 3