From 062407173465fb8d5b1781fdd12ed37931f1fe34 Mon Sep 17 00:00:00 2001 From: baztian Date: Mon, 23 Jan 2017 21:23:49 +0100 Subject: [PATCH] Try to fix Python 2/3 doctest compatibility again --- test/doctests.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 test/doctests.py diff --git a/test/doctests.py b/test/doctests.py new file mode 100644 index 0000000..f9dc1cb --- /dev/null +++ b/test/doctests.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +"""Run doctests.""" + +import doctest +import sys + +try: + import unittest2 as unittest +except ImportError: + import unittest + +class Py23DocChecker(doctest.OutputChecker): + """Doctest checker to avoid Python 2/3 unicode comparison + issues. Code taken from Dirkjan Ochtman""" + def check_output(self, want, got, optionflags): + if sys.version_info[0] > 2: + want = re.sub("u'(.*?)'", "'\\1'", want) + want = re.sub('u"(.*?)"', '"\\1"', want) + return doctest.OutputChecker.check_output(self, want, got, optionflags) + +def suite(): + suite = unittest.TestSuite() + suite.addTest(doctest.DocFileSuite('../README.rst', + checker=Py23DocChecker())) + return suite; + +def main(): + runner = unittest.TextTestRunner() + runner.run(suite()) + +if __name__ == '__main__': + sys.exit(main())