Skip to content

Commit 04a864f

Browse files
committed
Clean up test runner
Test code doesn't need to manually construct a TestSuite and a TextTestRunner, the unittest module has a discovery function that does all this for you. Delete all of the manual logic from tests.py, replace it with the two lines to bring in the doctest unit tests, and update the makefile to run the unittest discovery.
1 parent a95c26f commit 04a864f

File tree

2 files changed

+5
-21
lines changed

2 files changed

+5
-21
lines changed

makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ help:
1010
@echo
1111

1212
test:
13-
python tests.py
13+
python -munittest
1414

1515
coverage:
1616
coverage run --source=jsonpointer tests.py

tests.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import unittest
88
import sys
99
import copy
10+
import jsonpointer
1011
from jsonpointer import resolve_pointer, EndOfList, JsonPointerException, \
1112
JsonPointer, set_pointer
1213

@@ -410,23 +411,6 @@ def test_mock_dict_raises_key_error(self):
410411
self.assertRaises(JsonPointerException, resolve_pointer, doc, '/root/1/2/3/4')
411412

412413

413-
414-
suite = unittest.TestSuite()
415-
suite.addTest(unittest.makeSuite(SpecificationTests))
416-
suite.addTest(unittest.makeSuite(ComparisonTests))
417-
suite.addTest(unittest.makeSuite(WrongInputTests))
418-
suite.addTest(unittest.makeSuite(ToLastTests))
419-
suite.addTest(unittest.makeSuite(SetTests))
420-
suite.addTest(unittest.makeSuite(AltTypesTests))
421-
422-
modules = ['jsonpointer']
423-
424-
for module in modules:
425-
m = __import__(module, fromlist=[module])
426-
suite.addTest(doctest.DocTestSuite(m))
427-
428-
runner = unittest.TextTestRunner(verbosity=1)
429-
result = runner.run(suite)
430-
431-
if not result.wasSuccessful():
432-
sys.exit(1)
414+
def load_tests(loader, tests, ignore):
415+
tests.addTests(doctest.DocTestSuite(jsonpointer))
416+
return tests

0 commit comments

Comments
 (0)