summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Nordholts <martinn@src.gnome.org>2009-12-19 15:59:34 +0100
committerJonathan Corbet <corbet@lwn.net>2010-02-06 16:32:30 -0700
commit9abb7c32bbbebf228448619a3ecb8f78f6a6081f (patch)
tree1b999f700aedba87d1c247b27ee97a524947b13a
parent3b39893928a6260715abc483f39638b597990565 (diff)
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 <martinn@src.gnome.org>
-rw-r--r--tests/expected-datelc2
-rw-r--r--tests/expected-results.txt46
-rwxr-xr-xtests/gitdm-tests.py129
-rw-r--r--tests/testrepo/HEAD1
-rw-r--r--tests/testrepo/config6
-rw-r--r--tests/testrepo/info/refs1
-rw-r--r--tests/testrepo/objects/info/packs2
-rw-r--r--tests/testrepo/objects/pack/pack-f62fb949b32db1bccdc300fc13de20bca92b4c01.idxbin0 -> 1912 bytes
-rw-r--r--tests/testrepo/objects/pack/pack-f62fb949b32db1bccdc300fc13de20bca92b4c01.packbin0 -> 2883 bytes
-rw-r--r--tests/testrepo/packed-refs2
10 files changed, 189 insertions, 0 deletions
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 <martinn@src.gnome.org>
+#
+# 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 0000000..09c1099
--- /dev/null
+++ b/tests/testrepo/objects/pack/pack-f62fb949b32db1bccdc300fc13de20bca92b4c01.idx
Binary files differ
diff --git a/tests/testrepo/objects/pack/pack-f62fb949b32db1bccdc300fc13de20bca92b4c01.pack b/tests/testrepo/objects/pack/pack-f62fb949b32db1bccdc300fc13de20bca92b4c01.pack
new file mode 100644
index 0000000..14ab4db
--- /dev/null
+++ b/tests/testrepo/objects/pack/pack-f62fb949b32db1bccdc300fc13de20bca92b4c01.pack
Binary files differ
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