changeset 168:4f26fa049452

authormap: Add tests, fix in stupid mode.
author Augie Fackler <durin42@gmail.com>
date Tue, 30 Dec 2008 20:14:03 -0600
parents 3cd6a7354207
children f1919e1c35bf
files fetch_command.py hg_delta_editor.py tests/run.py tests/test_fetch_mappings.py
diffstat 4 files changed, 68 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/fetch_command.py
+++ b/fetch_command.py
@@ -514,8 +514,7 @@ def stupid_svn_server_pull_rev(ui, svn, 
                                          r.message or '...',
                                          files_touched,
                                          filectxfn,
-                                         '%s%s' % (r.author,
-                                                   hg_editor.author_host),
+                                         hg_editor.authorforsvnauthor(r.author),
                                          date,
                                          extra)
             ha = hg_editor.repo.commitctx(current_ctx)
@@ -553,8 +552,7 @@ def stupid_svn_server_pull_rev(ui, svn, 
                                      r.message or '...',
                                      files_touched,
                                      filectxfn,
-                                     '%s%s' % (r.author,
-                                               hg_editor.author_host),
+                                     hg_editor.authorforsvnauthor(r.author),
                                      date,
                                      {'branch': 'closed-branches'})
         ha = hg_editor.repo.commitctx(current_ctx)
--- a/hg_delta_editor.py
+++ b/hg_delta_editor.py
@@ -482,9 +482,9 @@ class HgChangeReceiver(delta.Editor):
         self.clear_current_info()
 
     def authorforsvnauthor(self, author):
-	    if(author in self.authors):
-	        return self.authors[author]
-	    return '%s%s' %(author, self.author_host)
+        if(author in self.authors):
+            return self.authors[author]
+        return '%s%s' %(author, self.author_host)
 
     def readauthors(self, authorfile):
         self.ui.status(
@@ -492,7 +492,7 @@ class HgChangeReceiver(delta.Editor):
             % authorfile)
         f = open(authorfile, 'r')
         for line in f:
-            if line.strip() == '':
+            if not line.strip():
                 continue
             try:
                 srcauth, dstauth = line.split('=', 1)
@@ -511,7 +511,7 @@ class HgChangeReceiver(delta.Editor):
                     ('Ignoring bad line in author map file %s: %s\n')
                     % (authorfile, line.rstrip()))
         f.close()
-        
+
     def writeauthors(self):
         f = open(self.authors_file, 'w+')
         self.ui.status(
@@ -563,7 +563,7 @@ class HgChangeReceiver(delta.Editor):
     @property
     def authors_file(self):
         return self.meta_file_named('authors')
-        
+
     @stash_exception_on_self
     def delete_entry(self, path, revision_bogus, parent_baton, pool=None):
         br_path, branch = self._path_and_branch_for_path(path)
--- a/tests/run.py
+++ b/tests/run.py
@@ -9,6 +9,7 @@ import test_fetch_branches
 import test_fetch_command
 import test_fetch_command_regexes
 import test_fetch_exec
+import test_fetch_mappings
 import test_fetch_renames
 import test_fetch_symlinks
 import test_fetch_truncated
@@ -26,6 +27,7 @@ def suite():
                                test_fetch_command.suite(),
                                test_fetch_command_regexes.suite(),
                                test_fetch_exec.suite(),
+                               test_fetch_mappings.suite(),
                                test_fetch_renames.suite(),
                                test_fetch_symlinks.suite(),
                                test_fetch_truncated.suite(),
new file mode 100644
--- /dev/null
+++ b/tests/test_fetch_mappings.py
@@ -0,0 +1,58 @@
+"""Tests for author maps and file maps.
+"""
+import os
+import unittest
+
+from mercurial import ui
+
+import test_util
+import fetch_command
+
+class MapTests(test_util.TestBase):
+    @property
+    def authors(self):
+        return os.path.join(self.tmpdir, 'authormap')
+
+    @property
+    def filemap(self):
+        return os.path.join(self.tmpdir, 'filemap')
+
+    def test_author_map(self, stupid=False):
+        test_util.load_svndump_fixture(self.repo_path, 'replace_trunk_with_branch.svndump')
+        authormap = open(self.authors, 'w')
+        authormap.write("Augie=Augie Fackler <durin42@gmail.com>\n")
+        authormap.close()
+        fetch_command.fetch_revisions(ui.ui(),
+                                      svn_url=test_util.fileurl(self.repo_path),
+                                      hg_repo_path=self.wc_path,
+                                      stupid=stupid,
+                                      authors=self.authors)
+        self.assertEqual(self.repo[0].user(),
+                         'Augie Fackler <durin42@gmail.com>')
+        self.assertEqual(self.repo['tip'].user(),
+                        'evil@5b65bade-98f3-4993-a01f-b7a6710da339')
+
+    def test_author_map_stupid(self):
+        self.test_author_map(True)
+
+    def test_author_map_closing_author(self, stupid=False):
+        test_util.load_svndump_fixture(self.repo_path, 'replace_trunk_with_branch.svndump')
+        authormap = open(self.authors, 'w')
+        authormap.write("evil=Testy <test@test>")
+        authormap.close()
+        fetch_command.fetch_revisions(ui.ui(),
+                                      svn_url=test_util.fileurl(self.repo_path),
+                                      hg_repo_path=self.wc_path,
+                                      stupid=stupid,
+                                      authors=self.authors)
+        self.assertEqual(self.repo[0].user(),
+                         'Augie@5b65bade-98f3-4993-a01f-b7a6710da339')
+        self.assertEqual(self.repo['tip'].user(),
+                        'Testy <test@test>')
+
+    def test_author_map_closing_author_stupid(self):
+        self.test_author_map_closing_author(True)
+
+
+def suite():
+    return unittest.TestLoader().loadTestsFromTestCase(MapTests)