Patchwork [2,of,8] tests: make doctest test runner less verbose

login
register
mail settings
Submitter Mads Kiilerich
Date Nov. 17, 2013, 4:28 p.m.
Message ID <6b40daa5808bbd6676a0.1384705738@localhost.localdomain>
Download mbox | patch
Permalink /patch/3009/
State Accepted
Commit 10a7d2bcb81bd5a9cb33b8e75fa8d045b2acf316
Headers show

Comments

Mads Kiilerich - Nov. 17, 2013, 4:28 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1384705019 18000
#      Sun Nov 17 11:16:59 2013 -0500
# Branch stable
# Node ID 6b40daa5808bbd6676a09d4860abc2c8eead020a
# Parent  aae11f56cbf23d977d8db733db4a0ccc609d071c
tests: make doctest test runner less verbose
Augie Fackler - Nov. 17, 2013, 10:34 p.m.
On Sun, Nov 17, 2013 at 11:28:58AM -0500, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <madski@unity3d.com>
> # Date 1384705019 18000
> #      Sun Nov 17 11:16:59 2013 -0500
> # Branch stable
> # Node ID 6b40daa5808bbd6676a09d4860abc2c8eead020a
> # Parent  aae11f56cbf23d977d8db733db4a0ccc609d071c
> tests: make doctest test runner less verbose
>

queued these. Dithering on this particular one a bit, but it's test
code so meh.

>
> diff --git a/tests/test-doctest.py b/tests/test-doctest.py
> --- a/tests/test-doctest.py
> +++ b/tests/test-doctest.py
> @@ -1,49 +1,28 @@
>  # this is hack to make sure no escape characters are inserted into the output
> -import os
> +import os, sys
>  if 'TERM' in os.environ:
>      del os.environ['TERM']
>  import doctest
>
> -import mercurial.util
> -doctest.testmod(mercurial.util)
> -# Only run doctests for the current platform
> -doctest.testmod(mercurial.util.platform)
> +def testmod(name, optionflags=0, testtarget=None):
> +    __import__(name)
> +    mod = sys.modules[name]
> +    if testtarget is not None:
> +        mod = getattr(mod, testtarget)
> +    doctest.testmod(mod, optionflags=optionflags)
>
> -import mercurial.changelog
> -doctest.testmod(mercurial.changelog)
> -
> -import mercurial.dagparser
> -doctest.testmod(mercurial.dagparser, optionflags=doctest.NORMALIZE_WHITESPACE)
> -
> -import mercurial.match
> -doctest.testmod(mercurial.match)
> -
> -import mercurial.store
> -doctest.testmod(mercurial.store)
> -
> -import mercurial.ui
> -doctest.testmod(mercurial.ui)
> -
> -import mercurial.url
> -doctest.testmod(mercurial.url)
> -
> -import mercurial.dispatch
> -doctest.testmod(mercurial.dispatch)
> -
> -import mercurial.encoding
> -doctest.testmod(mercurial.encoding)
> -
> -import mercurial.hgweb.hgwebdir_mod
> -doctest.testmod(mercurial.hgweb.hgwebdir_mod)
> -
> -import hgext.convert.cvsps
> -doctest.testmod(hgext.convert.cvsps)
> -
> -import mercurial.revset
> -doctest.testmod(mercurial.revset)
> -
> -import mercurial.minirst
> -doctest.testmod(mercurial.minirst)
> -
> -import mercurial.templatefilters
> -doctest.testmod(mercurial.templatefilters)
> +testmod('mercurial.changelog')
> +testmod('mercurial.dagparser', optionflags=doctest.NORMALIZE_WHITESPACE)
> +testmod('mercurial.dispatch')
> +testmod('mercurial.encoding')
> +testmod('mercurial.hgweb.hgwebdir_mod')
> +testmod('mercurial.match')
> +testmod('mercurial.minirst')
> +testmod('mercurial.revset')
> +testmod('mercurial.store')
> +testmod('mercurial.templatefilters')
> +testmod('mercurial.ui')
> +testmod('mercurial.url')
> +testmod('mercurial.util')
> +testmod('mercurial.util', testtarget='platform')
> +testmod('hgext.convert.cvsps')
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/tests/test-doctest.py b/tests/test-doctest.py
--- a/tests/test-doctest.py
+++ b/tests/test-doctest.py
@@ -1,49 +1,28 @@ 
 # this is hack to make sure no escape characters are inserted into the output
-import os
+import os, sys
 if 'TERM' in os.environ:
     del os.environ['TERM']
 import doctest
 
-import mercurial.util
-doctest.testmod(mercurial.util)
-# Only run doctests for the current platform
-doctest.testmod(mercurial.util.platform)
+def testmod(name, optionflags=0, testtarget=None):
+    __import__(name)
+    mod = sys.modules[name]
+    if testtarget is not None:
+        mod = getattr(mod, testtarget)
+    doctest.testmod(mod, optionflags=optionflags)
 
-import mercurial.changelog
-doctest.testmod(mercurial.changelog)
-
-import mercurial.dagparser
-doctest.testmod(mercurial.dagparser, optionflags=doctest.NORMALIZE_WHITESPACE)
-
-import mercurial.match
-doctest.testmod(mercurial.match)
-
-import mercurial.store
-doctest.testmod(mercurial.store)
-
-import mercurial.ui
-doctest.testmod(mercurial.ui)
-
-import mercurial.url
-doctest.testmod(mercurial.url)
-
-import mercurial.dispatch
-doctest.testmod(mercurial.dispatch)
-
-import mercurial.encoding
-doctest.testmod(mercurial.encoding)
-
-import mercurial.hgweb.hgwebdir_mod
-doctest.testmod(mercurial.hgweb.hgwebdir_mod)
-
-import hgext.convert.cvsps
-doctest.testmod(hgext.convert.cvsps)
-
-import mercurial.revset
-doctest.testmod(mercurial.revset)
-
-import mercurial.minirst
-doctest.testmod(mercurial.minirst)
-
-import mercurial.templatefilters
-doctest.testmod(mercurial.templatefilters)
+testmod('mercurial.changelog')
+testmod('mercurial.dagparser', optionflags=doctest.NORMALIZE_WHITESPACE)
+testmod('mercurial.dispatch')
+testmod('mercurial.encoding')
+testmod('mercurial.hgweb.hgwebdir_mod')
+testmod('mercurial.match')
+testmod('mercurial.minirst')
+testmod('mercurial.revset')
+testmod('mercurial.store')
+testmod('mercurial.templatefilters')
+testmod('mercurial.ui')
+testmod('mercurial.url')
+testmod('mercurial.util')
+testmod('mercurial.util', testtarget='platform')
+testmod('hgext.convert.cvsps')