Permalink
Browse files

add coverage to tests

  • Loading branch information...
1 parent f06b383 commit 2b8d859dbf2037d348745506049e471226c2ccbe @stefankoegl committed Nov 15, 2012
Showing with 42 additions and 3 deletions.
  1. +42 −3 tests.py
View
@@ -4,6 +4,7 @@
import doctest
import unittest
import jsonpatch
+import sys
class ApplyPatchTestCase(unittest.TestCase):
@@ -226,13 +227,51 @@ def test_add_nested(self):
}
self.assertEqual(expected, res)
-def suite():
+
+modules = ['jsonpatch']
+coverage_modules = []
+
+
+def get_suite():
suite = unittest.TestSuite()
suite.addTest(doctest.DocTestSuite(jsonpatch))
suite.addTest(unittest.makeSuite(ApplyPatchTestCase))
suite.addTest(unittest.makeSuite(EqualityTestCase))
suite.addTest(unittest.makeSuite(MakePatchTestCase))
return suite
-if __name__ == '__main__':
- unittest.main(defaultTest='suite')
+
+suite = get_suite()
+
+for module in modules:
+ m = __import__(module, fromlist=[module])
+ coverage_modules.append(m)
+ suite.addTest(doctest.DocTestSuite(m))
+
+runner = unittest.TextTestRunner(verbosity=1)
+
+try:
+ import coverage
+except ImportError:
+ coverage = None
+
+if coverage is not None:
+ coverage.erase()
+ coverage.start()
+
+result = runner.run(suite)
+
+if not result.wasSuccessful():
+ sys.exit(1)
+
+if coverage is not None:
+ coverage.stop()
+ coverage.report(coverage_modules)
+ coverage.erase()
+
+if coverage is None:
+ sys.stderr.write("""
+No coverage reporting done (Python module "coverage" is missing)
+Please install the python-coverage package to get coverage reporting.
+""")
+ sys.stderr.flush()

0 comments on commit 2b8d859

Please sign in to comment.