From 9abb7c32bbbebf228448619a3ecb8f78f6a6081f Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Sat, 19 Dec 2009 15:59:34 +0100 Subject: [PATCH] Add regression tests on gitdm output files Add simple regression tests that makes sure there are no regressions in the text output file and the date line count file. The primary purpose of introducing this regression test is to allow us to safely refactor the gitdm code. Signed-off-by: Martin Nordholts --- tests/expected-datelc | 2 + tests/expected-results.txt | 46 ++++++++ tests/gitdm-tests.py | 129 +++++++++++++++++++++ tests/testrepo/HEAD | 1 + tests/testrepo/config | 6 + tests/testrepo/info/refs | 1 + tests/testrepo/objects/info/packs | 2 + ...ck-f62fb949b32db1bccdc300fc13de20bca92b4c01.idx | Bin 0 -> 1912 bytes ...k-f62fb949b32db1bccdc300fc13de20bca92b4c01.pack | Bin 0 -> 2883 bytes tests/testrepo/packed-refs | 2 + 10 files changed, 189 insertions(+) create mode 100644 tests/expected-datelc create mode 100644 tests/expected-results.txt create mode 100755 tests/gitdm-tests.py create mode 100644 tests/testrepo/HEAD create mode 100644 tests/testrepo/config create mode 100644 tests/testrepo/info/refs create mode 100644 tests/testrepo/objects/info/packs create mode 100644 tests/testrepo/objects/pack/pack-f62fb949b32db1bccdc300fc13de20bca92b4c01.idx create mode 100644 tests/testrepo/objects/pack/pack-f62fb949b32db1bccdc300fc13de20bca92b4c01.pack create mode 100644 tests/testrepo/packed-refs diff --git a/tests/expected-datelc b/tests/expected-datelc new file mode 100644 index 0000000..f65ea92 --- /dev/null +++ b/tests/expected-datelc @@ -0,0 +1,2 @@ +2009/12/03 27 27 +2009/12/15 14 41 diff --git a/tests/expected-results.txt b/tests/expected-results.txt new file mode 100644 index 0000000..049f887 --- /dev/null +++ b/tests/expected-results.txt @@ -0,0 +1,46 @@ +Processed 10 csets from 4 developers +4 employers found +A total of 24 lines added, 24 removed (delta 0) + +Developers with the most changesets +Martin Nordholts 6 (60.0%) +Random Joe 2 (20.0%) +Line Remover 1 (10.0%) +Punk Rocker 1 (10.0%) + +Developers with the most changed lines +Line Remover 14 (34.1%) +Random Joe 13 (31.7%) +Martin Nordholts 10 (24.4%) +Punk Rocker 1 (2.4%) + +Developers with the most lines removed +Line Remover 14 (58.3%) + +Developers with the most signoffs (total 2) +Martin Nordholts 2 (100.0%) + +Developers with the most reviews (total 0) + +Developers with the most test credits (total 0) + +Developers who gave the most tested-by credits (total 0) + +Developers with the most report credits (total 0) + +Developers who gave the most report credits (total 0) + +Top changeset contributors by employer +enselic@gmail.com 6 (60.0%) +random.joe@example.com 2 (20.0%) +line.remover@bogus.bo 1 (10.0%) +punk.rocker@example.com 1 (10.0%) + +Top lines changed by employer +line.remover@bogus.bo 14 (34.1%) +enselic@gmail.com 13 (31.7%) +random.joe@example.com 13 (31.7%) +punk.rocker@example.com 1 (2.4%) + +Employers with the most signoffs (total 2) +enselic@gmail.com 2 (100.0%) diff --git a/tests/gitdm-tests.py b/tests/gitdm-tests.py new file mode 100755 index 0000000..a68003e --- /dev/null +++ b/tests/gitdm-tests.py @@ -0,0 +1,129 @@ +#!/usr/bin/python +# + +# +# This code is part of the LWN git data miner. +# +# Copyright 2009 Martin Nordholts +# +# This file may be distributed under the terms of the GNU General +# Public License, version 2. + +import unittest, subprocess, os + +class GitdmTests(unittest.TestCase): + + ## + # Setup test fixture. + # + def setUp(self): + self.srcdir = os.getcwd () + self.git_dir = os.path.join (self.srcdir, "tests/testrepo") + if not os.path.exists (self.git_dir): + self.fail ("'" + self.git_dir + "' didn't exist, you probably "+ + "didn't run the test with the source root as the working directory.") + + + ## + # Makes sure that the statistics collected for the test repository + # is the expected statistics. Note that the test must be run with + # the working directory as the source root and with git in the + # PATH. + # + def testResultOutputRegressionTest(self): + + # Build paths + actual_results_path = os.path.join (self.srcdir, "tests/actual-results.txt") + expected_results_path = os.path.join (self.srcdir, "tests/expected-results.txt") + + # Run actual test + self.runOutputFileRegressionTest (expected_results_path, + actual_results_path, + ["-o", actual_results_path]) + + + ## + # Does a regression test on the datelc (data line count) file + # + def testDateLineCountOutputRegressionTest(self): + + # Build paths + actual_datelc_path = os.path.join (self.srcdir, "datelc") + expected_datelc_path = os.path.join (self.srcdir, "tests/expected-datelc") + + # Run actual test + self.runOutputFileRegressionTest (expected_datelc_path, + actual_datelc_path, + ["-D"]) + + + ## + # Run a test, passing path to file with expected output, path to + # file which will countain the actual output, and arguments to + # pass to gitdm. We both make sure the file where the result will + # be put when gitdm is run does not exist beforehand, and we clean + # up after we are done. + # + def runOutputFileRegressionTest(self, expected_output_path, actual_output_path, arguments): + + # Make sure we can safely run the test + self.ensureFileDoesNotExist (actual_output_path) + + try: + # Collect statistics + self.runGitdm (arguments) + + # Make sure we got the result we expected + self.assertFilesEqual (expected_output_path, actual_output_path) + + finally: + # Remove any file we created, also if test fails + self.purgeFile (actual_output_path) + + + ## + # If passed file exists, delete it. + # + def purgeFile(self, filename): + if os.path.exists (filename): + os.remove (filename) + + + ## + # Make sure the file does not exist so we don't risk overwriting + # an important file. + # + def ensureFileDoesNotExist(self, filename): + if os.path.exists (filename): + self.fail ("The file '" + filename + "' exists, failing " + "test to avoid overwriting file.") + + + ## + # Run gitdm on the test repository with the passed arguments. + # + def runGitdm(self, arguments): + git_log_process = subprocess.Popen (["git", "--git-dir", self.git_dir, "log", "-p", "-M"], + stdout=subprocess.PIPE) + gitdm_process = subprocess.Popen (["./gitdm"] + arguments, + stdin=git_log_process.stdout) + gitdm_process.communicate () + + + ## + # Makes sure the files have the same content. + # + def assertFilesEqual(self, file1, file2): + f = open (file1, 'r') + file1_contents = f.read () + f.close () + f = open (file2, 'r') + file2_contents = f.read () + f.close () + self.assertEqual (file1_contents, file2_contents, + "The files '" + file1 + "' and '" + + file2 + "' were not equal!") + + +if __name__ == '__main__': + unittest.main () diff --git a/tests/testrepo/HEAD b/tests/testrepo/HEAD new file mode 100644 index 0000000..cb089cd --- /dev/null +++ b/tests/testrepo/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/tests/testrepo/config b/tests/testrepo/config new file mode 100644 index 0000000..96ecd44 --- /dev/null +++ b/tests/testrepo/config @@ -0,0 +1,6 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = true +[gc] + pruneexpire = now diff --git a/tests/testrepo/info/refs b/tests/testrepo/info/refs new file mode 100644 index 0000000..84de6b6 --- /dev/null +++ b/tests/testrepo/info/refs @@ -0,0 +1 @@ +2a3beb7042492ce6a0dc88ed59d04633b08b7bbc refs/heads/master diff --git a/tests/testrepo/objects/info/packs b/tests/testrepo/objects/info/packs new file mode 100644 index 0000000..8638101 --- /dev/null +++ b/tests/testrepo/objects/info/packs @@ -0,0 +1,2 @@ +P pack-f62fb949b32db1bccdc300fc13de20bca92b4c01.pack + diff --git a/tests/testrepo/objects/pack/pack-f62fb949b32db1bccdc300fc13de20bca92b4c01.idx b/tests/testrepo/objects/pack/pack-f62fb949b32db1bccdc300fc13de20bca92b4c01.idx new file mode 100644 index 0000000000000000000000000000000000000000..09c10995304705a114d2389eaf953001b4e4cd8c GIT binary patch literal 1912 zcwYNo;-AdGz`(?S0E}2L6O}MC5VPRGtT-?m6thDy2M)}Mgt>5FZUUHx2+T_&=EH*d z@n8Wmu^)VSC z#tbL;F2x>WH;&(_YR(pZ<7>f&lmD-2aXFl6l`PO27Hh5c+ZXp@ z*D{uquFW@(5<89;xH{%W6)q4z9 zXGnx~y+7Y0*T*BW`}U+cp;BDN_Pg9T1D_wheC*nJ;a{@68?E>~E&u+Q_t*I3Q^~i% zKZKmxerl}WG0Ab=gASS2n)$+Ve2=;(y(-+bcddt)mRm)nbLz2|Co*E|?(IG=^6i0P zn2%G+Lzbq_L}8t+3#1<(D3uXvjNWgy?8374F8NcE*PJJOkbK~4xG*WojXA)@4o<}cpMR8Ut`$T+Jd%H#Qkt&2D(y+3**eajs+ zjl$CX8frXp7iJb+Rl1{C9Hnvg{eT| z7R*^AdUQSeg4RO!^WrKGmMy65=~%(F?Si=AG$pxfe&ev4n64!p7^8ePj=B_)}_&5mwWU5n2rBbw{9)ir)XjC zwAg)B(8j21OZoL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d$vqZwFBa*w8L zCtuWuelDU5H|dXYB?(1Q8Z8?5R4o(1eS4QVlQ?BLK~)%i=8oRGvU@?+d79bIH>vk` zq1)&#wH%<|u~tu2Wo+MgfUJ?bpL!W=v`qQ5QSaJ6Kar?~wtGIu#OpJx7#pe3Urf@fYh;KH3$)rLYB0i@!GHtgVa0 z@szwiIz&Vf9?xyS=n9Su4N8kC)!(d$j)-CcFPJ_fY(NMJROH`xaYlPN^=^JSnfBUX znBK8;#lmF9lT)Ry=^jX5?4}|u>fM@_CwGXzeAN|ybkOupyRbP%Yn@fMk0*=|(`5&b z*bxdpJ_|c;wiR>l*DBx9edGY%QDI!8(e0$oro0qY|D!DSpsAoj1W(b^*U{0_bx=c{ z&_eYvQG=S5YQFf>g8n(X165~YqeH2h#QI1c3bSMZFn%OyrGux4Zof_daL3((Sd;ho zF{TSmLhE0J?O#*mllJJV<&d zzNM-FV*Fm5*|RGko|uTTldh2CR{wgGgRN)!e9t@4?r*FW@^a28(}r^>d+=EMg$+nk z2Yn0eVcVBi+)%d16N#i1T|+*RxRD@*XMx?m8_4ct85GOeD!Y=n8`jQuMpXOi8(Je%{VcZv-4 zZo9ks{lZIDtc$t=8#O1 zL2Z~=ajb#LPKK;^UnAX)y!E5Hrd4pVXf3K~=lkGbfaENc#s|h9#Zx?b3`-&tKU>tC z1;VsSn2pXL%w>K^R+YLCI2)?u<@bm4f`F!E1(%S6UJ!q%6>MyMh zc~QVV9E|ivV!N964Nwu&-5^$R)w`DJ=HY^o5jV$wdX-m4#0%!85m0GYu{O|xCH8+c^w+?TM73fy+0k-+?9CRx&$jV|~UY1!3&d58J4I!sZE5 zER*u%A@HC&Ogk|CG@jDXJ7U~l{6o^rl&S#$hP1T3UD`af U#@x14WK%-%ZhbOx$v7AEKjQ^lApigX literal 0 HcwPel00001 diff --git a/tests/testrepo/packed-refs b/tests/testrepo/packed-refs new file mode 100644 index 0000000..b62e86f --- /dev/null +++ b/tests/testrepo/packed-refs @@ -0,0 +1,2 @@ +# pack-refs with: peeled +2a3beb7042492ce6a0dc88ed59d04633b08b7bbc refs/heads/master -- 2.11.4.GIT