Patchwork [10,of,10] tests: test for the warning when repo.ui is passed to a new repo

login
register
mail settings
Submitter Simon Heimberg
Date March 22, 2013, 1:21 a.m.
Message ID <7bdc32431ae53519d6bf.1363915260@lapsi.heimberg.home>
Download mbox | patch
Permalink /patch/1156/
State Changes Requested, archived
Headers show

Comments

Simon Heimberg - March 22, 2013, 1:21 a.m.
# HG changeset patch
# User Simon Heimberg <simohe@besonet.ch>
# Date 1363912376 -3600
# Node ID 7bdc32431ae53519d6bf000e177de2821424cb56
# Parent  32ec0360c7ae215e72e9c8a0a810335c0ef66ccd
tests: test for the warning when repo.ui is passed to a new repo

Patch

diff -r 32ec0360c7ae -r 7bdc32431ae5 tests/test-ui-inheritance.py
--- /dev/null	Don Jan 01 00:00:00 1970 +0000
+++ b/tests/test-ui-inheritance.py	Fre Mär 22 01:32:56 2013 +0100
@@ -0,0 +1,92 @@ 
+import os
+from mercurial import ui, hg
+
+class testui(ui.ui):
+    def write_err(self, msg):
+        print "W:", msg,
+
+baseui = testui()
+
+r = hg.repository(baseui, "t", True)
+
+def test_repo(rui, ret=False):
+    # recurse for having more levels than showing
+    def z(n):
+        if n:
+            return z(n - 1)
+        else:
+            return hg.repository(rui, "t")
+    r = z(9)
+    if ret:
+        return r
+
+def test_peer(rui, ret=False):
+    # recurse for having more levels than showing
+    def z(n):
+        if n:
+            return z(n - 1)
+        else:
+            return hg.peer(rui, {}, "t")
+    r = z(9)
+    if ret:
+        return r
+
+
+def test_1_warn():
+    """
+test warning for developer
+
+correct, no warning
+    >>> test_peer(baseui)
+    >>> test_peer(r)
+    >>> test_repo(baseui)
+
+warning
+    >>> x = test_peer(r.ui, ret=True)  # doctest: +ELLIPSIS
+    W: PROGRAMMER WARNING: pass repo (not repo.ui) to hg.peer
+     (run pydoc mercurial.ui.checkglobal for more info)
+     Traceback (most recent call last):
+      ...
+      File ...
+      File ...
+      File ...
+      File ...
+      File ...
+      File ...
+      File ...
+      File ...
+        ...pass repo...
+    >>> x.local() and None
+    >>> test_repo(r.ui)  # doctest: +ELLIPSIS
+    W: PROGRAMMER WARNING: pass a baseui (not repo.ui) when creating a repo
+     ...
+      ...pass a baseui...
+    """
+
+def test_2_user():
+    """
+check that there is no output for users
+
+remove elements indicating a test run
+    >>> t = os.environ['TESTTMP']
+    >>> os.environ['TESTTMP'] = ''
+    >>> import sys
+    >>> ut = None
+    >>> if 'unittest' in sys.modules:
+    ...     ut = sys.modules.pop('unittest')
+
+do tests, no output for user
+    >>> test_peer(baseui) and None
+    >>> x = test_peer(r.ui, ret=True)
+    >>> x.local() and None
+    >>> test_repo(r.ui)
+
+reset environment
+    >>> os.environ['TESTTMP'] = t
+    >>> if ut: sys.modules['unittest'] = ut
+    """
+
+
+if __name__ == '__main__':
+    import doctest
+    doctest.testmod(optionflags=doctest.REPORT_NDIFF)