Permalink
Browse files

allows running specific tests from command line

  • Loading branch information...
rodrigomanhaes committed Jul 8, 2011
1 parent 1dae959 commit 2df34514e13aa50eb7e3cce3089bc2da74b51efd
Showing with 33 additions and 23 deletions.
  1. +7 −23 run_all_examples.py
  2. +26 −0 run_examples.py
View
@@ -1,31 +1,15 @@
#!/usr/bin/env python
-import doctest
-import unittest
import os
-import sys
import glob
+from run_examples import run
-
-def test_suite():
- flags = doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS
- if sys.version_info >= (3,):
- flags |= doctest.IGNORE_EXCEPTION_DETAIL
+def all_examples():
+ documentation = glob.glob('docs/*.rst') + ['README.rst']
doctests_path = os.path.join('should_dsl', 'doctests')
-
- suite = unittest.TestSuite()
-
- for doc in glob.glob('docs/*.rst') + ['README.rst']:
- suite.addTest(doctest.DocFileSuite(doc, optionflags=flags))
-
- for doctest_file in os.listdir(doctests_path):
- if doctest_file.endswith('.txt'):
- suite.addTest(doctest.DocFileSuite(os.path.join(doctests_path,
- doctest_file),
- optionflags=flags))
- return suite
+ doctests = map(lambda f: os.path.join(doctests_path, f),
+ filter(lambda f: f.endswith('.txt'), os.listdir(doctests_path)))
+ return documentation + doctests
if __name__ == '__main__':
- runner = unittest.TextTestRunner(verbosity=2)
- result = runner.run(test_suite())
- sys.exit(int(bool(result.failures or result.errors)))
+ run(all_examples())
View
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+import doctest
+import unittest
+import sys
+
+def test_suite(docs):
+ suite = unittest.TestSuite()
+ for doc in docs:
+ suite.addTest(doctest.DocFileSuite(doc, optionflags=flags()))
+ return suite
+
+def flags():
+ flags = doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS
+ if sys.version_info >= (3,):
+ flags |= doctest.IGNORE_EXCEPTION_DETAIL
+ return flags
+
+def run(docs):
+ suite = test_suite(docs)
+ runner = unittest.TextTestRunner(verbosity=2)
+ result = runner.run(suite)
+ sys.exit(int(bool(result.failures or result.errors)))
+
+if __name__ == '__main__':
+ run(sys.argv)
+

0 comments on commit 2df3451

Please sign in to comment.