def reg_test_7_hidden_files(): '''Ensure leading periods in hidden file names are parsed. Regression test for: https://github.com/tarmstrong/git2json/issues/7 ''' fixture = open(get_tst_path() + 'fixtures/test_git2json-2.txt') commits = list(git2json.parse_commits(fixture.read())) second_commit = commits[1] changes = second_commit['changes'] second_change = changes[1] fname = second_change[2] eq_(fname, '.travis.yml')
def get_commit_files(commit): '''Ask git which files were modified in a given commit.''' # TODO git2json shouldn't make me call this command manually command = "git log -1 --pretty=raw --numstat {}".format(commit) try: with open('/dev/null', 'w') as stderr: git_log_out = subprocess.check_output(command.split(), stderr=stderr) + '\n' except subprocess.CalledProcessError: raise NotInGitDir() from git2json import parse_commits commit = list(parse_commits(git_log_out))[0] return [change[2] for change in commit['changes']]
def get_commit_files(commit): '''Ask git which files were modified in a given commit.''' # TODO git2json shouldn't make me call this command manually command = "git log -1 --pretty=raw --numstat {}".format(commit) try: with open('/dev/null', 'w') as stderr: git_log_out = subprocess.check_output( command.split(), stderr=stderr) + '\n' except subprocess.CalledProcessError: raise NotInGitDir() from git2json import parse_commits commit = list(parse_commits(git_log_out))[0] return [change[2] for change in commit['changes']]
def test_parse_commits(): commit = ('commit 78a7baf74a77055e25914f2d50812c92bd6243bf' '\ntree b72a934faf0e0bd3a333a6069cc67dd74114bb9b' '\nparent a4d8c6dbab70038b4585f7711873e71f92db47bf' '\nparent a4d8c6dbab70038b4585f7711873e71f92db47bf' '\nauthor Tavish Armstrong' ' <*****@*****.**> 1380495019 -0400' '\ncommitter Tavish Armstrong' ' <*****@*****.**> 1380495019 -0400' '\n\n Start examples section in the README\n' '\n9\t0\tREADME.rst\n9\t0\tREADME.rst\n\n') parsed = list(g.parse_commits(commit)) assert len(parsed) > 0
def reg_test_empty_message_lines(): '''Empty lines (usually caused by a carriage return) don't cause crashes. Regression test for: https://github.com/tarmstrong/git2json/issues/11 ''' fixture = CARRIAGE_RETURN_FIXTURE commits = list(git2json.parse_commits(fixture)) eq_(2, len(commits)) second_commit = commits[0] message = second_commit['message'] expected_message = '''Hi\rthere Hi\rthere''' eq_(message, expected_message)
def test_parse_commits(): commit = ( 'commit 78a7baf74a77055e25914f2d50812c92bd6243bf' '\ntree b72a934faf0e0bd3a333a6069cc67dd74114bb9b' '\nparent a4d8c6dbab70038b4585f7711873e71f92db47bf' '\nparent a4d8c6dbab70038b4585f7711873e71f92db47bf' '\nauthor Tavish Armstrong' ' <*****@*****.**> 1380495019 -0400' '\ncommitter Tavish Armstrong' ' <*****@*****.**> 1380495019 -0400' '\n\n Start examples section in the README\n' '\n9\t0\tREADME.rst\n9\t0\tREADME.rst\n\n' ) parsed = list(g.parse_commits(commit)) assert len(parsed) > 0
def int_test_parse_commits(): '''Integration test: try to parse an entire git log from a file''' fixture = open(get_tst_path() + 'fixtures/test_git2json-1.txt') commits = git2json.parse_commits(fixture) parent = commits[0]['parents'] assert len(parent) == 2 parent = commits[1]['parents'] assert len(parent) == 1 author = commits[0]['author']['name'] eq_(author, u'Fernando Perez') email = commits[0]['author']['email'] eq_(email.strip(), '*****@*****.**') author = commits[1]['author']['name'] eq_(author, 'MinRK') email = commits[1]['author']['email'] eq_(email, '*****@*****.**') committer = commits[0]['committer']['name'] eq_(committer, u'Fernando Perez') email = commits[0]['committer']['email'] eq_(email.strip(), '*****@*****.**') committer = commits[1]['committer']['name'] eq_(committer, 'MinRK') email = commits[1]['committer']['email'] eq_(email, '*****@*****.**') eq_(len(commits[0]['changes']), 0) eq_(len(commits[1]['changes']), 1)
def int_test_parse_commits(): '''Integration test: try to parse an entire git log from a file''' fixture = open(get_tst_path() + 'fixtures/test_git2json-1.txt') commits = list(git2json.parse_commits(fixture.read())) parent = commits[0]['parents'] assert len(parent) == 2 parent = commits[1]['parents'] assert len(parent) == 1 author = commits[0]['author']['name'] eq_(author, 'Fernando Perez') email = commits[0]['author']['email'] eq_(email.strip(), '*****@*****.**') author = commits[1]['author']['name'] eq_(author, 'MinRK') email = commits[1]['author']['email'] eq_(email, '*****@*****.**') committer = commits[0]['committer']['name'] eq_(committer, 'Fernando Perez') email = commits[0]['committer']['email'] eq_(email.strip(), '*****@*****.**') committer = commits[1]['committer']['name'] eq_(committer, 'MinRK') email = commits[1]['committer']['email'] eq_(email, '*****@*****.**') eq_(len(commits[0]['changes']), 0) eq_(len(commits[1]['changes']), 1)
import git2json as g import subprocess as s BENCH_REPO = '/home/tavish/capstone/nbdiff/.git' check_added = '1f52ff8b5acaa408948d7a73b07b9dd2554e863a' HEAD = check_added commits = g.parse_commits(g.run_git_log(extra_args=[HEAD + '..', '--']).read()) i = 0 for commit in commits: if i % 5 == 0: s.call(('git --git-dir=' + BENCH_REPO + ' checkout ' + commit).split()) benchmark_output = s.check_output(['python', 'benchmark.py', commit]) with open('results.csv', 'a') as out: out.write(benchmark_output) i += 1