Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
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_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_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_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']
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']
def test_projectname():
gr = GitRepository('test-repos/test1/')
assert gr.project_name == "test1"
gr = GitRepository('test-repos/test1')
assert gr.project_name == "test1"
def test_checkout_consecutive_commits():
gr = GitRepository('test-repos/git-1/')
gr.checkout('a7053a4dcd627f5f4f213dc9aa002eb1caf926f8')
gr.checkout('f0dd1308bd904a9b108a6a40865166ee962af3d4')
gr.checkout('9e71dd5726d775fb4a5f08506a539216e878adbb')
files3 = gr.files()
assert len(files3) == 3
gr.reset()
def resource():
yield GitRepository('test-repos/git-1/')