def test_only_authors(): lc = list( RepositoryMining('test-repos/git-10/', only_authors=["Maurício Aniche"]).traverse_commits()) assert len(lc) == 4 lc = list( RepositoryMining('test-repos/git-10/', only_authors=["ishepard"]).traverse_commits()) assert len(lc) == 1
def test_only_in_branches(): # by default, only analyze master assert len(list( RepositoryMining('test-repos/test8/').traverse_commits())) == 3 # only analyze b2 assert len( list( RepositoryMining('test-repos/test8/', only_in_branch='b2').traverse_commits())) == 4 # only analyze b1 assert len( list( RepositoryMining('test-repos/test8/', only_in_branch='b1').traverse_commits())) == 5
def test_no_filters(): lc = list(RepositoryMining('test-repos/git-4/').traverse_commits()) assert len(lc) == 3 assert lc[0].hash == 'a1b6136f978644ff1d89816bc0f2bd86f6d9d7f5' assert lc[1].hash == '375de7a8275ecdc0b28dc8de2568f47241f443e9' assert lc[2].hash == 'b8c2be250786975f1c6f47e96922096f1bb25e39'
def test_between_dates_reversed(): # logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s', level=logging.INFO) lc = list(RepositoryMining('test-repos/git-4/', since=dt1, to=dt2, reversed_order=True).traverse_commits()) assert len(lc) == 2 assert lc[0].hash == '375de7a8275ecdc0b28dc8de2568f47241f443e9' assert lc[1].hash == 'a1b6136f978644ff1d89816bc0f2bd86f6d9d7f5'
def mine(_type): p = psutil.Process(os.getpid()) dt1 = datetime(2017, 1, 1) dt2 = datetime(2017, 7, 1) all_commits = [] start = datetime.now() for commit in RepositoryMining('test-repos/hadoop', since=dt1, to=dt2).traverse_commits(): memory = p.memory_info()[0] / (2 ** 20) all_commits.append(memory) h = commit.author.name if _type == 0: continue for mod in commit.modifications: dd = mod.diff if _type == 1: continue if mod.filename.endswith('.java'): cc = mod.complexity end = datetime.now() diff = end - start return diff, all_commits
def test_between_dates_without_timezone(): dt1 = datetime(2016, 10, 8, 21, 0, 0) dt2 = datetime(2016, 10, 8, 21, 59, 0) list_commits = list(RepositoryMining('test-repos/git-4/', since=dt1, to=dt2).traverse_commits()) assert len(list_commits) == 2 assert list_commits[0].hash == 'a1b6136f978644ff1d89816bc0f2bd86f6d9d7f5' assert list_commits[1].hash == '375de7a8275ecdc0b28dc8de2568f47241f443e9'
def test_only_in_main_branch(): lc = list(RepositoryMining('test-repos/git-5/').traverse_commits()) assert len(lc) == 5 assert lc[0].hash == '4a17f31c0d1285477a3a467d0bc3cb38e775097d' assert lc[1].hash == 'ff663cf1931a67d5e47b75fc77dcea432c728052' assert lc[2].hash == 'fa8217c324e7fb46c80e1ddf907f4e141449637e' assert lc[3].hash == '5d9d79607d7e82b6f236aa29be4ba89a28fb4f15' assert lc[4].hash == '377e0f474d70f6205784d0150ee0069a050c29ed'
def test_mod_with_file_types(): lc = list( RepositoryMining( 'test-repos/git-4/', only_modifications_with_file_types=['.java']).traverse_commits()) assert len(lc) == 2 assert lc[0].hash == 'a1b6136f978644ff1d89816bc0f2bd86f6d9d7f5' assert lc[1].hash == 'b8c2be250786975f1c6f47e96922096f1bb25e39'
def test_mod_with_file_types(): lc = list( RepositoryMining( 'test-repos/git-7/', only_modifications_with_file_types=['.java']).traverse_commits()) assert len(lc) == 2 assert lc[0].hash == '5adbb71167e79ab6b974827e74c9da4d81977655' assert lc[1].hash == '0577bec2387ee131e1ccf336adcc172224d3f6f9'
def test_between_dates_reversed(): lc = list( RepositoryMining('test-repos/git-4/', single='375de7a8275ecdc0b28dc8de2568f47241f443e9'). traverse_commits()) to_zone = timezone(timedelta(hours=-4)) dt = datetime(2016, 10, 8, 17, 57, 49, tzinfo=to_zone) assert lc[0].author_date == dt
def test_one_timezone(): lc = list( RepositoryMining('test-repos/git-2/', single='29e929fbc5dc6a2e9c620069b24e2a143af4285f'). traverse_commits()) to_zone = timezone(timedelta(hours=2)) dt = datetime(2016, 4, 4, 13, 21, 25, tzinfo=to_zone) assert lc[0].author_date == dt
def test_multiple_filters(): lc = list( RepositoryMining('test-repos/git-5/', only_no_merge=True).traverse_commits()) assert len(lc) == 4 assert lc[0].hash == '4a17f31c0d1285477a3a467d0bc3cb38e775097d' assert lc[1].hash == 'ff663cf1931a67d5e47b75fc77dcea432c728052' assert lc[2].hash == 'fa8217c324e7fb46c80e1ddf907f4e141449637e' assert lc[3].hash == '377e0f474d70f6205784d0150ee0069a050c29ed'
def test_between_revisions(): from_tag = 'tag1' to_tag = 'tag3' lc = list( RepositoryMining('test-repos/git-8/', from_tag=from_tag, to_tag=to_tag).traverse_commits()) assert len(lc) == 5 assert '6bb9e2c6a8080e6b5b34e6e316c894b2ddbf7fcd' == lc[0].hash assert 'f1a90b8d7b151ceefd3e3dfc0dc1d0e12b5f48d0' == lc[1].hash assert '4638730126d40716e230c2040751a13153fb1556' == lc[2].hash assert 'a26f1438bd85d6b22497c0e5dae003812becd0bc' == lc[3].hash assert '627e1ad917a188a861c9fedf6e5858b79edbe439' == lc[4].hash
def test_only_commits(): # 4e669cb4f69245dc669e116517d80d038d8e0434 # 29e929fbc5dc6a2e9c620069b24e2a143af4285f # 8986af2a679759e5a15794f6d56e6d46c3f302f1 # 8169f76a3d7add54b4fc7bca7160d1f1eede6eda # 168b3aab057ed61a769acf336a4ef5e64f76c9fd lc = list( RepositoryMining('test-repos/git-10/', only_commits=[ "4e669cb4f69245dc669e116517d80d038d8e0434" ]).traverse_commits()) assert len(lc) == 1 assert lc[0].hash == "4e669cb4f69245dc669e116517d80d038d8e0434" lc = list( RepositoryMining('test-repos/git-10/', only_commits=[ "4e669cb4f69245dc669e116517d80d038d8e0434", "8986af2a679759e5a15794f6d56e6d46c3f302f1" ]).traverse_commits()) assert len(lc) == 2 assert lc[0].hash == "8986af2a679759e5a15794f6d56e6d46c3f302f1" assert lc[1].hash == "4e669cb4f69245dc669e116517d80d038d8e0434" lc = list( RepositoryMining('test-repos/git-10/', only_commits=[ "4e669cb4f69245dc669e116517d80d038d8e0434", "8986af2a679759e5a15794f6d56e6d46c3f302f1", "29e929fbc5dc6a2e9c620069b24e2a143af4285f" ]).traverse_commits()) assert len(lc) == 3 assert lc[0].hash == "8986af2a679759e5a15794f6d56e6d46c3f302f1" assert lc[1].hash == "29e929fbc5dc6a2e9c620069b24e2a143af4285f" assert lc[2].hash == "4e669cb4f69245dc669e116517d80d038d8e0434" lc = list( RepositoryMining('test-repos/git-10/', only_commits=["fake hash"]).traverse_commits()) assert len(lc) == 0 only_commits = len( list( RepositoryMining('test-repos/git-10/', only_commits=[ "4e669cb4f69245dc669e116517d80d038d8e0434", "29e929fbc5dc6a2e9c620069b24e2a143af4285f", "8986af2a679759e5a15794f6d56e6d46c3f302f1", "8169f76a3d7add54b4fc7bca7160d1f1eede6eda", "168b3aab057ed61a769acf336a4ef5e64f76c9fd" ]).traverse_commits())) total_commits = len( list(RepositoryMining('test-repos/git-10/').traverse_commits())) assert total_commits == only_commits
def test_multiple_filters_exceptions(): from_commit = '6411e3096dd2070438a17b225f44475136e54e3a' from_tag = 'v1.4' with pytest.raises(Exception): for commit in RepositoryMining('test-repos/test1/', from_commit=from_commit, from_tag=from_tag).traverse_commits(): print(commit.hash) with pytest.raises(Exception): for commit in RepositoryMining( 'test-repos/test1/', since=dt2, from_commit=from_commit).traverse_commits(): print(commit.hash) with pytest.raises(Exception): for commit in RepositoryMining('test-repos/test1/', since=dt2, from_tag=from_tag).traverse_commits(): print(commit.hash) with pytest.raises(Exception): for commit in RepositoryMining('test-repos/test1/', to=dt2, to_tag=from_tag).traverse_commits(): print(commit.hash) with pytest.raises(Exception): for commit in RepositoryMining('test-repos/test1/', single=from_commit, to=dt2, to_tag=from_tag).traverse_commits(): print(commit.hash) with pytest.raises(Exception): for commit in RepositoryMining('test-repos/test1/', to_commit=from_commit, to=dt2).traverse_commits(): print(commit.hash)
def repository_mining_st(path, since, to): return list(RepositoryMining(path, since=since, to=to).traverse_commits())
def lc(request): reversed = request.param yield list( RepositoryMining('test-repos/git-4', reversed_order=reversed).traverse_commits())
def test_only_in_branch_not_exist(): with pytest.raises(Exception): list( RepositoryMining('test-repos/git-5/', only_in_branch='branch7').traverse_commits())
def repository_mining_cc(path, from_commit, to_commit): return list( RepositoryMining(path, from_commit=from_commit, to_commit=to_commit).traverse_commits())
def repository_mining_tt(path, from_tag, to_tag): return list( RepositoryMining(path, from_tag=from_tag, to_tag=to_tag).traverse_commits())
def test_between_dates(): list_commits = list(RepositoryMining('test-repos/git-4/', since=dt1, to=dt2).traverse_commits()) assert len(list_commits) == 2 assert list_commits[0].hash == 'a1b6136f978644ff1d89816bc0f2bd86f6d9d7f5' assert list_commits[1].hash == '375de7a8275ecdc0b28dc8de2568f47241f443e9'