Skip to content

Commit b8408b1

Browse files
author
Jaakko Kangasharju
committed
Add script to verify regressions against a known-good database
When trying to optimize performance, it is really important to not break the calculations that are being performed. To make this easier to verify, add a script that takes two project names for the same repository (intended to be a known-good version and a new improved version) and verifies that the data computed for each commit is the same. Future improvements: Verify the whole database, though verifying the commits does the important parts. Run this automatically (will need to wait until proper CI is set up anyway).
1 parent 97b7372 commit b8408b1

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/check_regression.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import sys
2+
import itertools
3+
4+
from githammer import Hammer
5+
6+
7+
def check_commit(index, commit_old, commit_new, attr):
8+
old_attr = getattr(commit_old, attr)
9+
new_attr = getattr(commit_new, attr)
10+
if old_attr != new_attr:
11+
sys.exit('Error in commit {} ({}): Incorrect {} {} (expected {})'.
12+
format(index, commit_old.hexsha, attr, new_attr, old_attr))
13+
14+
15+
if len(sys.argv) < 3:
16+
sys.exit('Usage: {} <known good project> <new project>'.format(sys.argv[0]))
17+
18+
hammer_old = Hammer(sys.argv[1])
19+
hammer_new = Hammer(sys.argv[2])
20+
21+
count = 0
22+
23+
for (index, (commit_old, commit_new)) in enumerate(itertools.zip_longest(hammer_old.iter_individual_commits(),
24+
hammer_new.iter_individual_commits())):
25+
check_commit(index, commit_old, commit_new, 'hexsha')
26+
check_commit(index, commit_old, commit_new, 'author_name')
27+
check_commit(index, commit_old, commit_new, 'added_lines')
28+
check_commit(index, commit_old, commit_new, 'deleted_lines')
29+
check_commit(index, commit_old, commit_new, 'commit_time')
30+
check_commit(index, commit_old, commit_new, 'commit_time_utc_offset')
31+
check_commit(index, commit_old, commit_new, 'line_counts')
32+
check_commit(index, commit_old, commit_new, 'test_counts')
33+
count += 1
34+
35+
print('OK, checked {} commits'.format(count))

0 commit comments

Comments
 (0)