Rev 35: Merge Lukas's extra tests, update for the new code. in http://bazaar.launchpad.net/~bzr/bzr-stats/trunk

John Arbash Meinel john at arbash-meinel.com
Fri Jan 15 22:16:17 GMT 2010


At http://bazaar.launchpad.net/~bzr/bzr-stats/trunk

------------------------------------------------------------
revno: 35 [merge]
revision-id: john at arbash-meinel.com-20100115221553-iyks8nuykfk9j2jp
parent: john at arbash-meinel.com-20100115215250-hmrp4yeu2ty035nl
parent: lalinsky at gmail.com-20080722095908-81f05ft8zhj5rcpf
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: trunk
timestamp: Fri 2010-01-15 16:15:53 -0600
message:
  Merge Lukas's extra tests, update for the new code.
  Also, re-implement the case-insensitive comparisons.
added:
  test_stats.py                  test_stats.py-20080709084050-sx33b3au5f6q9zvm-1
modified:
  __init__.py                    __init__.py-20060629132721-mkbaty0vfk4y3v59-1
  test_classify.py               test_classify.py-20080628185419-ego83y2jujmkx52r-1
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2010-01-15 21:51:02 +0000
+++ b/__init__.py	2010-01-15 22:15:53 +0000
@@ -78,9 +78,10 @@
         new_combos.update(old_combos)
         for old_user, old_email in old_combos:
             if (old_user and old_user != user):
-                old_user_id = username_to_id[old_user]
+                low_old_user = old_user.lower()
+                old_user_id = username_to_id[low_old_user]
                 assert old_user_id in (old_id, new_id)
-                username_to_id[old_user] = new_id
+                username_to_id[low_old_user] = new_id
             if (old_email and old_email != email):
                 old_email_id = email_to_id[old_email]
                 assert old_email_id in (old_id, new_id)
@@ -94,14 +95,16 @@
             for user in usernames:
                 if not user:
                     continue # The mysterious ('', '') user
-                user_id = username_to_id.get(user)
+                # When mapping, use case-insensitive names
+                low_user = user.lower()
+                user_id = username_to_id.get(low_user)
                 if user_id is None:
                     id_counter += 1
                     user_id = id_counter
-                    username_to_id[user] = user_id
+                    username_to_id[low_user] = user_id
                     id_to_combos[user_id] = id_combos = set()
                 else:
-                    id_combos = id_combos[user_id]
+                    id_combos = id_to_combos[user_id]
                 id_combos.add((user, email))
             continue
 
@@ -116,13 +119,14 @@
             if not user:
                 # We don't match on empty usernames
                 continue
-            user_id = username_to_id.get(user)
+            low_user = user.lower()
+            user_id = username_to_id.get(low_user)
             if user_id is not None:
                 # This UserName was matched to an cur_id
                 if user_id != cur_id:
                     # And it is a different identity than the current email
                     collapse_ids(user_id, cur_id, id_combos)
-            username_to_id[user] = cur_id
+            username_to_id[low_user] = cur_id
     combo_to_best_combo = {}
     for cur_id, combos in id_to_combos.iteritems():
         best_combo = sorted(combos,
@@ -184,7 +188,7 @@
         pb.note('getting ancestry 2')
         ancestry = a_repo.get_ancestry(end_rev)[1:]
         ancestry = [rev for rev in ancestry if rev not in start_ancestry]
-        revs, canonical_committer = sort_by_committer(a_repo, ancestry)
+        revs, canonical_committer = get_revisions_and_committers(a_repo, ancestry)
     finally:
         a_repo.unlock()
         pb.finished()
@@ -429,7 +433,7 @@
     from bzrlib.tests import TestLoader
     suite = TestSuite()
     loader = TestLoader()
-    testmod_names = [ 'test_classify']
+    testmod_names = ['test_classify', 'test_stats']
     suite.addTest(loader.loadTestsFromModuleNames(['%s.%s' % (__name__, i) for i in testmod_names]))
     return suite
 

=== modified file 'test_classify.py'
--- a/test_classify.py	2008-08-04 19:49:51 +0000
+++ b/test_classify.py	2010-01-15 22:15:53 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2008 Jelmer Vernooij <jelmer at samba.org>
+# Copyright (C) 2008, 2010 Jelmer Vernooij <jelmer at samba.org>
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -20,6 +20,8 @@
 class TestClassify(TestCase):
     def test_classify_code(self):
         self.assertEquals("code", classify_filename("foo/bar.c"))
+        self.assertEquals("code", classify_filename("foo/bar.pl"))
+        self.assertEquals("code", classify_filename("foo/bar.pm"))
 
     def test_classify_documentation(self):
         self.assertEquals("documentation", classify_filename("bla.html"))
@@ -35,3 +37,6 @@
 
     def test_classify_doc_hardcoded(self):
         self.assertEquals("documentation", classify_filename("README"))
+
+    def test_classify_multiple_periods(self):
+        self.assertEquals("documentation", classify_filename("foo.bla.html"))

=== added file 'test_stats.py'
--- a/test_stats.py	1970-01-01 00:00:00 +0000
+++ b/test_stats.py	2010-01-15 22:15:53 +0000
@@ -0,0 +1,104 @@
+from bzrlib.tests import TestCase, TestCaseWithTransport
+from bzrlib.revision import Revision
+from bzrlib.plugins.stats import get_revisions_and_committers, collapse_by_person
+
+
+class TestGetRevisionsAndCommitters(TestCaseWithTransport):
+
+    def test_simple(self):
+        wt = self.make_branch_and_tree('.')
+        wt.commit(message='1', committer='Fero <fero at example.com>', rev_id='1')
+        wt.commit(message='2', committer='Fero <fero at example.com>', rev_id='2')
+        wt.commit(message='3', committer='Jano <jano at example.com>', rev_id='3')
+        wt.commit(message='4', committer='Jano <jano at example.com>',
+                  authors=['Vinco <vinco at example.com>'], rev_id='4')
+        wt.commit(message='5', committer='Ferko <fero at example.com>', rev_id='5')
+        revs, committers = get_revisions_and_committers(wt.branch.repository,
+                                                        ['1', '2', '3', '4', '5'])
+        fero = ('Fero', 'fero at example.com')
+        jano = ('Jano', 'jano at example.com')
+        vinco = ('Vinco', 'vinco at example.com')
+        ferok = ('Ferko', 'fero at example.com')
+        self.assertEqual({fero: fero, jano: jano, vinco:vinco, ferok: fero},
+                         committers)
+
+    def test_empty_email(self):
+        wt = self.make_branch_and_tree('.')
+        wt.commit(message='1', committer='Fero', rev_id='1')
+        wt.commit(message='2', committer='Fero', rev_id='2')
+        wt.commit(message='3', committer='Jano', rev_id='3')
+        revs, committers = get_revisions_and_committers(wt.branch.repository,
+                                                        ['1', '2', '3'])
+        self.assertEqual({('Fero', ''): ('Fero', ''),
+                          ('Jano', ''): ('Jano', ''),
+                         }, committers)
+
+    def test_different_case(self):
+        wt = self.make_branch_and_tree('.')
+        wt.commit(message='1', committer='Fero', rev_id='1')
+        wt.commit(message='2', committer='Fero', rev_id='2')
+        wt.commit(message='3', committer='FERO', rev_id='3')
+        revs, committers = get_revisions_and_committers(wt.branch.repository,
+                                                        ['1', '2', '3'])
+        self.assertEqual({('Fero', ''): ('Fero', ''),
+                          ('FERO', ''): ('Fero', ''),
+                         }, committers)
+
+
+class TestCollapseByPerson(TestCase):
+
+    def test_no_conflicts(self):
+        revisions = [
+            Revision('1', {}, committer='Foo <foo at example.com>'),
+            Revision('2', {}, committer='Bar <bar at example.com>'),
+            Revision('3', {}, committer='Bar <bar at example.com>'),
+        ]
+        foo = ('Foo', 'foo at example.com')
+        bar = ('Bar', 'bar at example.com')
+        committers = {foo: foo, bar: bar}
+        info = collapse_by_person(revisions, committers)
+        self.assertEquals(2, info[0][0])
+        self.assertEquals({'bar at example.com': 2}, info[0][2])
+        self.assertEquals({'Bar': 2}, info[0][3])
+
+    def test_different_email(self):
+        revisions = [
+            Revision('1', {}, committer='Foo <foo at example.com>'),
+            Revision('2', {}, committer='Foo <bar at example.com>'),
+            Revision('3', {}, committer='Foo <bar at example.com>'),
+        ]
+        foo = ('Foo', 'foo at example.com')
+        bar = ('Foo', 'bar at example.com')
+        committers = {foo: foo, bar: foo}
+        info = collapse_by_person(revisions, committers)
+        self.assertEquals(3, info[0][0])
+        self.assertEquals({'foo at example.com': 1, 'bar at example.com': 2}, info[0][2])
+        self.assertEquals({'Foo': 3}, info[0][3])
+
+    def test_different_name(self):
+        revisions = [
+            Revision('1', {}, committer='Foo <foo at example.com>'),
+            Revision('2', {}, committer='Bar <foo at example.com>'),
+            Revision('3', {}, committer='Bar <foo at example.com>'),
+        ]
+        foo = ('Foo', 'foo at example.com')
+        bar = ('Bar', 'foo at example.com')
+        committers = {foo: foo, bar: foo}
+        info = collapse_by_person(revisions, committers)
+        self.assertEquals(3, info[0][0])
+        self.assertEquals({'foo at example.com': 3}, info[0][2])
+        self.assertEquals({'Foo': 1, 'Bar': 2}, info[0][3])
+
+    def test_different_name_case(self):
+        revisions = [
+            Revision('1', {}, committer='Foo <foo at example.com>'),
+            Revision('2', {}, committer='Foo <foo at example.com>'),
+            Revision('3', {}, committer='FOO <bar at example.com>'),
+        ]
+        foo = ('Foo', 'foo at example.com')
+        FOO = ('FOO', 'bar at example.com')
+        committers = {foo: foo, FOO: foo}
+        info = collapse_by_person(revisions, committers)
+        self.assertEquals(3, info[0][0])
+        self.assertEquals({'foo at example.com': 2, 'bar at example.com': 1}, info[0][2])
+        self.assertEquals({'Foo': 2, 'FOO': 1}, info[0][3])



More information about the bazaar-commits mailing list