Auto count tests and include in report

This commit is contained in:
Eli Ribble 2015-07-30 17:24:06 -06:00
parent 6c78e686ee
commit dfb42f6229
2 changed files with 126 additions and 41 deletions

View File

@ -1,41 +0,0 @@
#!/usr/bin/env python
import argparse
import datetime
import jinja2
import os
import subprocess
import teamanalysis.git
import teamanalysis.repos
import teamanalysis.time
import webbrowser
def _get_commits(repo, start, end):
abspath = '/Users/eliribble/src/{}/'.format(repo)
os.chdir(abspath)
command = [
'git',
'log',
'--pretty=format:"%h %aI"',
'--after={}'.format(start.isoformat()),
'--before={}'.format(end.isoformat())]
output = subprocess.check_output(command)
return output
def _show_summary(timepoint):
start, end = teamanalysis.time.get_checkpoint(timepoint)
results = {}
for repo in teamanalysis.repos.REPOSITORIES:
output = _get_commits(repo, start, end)
lines = output.split('\n')
results[repo] = len(lines) if output else 0
#print("{0:<30}: {1}".format(repo, results[repo]))
print("{}\t{}\t{}".format(start.date().isoformat(), end.date().isoformat(), sum(results.values())))
def main():
timepoint = datetime.datetime(2014, 1, 1, 0, 0, 1)
while timepoint < datetime.datetime.utcnow():
_show_summary(timepoint)
timepoint = timepoint + datetime.timedelta(days=7)
if __name__ == '__main__':
main()

126
bin/overview-by-date Executable file
View File

@ -0,0 +1,126 @@
#!/usr/bin/env python
import argparse
import datetime
import jinja2
import logging
import os
import pprint
import re
import subprocess
import teamanalysis.git
import teamanalysis.repos
import teamanalysis.time
import webbrowser
LOGGER = logging.getLogger('overview-by-date')
def _get_abspath(repo):
return '/Users/eliribble/src/teamanalysis/repos/{}/'.format(repo)
def _get_commit_count(repo, start, end):
abspath = _get_abspath(repo)
os.chdir(abspath)
command = ['git', 'checkout', 'master']
subprocess.check_output(command, stderr=subprocess.STDOUT)
command = [
'git',
'log',
'--pretty=format:"%h %aI"',
'--after={}'.format(start.isoformat()),
'--before={}'.format(end.isoformat())]
LOGGER.debug(" ".join(command))
output = subprocess.check_output(command)
lines = output.split('\n')
result = len(lines) if output else 0
return result
def _get_commit_sha_by_date(repo, timepoint):
abspath = _get_abspath(repo)
os.chdir(abspath)
command = [
'git',
'rev-list',
'-n',
'1',
'--before="{}"'.format(timepoint.date().isoformat()),
'master',
'--',
]
LOGGER.debug("%s", ' '.join(command))
output = subprocess.check_output(command)
output = output.strip()
LOGGER.debug("%s: %s", ' '.join(command), output)
return output
def _git_checkout_by_date(repo, timepoint):
abspath = _get_abspath(repo)
commit = _get_commit_sha_by_date(repo, timepoint)
os.chdir(abspath)
command = [
'git',
'checkout',
commit,
]
output = subprocess.check_output(command, stderr=subprocess.STDOUT)
LOGGER.debug("Checked out %s at %s", repo, timepoint.date().isoformat())
return output
TEST_FUNCTION_PATTERN = re.compile(r'\s+<Function')
def _count_tests(repo):
abspath = _get_abspath(repo)
os.chdir(abspath)
command = [
os.path.join(abspath, 've', 'bin', 'python'),
'/usr/local/bin/py.test',
'--collect-only'
]
LOGGER.debug(" ".join(command))
try:
output = subprocess.check_output(command, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError:
LOGGER.info("Failed to call py.test for %s", repo)
return 0
count = 0
for line in output.split('\n'):
if TEST_FUNCTION_PATTERN.match(line):
count += 1
LOGGER.debug("Counted %d tests for %s", count, repo)
return count
def _get_test_count(repo, end):
abspath = _get_abspath(repo)
_git_checkout_by_date(repo, end)
return _count_tests(repo)
def _show_summary(timepoint):
start, end = teamanalysis.time.get_checkpoint(timepoint)
LOGGER.debug("Working %s to %s for %s", start, end, timepoint)
results = {}
for repo in teamanalysis.repos.REPOSITORIES:
commits = _get_commit_count(repo, start, end)
tests = _get_test_count(repo, end)
results[repo] = {
'commits' : commits,
'tests' : tests,
}
#print("{0:<30}: {1}".format(repo, results[repo]))
#pprint.pprint({k: v['tests'] for k, v in results.items()})
#pprint.pprint({k: v['commits'] for k, v in results.items()})
totals = {
'commits' : sum([result['commits'] for result in results.values()]),
'tests' : sum([result['tests'] for result in results.values() if result['tests']]),
}
print("{}\t{}\t{}\t{}".format(start.date().isoformat(), end.date().isoformat(), totals['commits'], totals['tests']))
def main():
logging.basicConfig()
LOGGER.setLevel(logging.INFO)
#LOGGER.setLevel(logging.DEBUG)
timepoint = datetime.datetime(2015, 5, 1, 0, 0, 1)
now = datetime.datetime.utcnow()
while timepoint < now + datetime.timedelta(days=7):
_show_summary(timepoint)
timepoint = timepoint + datetime.timedelta(days=7)
if __name__ == '__main__':
main()