summaryrefslogtreecommitdiff
path: root/tests.py
diff options
context:
space:
mode:
authorStefan Kögl <stefan@skoegl.net>2012-11-15 11:26:22 +0100
committerStefan Kögl <stefan@skoegl.net>2012-11-15 11:29:08 +0100
commit2b8d859dbf2037d348745506049e471226c2ccbe (patch)
tree8fadfe529ce0a97a9bc2db971c645bef050b0c30 /tests.py
parentf06b38333e35e7b7bcbf497103f6772dc0458ad9 (diff)
downloadpython-json-patch-2b8d859dbf2037d348745506049e471226c2ccbe.tar.gz
add coverage to tests
Diffstat (limited to 'tests.py')
-rwxr-xr-xtests.py45
1 files changed, 42 insertions, 3 deletions
diff --git a/tests.py b/tests.py
index 3407136..bac293f 100755
--- a/tests.py
+++ b/tests.py
@@ -4,6 +4,7 @@
import doctest
import unittest
import jsonpatch
+import sys
class ApplyPatchTestCase(unittest.TestCase):
@@ -226,7 +227,12 @@ class MakePatchTestCase(unittest.TestCase):
}
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))
@@ -234,5 +240,38 @@ def suite():
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()