How to use PyDriller - 10 common examples

To help you get started, we’ve selected a few PyDriller examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ishepard / pydriller / tests / integration / test_commit_filters.py View on Github external
def test_single_commit():
    lc = list(RepositoryMining('test-repos/git-10/',
                               single="4e669cb4f69245dc669e116517d80d038d8e0434").traverse_commits())
    assert len(lc) == 1
    assert lc[0].hash == "4e669cb4f69245dc669e116517d80d038d8e0434"

    lc = list(RepositoryMining('test-repos/git-10/',
                               single="168b3aab057ed61a769acf336a4ef5e64f76c9fd").traverse_commits())
    assert len(lc) == 1
    assert lc[0].hash == "168b3aab057ed61a769acf336a4ef5e64f76c9fd"
github ishepard / pydriller / tests / test_git_repository.py View on Github external
def test_should_detail_a_commit():
    gr = GitRepository('test-repos/git-1/')
    commit = gr.get_commit('866e997a9e44cb4ddd9e00efe49361420aff2559')

    assert commit.author.name == "Maurício Aniche"
    assert commit.author.email == "mauricioaniche@gmail.com"

    assert commit.msg == "Matricula adicionada"
    assert len(commit.modifications) == 1

    assert commit.modifications[0].new_path == "Matricula.java"
    assert commit.modifications[0].diff.startswith("@@ -0,0 +1,62 @@\n+package model;") is True
    assert commit.modifications[0].source_code.startswith("package model;") is True
github ishepard / pydriller / tests / test_git_repository.py View on Github external
def test_get_commits_last_modified_lines_hyper_blame_unblamable(tmp_path):
    p = tmp_path / "ignore.txt"
    p.write_text("540c7f31c18664a38190fafb6721b5174ff4a166")

    gr = GitRepository('test-repos/test5/')

    buggy_commits = gr.get_commits_last_modified_lines(gr.get_commit(
        'e6d3b38a9ef683e8184eac10a0471075c2808bbd'),
        hashes_to_ignore_path=str(p))

    assert len(buggy_commits) == 0
github ishepard / pydriller / tests / test_commit.py View on Github external
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'))
github ishepard / pydriller / tests / test_commit.py View on Github external
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
github ishepard / pydriller / tests / test_commit.py View on Github external
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
github ishepard / pydriller / tests / test_git_repository.py View on Github external
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[
        'H.java']
github ishepard / pydriller / tests / test_git_repository.py View on Github external
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) == 1
    assert '2eb905e5e7be414fd184d6b4f1571b142621f4de' in buggy_commits[
        'A.java']
    assert '20a40688521c1802569e60f9d55342c3bfdd772c' in buggy_commits[
        'A.java']
    assert '22505e97dca6f843549b3a484b3609be4e3acf17' in buggy_commits[
        'A.java']
github ishepard / pydriller / tests / test_git_repository.py View on Github external
gr = GitRepository('test-repos/test1/')
    c = gr.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.modifications) == 2
    assert c.msg == 'First commit adding 2 files'
    assert c.in_main_branch is True

    assert c.modifications[0].change_type == ModificationType.ADD
    assert c.modifications[1].change_type == ModificationType.ADD
github ishepard / pydriller / tests / test_git_repository.py View on Github external
def test_modification_status():
    gr = GitRepository('test-repos/git-1/')
    commit = gr.get_commit('866e997a9e44cb4ddd9e00efe49361420aff2559')
    assert commit.modifications[0].change_type == ModificationType.ADD
    assert commit.modifications[0].old_path is None

    commit = gr.get_commit('57dbd017d1a744b949e7ca0b1c1a3b3dd4c1cbc1')
    assert commit.modifications[0].change_type == ModificationType.MODIFY
    assert commit.modifications[0].new_path == commit.modifications[0].old_path

    commit = gr.get_commit('ffccf1e7497eb8136fd66ed5e42bef29677c4b71')
    assert commit.modifications[0].change_type == ModificationType.DELETE
    assert commit.modifications[0].new_path is None