changeset 576:d96aa92d9ad9

tests: silence test suite by using quiet UIs everywhere
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Fri, 26 Feb 2010 14:50:22 +0100
parents c278a225b750
children 930bb6df19a0
files hgsubversion/utility_commands.py tests/test_externals.py tests/test_fetch_branches.py tests/test_fetch_mappings.py tests/test_fetch_truncated.py tests/test_push_command.py tests/test_util.py tests/test_utility_commands.py
diffstat 8 files changed, 54 insertions(+), 83 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/utility_commands.py
+++ b/hgsubversion/utility_commands.py
@@ -77,7 +77,7 @@ def info(ui, repo, **opts):
     author = meta.authors.reverselookup(parent.user())
     # cleverly figure out repo root w/o actually contacting the server
     reporoot = url[:len(url)-len(subdir)]
-    ui.status('''URL: %(url)s
+    ui.write('''URL: %(url)s
 Repository Root: %(reporoot)s
 Repository UUID: %(uuid)s
 Revision: %(revision)s
@@ -111,7 +111,7 @@ def listauthors(ui, args, authors=None, 
         authorfile.write('%s=\n' % '=\n'.join(sorted(author_set)))
         authorfile.close()
     else:
-        ui.status('%s\n' % '\n'.join(sorted(author_set)))
+        ui.write('%s\n' % '\n'.join(sorted(author_set)))
 
 
 table = {
--- a/tests/test_externals.py
+++ b/tests/test_externals.py
@@ -113,7 +113,7 @@ class TestFetchExternals(test_util.TestB
                 self.assertTrue(not os.path.isdir(p),
                                 'unexpected: %s@%r' % (d, rev))
 
-        ui = test_util.ui.ui()
+        ui = self.ui()
         repo = self._load_fixture_and_fetch('externals.svndump', stupid=0)
         commands.update(ui, repo)
         checkdeps(['deps/project1'], [], repo, 0)
--- a/tests/test_fetch_branches.py
+++ b/tests/test_fetch_branches.py
@@ -2,7 +2,6 @@ import unittest
 
 from mercurial import hg
 from mercurial import node
-from mercurial import ui
 from mercurial import util as hgutil
 
 import test_util
@@ -18,8 +17,8 @@ class TestFetchBranches(test_util.TestBa
     def _load_fixture_and_fetch_with_anchor(self, fixture_name, anchor):
         test_util.load_svndump_fixture(self.repo_path, fixture_name)
         source = '%s#%s' % (test_util.fileurl(self.repo_path), anchor)
-        repo = hg.clone(ui.ui(), source=source, dest=self.wc_path)
-        return hg.repository(ui.ui(), self.wc_path)
+        repo = hg.clone(self.ui(), source=source, dest=self.wc_path)
+        return hg.repository(self.ui(), self.wc_path)
 
     def openbranches(self, repo):
         hctxs = [repo[hn] for hn in repo.heads()]
--- a/tests/test_fetch_mappings.py
+++ b/tests/test_fetch_mappings.py
@@ -4,7 +4,6 @@ import os
 import unittest
 
 from mercurial import commands
-from mercurial import ui
 from mercurial import node
 
 import test_util
@@ -30,10 +29,9 @@ class MapTests(test_util.TestBase):
         authormap.write('Augie=Augie Fackler <durin42@gmail.com> # stuffy\n')
         authormap.write("Augie Fackler <durin42@gmail.com>\n")
         authormap.close()
-        _ui = ui.ui()
-        _ui.setconfig('hgsubversion', 'stupid', str(stupid))
-        _ui.setconfig('hgsubversion', 'authormap', self.authors)
-        commands.clone(_ui, test_util.fileurl(self.repo_path),
+        ui = self.ui(stupid)
+        ui.setconfig('hgsubversion', 'authormap', self.authors)
+        commands.clone(ui, test_util.fileurl(self.repo_path),
                        self.wc_path, authors=self.authors)
         self.assertEqual(self.repo[0].user(),
                          'Augie Fackler <durin42@gmail.com>')
@@ -48,10 +46,9 @@ class MapTests(test_util.TestBase):
         authormap = open(self.authors, 'w')
         authormap.write("evil=Testy <test@test>")
         authormap.close()
-        _ui = ui.ui()
-        _ui.setconfig('hgsubversion', 'stupid', str(stupid))
-        _ui.setconfig('hgsubversion', 'authormap', self.authors)
-        commands.clone(_ui, test_util.fileurl(self.repo_path),
+        ui = self.ui(stupid)
+        ui.setconfig('hgsubversion', 'authormap', self.authors)
+        commands.clone(ui, test_util.fileurl(self.repo_path),
                        self.wc_path, authors=self.authors)
         self.assertEqual(self.repo[0].user(),
                          'Augie@5b65bade-98f3-4993-a01f-b7a6710da339')
@@ -67,7 +64,7 @@ class MapTests(test_util.TestBase):
         new = open(self.authors, 'w')
         new.write(open(orig).read())
         new.close()
-        test = maps.AuthorMap(ui.ui(), self.authors)
+        test = maps.AuthorMap(self.ui(), self.authors)
         fromself = set(test)
         test.load(orig)
         all = set(test)
@@ -78,10 +75,9 @@ class MapTests(test_util.TestBase):
         filemap = open(self.filemap, 'w')
         filemap.write("include alpha\n")
         filemap.close()
-        _ui = ui.ui()
-        _ui.setconfig('hgsubversion', 'stupid', str(stupid))
-        _ui.setconfig('hgsubversion', 'filemap', self.filemap)
-        commands.clone(_ui, test_util.fileurl(self.repo_path),
+        ui = self.ui(stupid)
+        ui.setconfig('hgsubversion', 'filemap', self.filemap)
+        commands.clone(ui, test_util.fileurl(self.repo_path),
                        self.wc_path, filemap=self.filemap)
         self.assertEqual(node.hex(self.repo[0].node()), '88e2c7492d83e4bf30fbb2dcbf6aa24d60ac688d')
         self.assertEqual(node.hex(self.repo['default'].node()), 'e524296152246b3837fe9503c83b727075835155')
@@ -94,10 +90,9 @@ class MapTests(test_util.TestBase):
         filemap = open(self.filemap, 'w')
         filemap.write("exclude alpha\n")
         filemap.close()
-        _ui = ui.ui()
-        _ui.setconfig('hgsubversion', 'stupid', str(stupid))
-        _ui.setconfig('hgsubversion', 'filemap', self.filemap)
-        commands.clone(_ui, test_util.fileurl(self.repo_path),
+        ui = self.ui(stupid)
+        ui.setconfig('hgsubversion', 'filemap', self.filemap)
+        commands.clone(ui, test_util.fileurl(self.repo_path),
                        self.wc_path, filemap=self.filemap)
         self.assertEqual(node.hex(self.repo[0].node()), '2c48f3525926ab6c8b8424bcf5eb34b149b61841')
         self.assertEqual(node.hex(self.repo['default'].node()), 'b37a3c0297b71f989064d9b545b5a478bbed7cc1')
@@ -111,10 +106,9 @@ class MapTests(test_util.TestBase):
         branchmap.write("badname = good-name # stuffy\n")
         branchmap.write("feature = default\n")
         branchmap.close()
-        _ui = ui.ui()
-        _ui.setconfig('hgsubversion', 'stupid', str(stupid))
-        _ui.setconfig('hgsubversion', 'branchmap', self.branchmap)
-        commands.clone(_ui, test_util.fileurl(self.repo_path),
+        ui = self.ui(stupid)
+        ui.setconfig('hgsubversion', 'branchmap', self.branchmap)
+        commands.clone(ui, test_util.fileurl(self.repo_path),
                        self.wc_path, branchmap=self.branchmap)
         branches = set(self.repo[i].branch() for i in self.repo)
         self.assert_('badname' not in branches)
--- a/tests/test_fetch_truncated.py
+++ b/tests/test_fetch_truncated.py
@@ -2,7 +2,6 @@ import unittest
 
 from mercurial import commands
 from mercurial import hg
-from mercurial import ui
 
 import test_util
 
@@ -11,10 +10,8 @@ class TestFetchTruncatedHistory(test_uti
         # Test repository does not follow the usual layout
         test_util.load_svndump_fixture(self.repo_path, 'truncatedhistory.svndump')
         svn_url = test_util.fileurl(self.repo_path + '/project2')
-        _ui = ui.ui()
-        _ui.setconfig('hgsubversion', 'stupid', str(stupid))
-        commands.clone(_ui, svn_url, self.wc_path, noupdate=True)
-        repo = hg.repository(_ui, self.wc_path)
+        commands.clone(self.ui(stupid), svn_url, self.wc_path, noupdate=True)
+        repo = hg.repository(self.ui(stupid), self.wc_path)
 
         # We are converting /project2/trunk coming from:
         #
--- a/tests/test_push_command.py
+++ b/tests/test_push_command.py
@@ -11,7 +11,6 @@ from mercurial import context
 from mercurial import commands
 from mercurial import hg
 from mercurial import node
-from mercurial import ui
 from mercurial import revlog
 from mercurial import util as hgutil
 
@@ -94,7 +93,7 @@ class PushTests(test_util.TestBase):
             time.sleep(2)
             import shutil
             shutil.rmtree(self.wc_path)
-            commands.clone(ui.ui(), 'svn://%s:%d/' % (self.host, self.port),
+            commands.clone(self.ui(), 'svn://%s:%d/' % (self.host, self.port),
                            self.wc_path, noupdate=True)
 
             repo = self.repo
--- a/tests/test_util.py
+++ b/tests/test_util.py
@@ -97,6 +97,14 @@ def fileurl(path):
     url = 'file://%s%s' % (drive, path)
     return url
 
+def testui(stupid=False, layout='auto'):
+    u = ui.ui()
+    bools = {True: 'true', False: 'false'}
+    u.setconfig('ui', 'quiet', bools[True])
+    u.setconfig('hgsubversion', 'stupid', bools[stupid])
+    u.setconfig('hgsubversion', 'layout', layout)
+    return u
+
 def load_svndump_fixture(path, fixture_name):
     '''Loads an svnadmin dump into a fresh repo at path, which should not
     already exist.
@@ -114,17 +122,9 @@ def load_fixture_and_fetch(fixture_name,
     load_svndump_fixture(repo_path, fixture_name)
     if subdir:
         repo_path += '/' + subdir
-
-    confvars = locals()
-    def conf():
-        _ui = ui.ui()
-        for var in ('stupid', 'layout'):
-            _ui.setconfig('hgsubversion', var, str(confvars[var]))
-        return _ui
-    _ui = conf()
+    _ui = testui(stupid=stupid, layout=layout)
     commands.clone(_ui, fileurl(repo_path), wc_path, noupdate=noupdate)
-    _ui = conf()
-    return hg.repository(_ui, wc_path)
+    return hg.repository(testui(), wc_path)
 
 def rmtree(path):
     # Read-only files cannot be removed under Windows
@@ -192,6 +192,9 @@ class TestBase(unittest.TestCase):
                 fromfile='expected', tofile='got'))
             raise
 
+    def ui(self, stupid=False, layout='auto'):
+        return testui(stupid, layout)
+
     def _load_fixture_and_fetch(self, fixture_name, subdir=None, stupid=False, layout='auto'):
         if layout == 'single':
             if subdir is None:
@@ -205,7 +208,7 @@ class TestBase(unittest.TestCase):
     # define this as a property so that it reloads anytime we need it
     @property
     def repo(self):
-        return hg.repository(ui.ui(), self.wc_path)
+        return hg.repository(testui(), self.wc_path)
 
     def pushrevisions(self, stupid=False, expected_extra_back=0):
         before = len(self.repo)
--- a/tests/test_utility_commands.py
+++ b/tests/test_utility_commands.py
@@ -2,7 +2,6 @@ import os
 import unittest
 
 from hgext import rebase
-from mercurial import ui
 from mercurial import hg
 from mercurial import revlog
 from mercurial import context
@@ -32,7 +31,7 @@ class UtilityTests(test_util.TestBase):
     def test_info_output(self):
         self._load_fixture_and_fetch('two_heads.svndump')
         hg.update(self.repo, 'the_branch')
-        u = ui.ui()
+        u = self.ui()
         u.pushbuffer()
         utility_commands.info(u, self.repo)
         actual = u.popbuffer()
@@ -69,7 +68,7 @@ class UtilityTests(test_util.TestBase):
     def test_info_single(self):
         self._load_fixture_and_fetch('two_heads.svndump', subdir='trunk')
         hg.update(self.repo, 'tip')
-        u = ui.ui()
+        u = self.ui()
         u.pushbuffer()
         utility_commands.info(u, self.repo)
         actual = u.popbuffer()
@@ -83,7 +82,7 @@ class UtilityTests(test_util.TestBase):
 
     def test_parent_output(self):
         self._load_fixture_and_fetch('two_heads.svndump')
-        u = ui.ui()
+        u = self.ui()
         u.pushbuffer()
         parents = (self.repo['the_branch'].node(), revlog.nullid, )
         def filectxfn(repo, memctx, path):
@@ -104,21 +103,16 @@ class UtilityTests(test_util.TestBase):
         hg.update(self.repo, new)
         wrappers.parents(lambda x, y: None, u, self.repo, svn=True)
         actual = u.popbuffer()
-        self.assertEqual(actual,
-                         'changeset:   3:4e256962fc5d\n'
-                         'branch:      the_branch\n'
-                         'user:        durin@df2126f7-00ab-4d49-b42c-7e981dde0bcf\n'
-                         'date:        Wed Oct 08 01:39:05 2008 +0000\n'
-                         'summary:     add delta on the branch\n\n')
+        self.assertEqual(actual, '3:4e256962fc5d\n')
 
         hg.update(self.repo, 'default')
+
         # Make sure styles work
         u.pushbuffer()
         wrappers.parents(lambda x, y: None, u, self.repo, svn=True, style='compact')
         actual = u.popbuffer()
-        self.assertEqual(actual,
-                         '4:1   1083037b18d8   2008-10-08 01:39 +0000   durin\n'
-                         '  Add gamma on trunk.\n\n')
+        self.assertEqual(actual, '4:1083037b18d8\n')
+
         # custom templates too
         u.pushbuffer()
         wrappers.parents(lambda x, y: None, u, self.repo, svn=True, template='{node}\n')
@@ -128,16 +122,11 @@ class UtilityTests(test_util.TestBase):
         u.pushbuffer()
         wrappers.parents(lambda x, y: None, u, self.repo, svn=True)
         actual = u.popbuffer()
-        self.assertEqual(actual,
-                         'changeset:   4:1083037b18d8\n'
-                         'parent:      1:c95251e0dd04\n'
-                         'user:        durin@df2126f7-00ab-4d49-b42c-7e981dde0bcf\n'
-                         'date:        Wed Oct 08 01:39:29 2008 +0000\n'
-                         'summary:     Add gamma on trunk.\n\n')
+        self.assertEqual(actual, '4:1083037b18d8\n')
 
     def test_outgoing_output(self):
         self._load_fixture_and_fetch('two_heads.svndump')
-        u = ui.ui()
+        u = self.ui()
         parents = (self.repo['the_branch'].node(), revlog.nullid, )
         def filectxfn(repo, memctx, path):
             return context.memfilectx(path=path,
@@ -158,23 +147,13 @@ class UtilityTests(test_util.TestBase):
         u.pushbuffer()
         commands.outgoing(u, self.repo, self.repourl)
         actual = u.popbuffer()
-        u.write(actual)
         self.assertTrue(node.hex(self.repo['localbranch'].node())[:8] in actual)
-        actual = actual.splitlines()
-        self.assertEqual(actual[0], 'comparing with ' + self.repourl)
-        self.assertEqual(actual[1], 'changeset:   5:6de15430fa20')
-        self.assertEqual(actual[2], 'branch:      localbranch')
-        self.assertEqual(actual[3], 'tag:         tip')
-        self.assertEqual(actual[4], 'parent:      3:4e256962fc5d')
-        self.assertEqual(actual[5], 'user:        testy')
-        self.assertEqual(actual[6], 'date:        Sun Dec 21 16:32:00 2008 -0500')
-        self.assertEqual(actual[7], 'summary:     automated test')
+        self.assertEqual(actual.strip(), '5:6de15430fa20')
         hg.update(self.repo, 'default')
         u.pushbuffer()
         commands.outgoing(u, self.repo, self.repourl)
         actual = u.popbuffer()
-        u.write(actual)
-        self.assertEqual(actual.splitlines()[1], 'no changes found')
+        self.assertEqual(actual, '')
 
     def test_rebase(self):
         self._load_fixture_and_fetch('two_revs.svndump')
@@ -197,7 +176,7 @@ class UtilityTests(test_util.TestBase):
         self.assertEqual(self.repo['tip'].branch(), 'localbranch')
         beforerebasehash = self.repo['tip'].node()
         hg.update(self.repo, 'tip')
-        wrappers.rebase(rebase.rebase, ui.ui(), self.repo, svn=True)
+        wrappers.rebase(rebase.rebase, self.ui(), self.repo, svn=True)
         self.assertEqual(self.repo['tip'].branch(), 'localbranch')
         self.assertEqual(self.repo['tip'].parents()[0].parents()[0], self.repo[0])
         self.assertNotEqual(beforerebasehash, self.repo['tip'].node())
@@ -206,7 +185,7 @@ class UtilityTests(test_util.TestBase):
         """ Test generation of .hgignore file. """
         test_util.load_fixture_and_fetch('ignores.svndump', self.repo_path,
                                          self.wc_path, noupdate=False)
-        u = ui.ui()
+        u = self.ui()
         u.pushbuffer()
         utility_commands.genignore(u, self.repo, self.wc_path)
         self.assertEqual(open(os.path.join(self.wc_path, '.hgignore')).read(),
@@ -215,7 +194,7 @@ class UtilityTests(test_util.TestBase):
     def test_genignore_single(self):
         self._load_fixture_and_fetch('ignores.svndump', subdir='trunk')
         hg.update(self.repo, 'tip')
-        u = ui.ui()
+        u = self.ui()
         u.pushbuffer()
         utility_commands.genignore(u, self.repo, self.wc_path)
         self.assertStringEqual(open(os.path.join(self.wc_path, '.hgignore')).read(),
@@ -224,7 +203,7 @@ class UtilityTests(test_util.TestBase):
     def test_list_authors(self):
         test_util.load_svndump_fixture(self.repo_path,
                                        'replace_trunk_with_branch.svndump')
-        u = ui.ui()
+        u = self.ui()
         u.pushbuffer()
         utility_commands.listauthors(u,
                                      args=[test_util.fileurl(self.repo_path)],
@@ -237,7 +216,7 @@ class UtilityTests(test_util.TestBase):
         test_util.load_svndump_fixture(self.repo_path,
                                        'replace_trunk_with_branch.svndump')
         author_path = os.path.join(self.repo_path, 'authors')
-        utility_commands.listauthors(ui.ui(),
+        utility_commands.listauthors(self.ui(),
                                      args=[test_util.fileurl(self.repo_path)],
                                      authors=author_path)
         self.assertEqual(open(author_path).read(), 'Augie=\nevil=\n')