[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [bridgedb/master] Add test_Tests.generateTrialAdaptedDoctestsSuite().



commit f405105fe5a60fac55f388d554a4f6ea8dea8a42
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date:   Fri Dec 20 02:41:53 2013 +0000

    Add test_Tests.generateTrialAdaptedDoctestsSuite().
    
    This function discovers doctests within the directory that BridgeDB was
    installed within, and then it builds a `twisted.trial.unittest.TestSuite` from
    all discovered doctests.
---
 lib/bridgedb/test/test_Tests.py |   31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/lib/bridgedb/test/test_Tests.py b/lib/bridgedb/test/test_Tests.py
index f261168..b898cc4 100644
--- a/lib/bridgedb/test/test_Tests.py
+++ b/lib/bridgedb/test/test_Tests.py
@@ -16,7 +16,10 @@ be compatible with the newer :mod:`twisted.trial` unittests in this directory.
 from __future__ import print_function
 from __future__ import unicode_literals
 
+import doctest
+import glob
 import logging
+import os
 import warnings
 
 from twisted.trial import unittest
@@ -27,6 +30,34 @@ logging.warnings.filterwarnings('ignore', module="Tests")
 pyunit = __import__('unittest')
 
 
+def generateTrialAdaptedDoctestsSuite():
+    """Dynamically generates a :class:`unittest.TestSuite` all containing
+    discovered doctests within the installed ``bridgedb`` package.
+    """
+    bridgedb     = __import__('bridgedb')
+    fakedGlobals = globals().update({'bridgedb': bridgedb})
+    modulePath   = bridgedb.__path__[0]
+
+    #: The package directories to search for source code with doctests.
+    packagePaths = [modulePath,
+                    os.path.join(modulePath, 'parse'),
+                    os.path.join(modulePath, 'test')]
+    #: The source code files which will be searched for doctests.
+    files = []
+    #: The cls.testSuites which the test methods will be generated from.
+    testSuites = []
+
+    packages = [os.path.join(pkg, '*.py') for pkg in packagePaths]
+    [files.extend(glob.glob(pkg)) for pkg in packages]
+
+    for filename in files:
+        testSuites.append(
+            doctest.DocFileSuite(filename,
+                                 module_relative=False,
+                                 globs=fakedGlobals))
+    return testSuites
+
+
 class OldUnittests(unittest.TestCase):
     """A wrapper around :mod:`bridgedb.Tests` to produce :mod:`~twisted.trial`
     compatible output.



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits