Anonymous avatar Anonymous committed 20545f6

Added Doctests support

Comments (0)

Files changed (1)

 
 # End of Constants
 
+def file_name_to_module(file_name):
+    """
+    >>> print(file_name_to_module("pyTDDmon.pyw"))
+    pyTDDmon
+    >>> print(file_name_to_module("pyTDDmon.py"))
+    pyTDDmon
+    """
+    return ".".join(file_name.split(".")[:-1])
+
 def build_run_script(files):
     header =    '''\
 import unittest
+import doctest
 
 suite = unittest.TestSuite()
 load_module_tests = unittest.defaultTestLoader.loadTestsFromModule
 '''
     middle = []
     for filename in files:
-        module = filename[:-3]
-        middle.append( 'import ' + module)
-        middle.append('suite.addTests(load_module_tests(' + module + '))\n')
+        module = file_name_to_module(filename)
+        middle.append('import ' + module)
+        middle.append('suite.addTests(load_module_tests(' + module + '))')
+        middle.append('try:')
+        middle.append('    suite.addTests(doctest.DocTestSuite(' + module + '))')
+        middle.append('except:pass')
+        middle.append('')
     footer = '''\
 if __name__ == '__main__':
     out = file(%r, "w")
     unittest.TextTestRunner(stream=out).run(suite)
 ''' % TEMP_OUT_FILE_NAME
 
-    return header + "\n".join(middle) + footer
+    content = header + "\n".join(middle) + footer
+    return content
 
 def calculate_checksum(filelist, fileinfo):
     val = 0
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.