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_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_get_all_commits(): gr = GitRepository('test-repos/git-1/') change_sets = gr.get_change_sets() assert 13 == len(change_sets) assert 'e7d13b0511f8a176284ce4f92ed8c6e8d09c77f2' == change_sets[0].id assert '866e997a9e44cb4ddd9e00efe49361420aff2559' == change_sets[12].id
def test_get_commits_last_modified_lines_simple(): gr = GitRepository('test-repos/test5/') buggy_commits = gr.get_commits_last_modified_lines(gr.get_commit('e6d3b38a9ef683e8184eac10a0471075c2808bbd')) assert len(buggy_commits) == 1 assert '540c7f31c18664a38190fafb6721b5174ff4a166' in buggy_commits
def test_get_commits_last_modified_lines_with_more_modification( repo: GitRepository): 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_get_commits_last_modified_lines_hyper_blame(repo: GitRepository): 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_rename(repo: GitRepository): 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_get_commits_last_modified_lines_rename_and_fix(repo: GitRepository): buggy_commits = repo.get_commits_last_modified_lines( repo.get_commit('4e287ab8e6dba110219404fb8a43993f3dda674c')) assert len(buggy_commits) == 1 assert '06b9ff31cd3475d9fd9ef668cc0844ab169da726' in buggy_commits[ 'H.java']
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_source_code_before_complete(repo: GitRepository): m1 = repo.get_commit( 'ca1f75455f064410360bc56218d0418221cf9484').modifications[0] with open('test-repos/source_code_before_commit/' '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/source_code_before_commit/' 'sc_A_022ebf5fba835c6d95e99eaccc2d85b3db5a2ec0.txt') as f: sc = f.read() m1 = repo.get_commit( '022ebf5fba835c6d95e99eaccc2d85b3db5a2ec0').modifications[0] assert m1.source_code == sc assert m1.source_code_before == old_sc old_sc = sc m1 = repo.get_commit( 'ecd6780457835a2fc85c532338a29f2c98a6cfeb').modifications[0] assert m1.source_code is None assert m1.source_code_before == old_sc
def test_get_commits_last_modified_lines_rename_simple(): gr = GitRepository('test-repos/test5/') buggy_commits = gr.get_commits_last_modified_lines(gr.get_commit('45ba0a61ccc448625bce0fea0301cf0c1ab32696')) assert len(buggy_commits) == 1 assert 'e358878a00e78aca8366264d61a7319d00dd8186' in buggy_commits
def test_get_commits_last_modified_lines_with_more_modification(): gr = GitRepository('test-repos/test5/') buggy_commits = gr.get_commits_last_modified_lines( gr.get_commit('c7002fb321a8ba32a28fac200538f7c2ba76f175')) assert len(buggy_commits) == 1 assert '5cb9e9ae44a0949ec91d06a955975289be766f34' in buggy_commits
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_get_commits_last_modified_lines_rename_simple_more_commits(): gr = GitRepository('test-repos/test5/') buggy_commits = gr.get_commits_last_modified_lines( gr.get_commit('4e287ab8e6dba110219404fb8a43993f3dda674c')) assert len(buggy_commits) == 1 assert '06b9ff31cd3475d9fd9ef668cc0844ab169da726' in buggy_commits
def test_get_commits_last_modified_lines_useless_lines(): gr = GitRepository('test-repos/test5/') buggy_commits = gr.get_commits_last_modified_lines( gr.get_commit('3bc7295c16b7dfc15d5f82eb6962a2774e1b8420')) assert len(buggy_commits) == 1 assert 'c7fc2e870ce03b0b8dc29ed0eeb26d14e235ea3b' in buggy_commits
def test_get_commits_last_modified_lines_multiple_rename(): gr = GitRepository('test-repos/test5/') # in this case the algorithm doesn't work because the file has been renamed 2 times! buggy_commits = gr.get_commits_last_modified_lines( gr.get_commit('9e858753b3d69f560cf72aaaa297f2608145ebcf')) assert len(buggy_commits) == 0
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_get_all_commits(): gr = GitRepository('test-repos/git-1/') change_sets = list(gr.get_list_commits()) assert len(change_sets) == 13 assert change_sets[0].hash == '866e997a9e44cb4ddd9e00efe49361420aff2559' assert change_sets[12].hash == 'e7d13b0511f8a176284ce4f92ed8c6e8d09c77f2'
def test_get_head(): gr = GitRepository('test-repos/test1/') assert gr is not None cs = gr.get_head() assert cs is not None assert cs.hash == 'da39b1326dbc2edfe518b90672734a08f3c13458' assert cs.author_date.timestamp() == 1522164679
def test_get_commit_from_tag(): gr = GitRepository('test-repos/test1/') commit = gr.get_commit_from_tag('v1.4') assert commit.hash == '09f6182cef737db02a085e1d018963c7a29bde5a' with pytest.raises(IndexError): gr.get_commit_from_tag('v1.5')
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_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_detail_rename(): gr = GitRepository('test-repos/git-1/') commit = gr.get_commit('f0dd1308bd904a9b108a6a40865166ee962af3d4') assert commit.author.name == "MaurĂcio Aniche" assert commit.author.email == "*****@*****.**" assert commit.modifications[0].new_path == "Matricula.javax" assert commit.modifications[0].old_path == "Matricula.java"
def test_tags(repo: GitRepository): commit = repo.get_commit_from_tag('tag1') assert commit.hash == '6bb9e2c6a8080e6b5b34e6e316c894b2ddbf7fcd' commit = repo.get_commit_from_tag('tag2') assert commit.hash == '4638730126d40716e230c2040751a13153fb1556' with pytest.raises(IndexError): repo.get_commit_from_tag('tag4')
def test_get_commits_last_modified_lines_multiple(): gr = GitRepository('test-repos/test5/') buggy_commits = gr.get_commits_last_modified_lines(gr.get_commit('9942ee9dcdd1103e5808d544a84e6bc8cade0e54')) assert len(buggy_commits) == 3 assert '2eb905e5e7be414fd184d6b4f1571b142621f4de' in buggy_commits assert '20a40688521c1802569e60f9d55342c3bfdd772c' in buggy_commits assert '22505e97dca6f843549b3a484b3609be4e3acf17' in buggy_commits
def test_filepahs(): gr = GitRepository('test-repos/test7') c = gr.get_commit('f0f8aea2db50ed9f16332d86af3629ff7780583e') mod0 = c.modifications[0] assert mod0.filename == 'a.java' assert mod0.new_path == str(Path('dir2/a.java')) assert mod0.old_path == str(Path('dir2/a.java'))
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_get_commits_modified_file(): gr = GitRepository('test-repos/test1/') commits = gr.get_commits_modified_file('file2.java') assert len(commits) == 3 assert '09f6182cef737db02a085e1d018963c7a29bde5a' in commits assert '6411e3096dd2070438a17b225f44475136e54e3a' in commits assert 'a88c84ddf42066611e76e6cb690144e5357d132c' in commits
def test_get_tagged_commits(): gr = GitRepository('test-repos/git-8/') tagged_commits = gr.get_tagged_commits() assert len(tagged_commits) == 3 assert '6bb9e2c6a8080e6b5b34e6e316c894b2ddbf7fcd' == tagged_commits[0] assert '4638730126d40716e230c2040751a13153fb1556' == tagged_commits[1] assert '627e1ad917a188a861c9fedf6e5858b79edbe439' == tagged_commits[2]