summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Laxalde <denis.laxalde@logilab.fr>2016-01-19 14:47:33 +0100
committerDenis Laxalde <denis.laxalde@logilab.fr>2016-01-19 14:47:33 +0100
commit26f0436667158ac9ed0b2e5b085158787fd6209b (patch)
tree0eb9862ffa953c96b40a11eac3fdb92358ecc736
parenta98eab8a863cecfad72b981307b43ee44d1f9f3a (diff)
downloadlogilab-common-26f0436667158ac9ed0b2e5b085158787fd6209b.tar.gz
[testlib] Deprecate doctest things in favour of stdlib module
And adjust all tests accordingly. Drop docstring example from fileutils.abspath_listdir since I could not have it skipped.
-rw-r--r--logilab/common/fileutils.py8
-rw-r--r--logilab/common/testlib.py6
-rw-r--r--test/unittest_fileutils.py13
-rw-r--r--test/unittest_modutils.py11
-rw-r--r--test/unittest_textutils.py14
5 files changed, 23 insertions, 29 deletions
diff --git a/logilab/common/fileutils.py b/logilab/common/fileutils.py
index b30cf5f..366d23d 100644
--- a/logilab/common/fileutils.py
+++ b/logilab/common/fileutils.py
@@ -67,13 +67,7 @@ def first_level_directory(path):
return head
def abspath_listdir(path):
- """Lists path's content using absolute paths.
-
- >>> os.listdir('/home')
- ['adim', 'alf', 'arthur', 'auc']
- >>> abspath_listdir('/home')
- ['/home/adim', '/home/alf', '/home/arthur', '/home/auc']
- """
+ """Lists path's content using absolute paths."""
path = abspath(path)
return [join(path, filename) for filename in listdir(path)]
diff --git a/logilab/common/testlib.py b/logilab/common/testlib.py
index 4310a29..fa3e36e 100644
--- a/logilab/common/testlib.py
+++ b/logilab/common/testlib.py
@@ -56,10 +56,10 @@ from shutil import rmtree
from operator import itemgetter
from inspect import isgeneratorfunction
-from six import PY2, string_types
+from six import PY2, add_metaclass, string_types
from six.moves import builtins, range, configparser, input
-from logilab.common.deprecation import deprecated
+from logilab.common.deprecation import class_deprecated, deprecated
import unittest as unittest_legacy
if not getattr(unittest_legacy, "__package__", None):
@@ -550,11 +550,13 @@ class DocTestFinder(doctest.DocTestFinder):
globs, source_lines)
+@add_metaclass(class_deprecated)
class DocTest(TestCase):
"""trigger module doctest
I don't know how to make unittest.main consider the DocTestSuite instance
without this hack
"""
+ __deprecation_warning__ = 'use stdlib doctest module with unittest API directly'
skipped = ()
def __call__(self, result=None, runcondition=None, options=None):\
# pylint: disable=W0613
diff --git a/test/unittest_fileutils.py b/test/unittest_fileutils.py
index 927347d..80cefe4 100644
--- a/test/unittest_fileutils.py
+++ b/test/unittest_fileutils.py
@@ -17,6 +17,7 @@
# with logilab-common. If not, see <http://www.gnu.org/licenses/>.
"""unit tests for logilab.common.fileutils"""
+import doctest
import sys, os, tempfile, shutil
from stat import S_IWRITE
from os.path import join
@@ -132,16 +133,12 @@ class ProtectedFileTC(TestCase):
self.assertTrue(not os.stat(self.rpath).st_mode & S_IWRITE)
-from logilab.common.testlib import DocTest
if sys.version_info < (3, 0):
- # skip if python3, test fail because of traceback display incompatibility :(
- class ModuleDocTest(DocTest):
- """relative_path embed tests in docstring"""
- from logilab.common import fileutils as module
- skipped = ('abspath_listdir',)
+ def load_tests(loader, tests, ignore):
+ from logilab.common import fileutils
+ tests.addTests(doctest.DocTestSuite(fileutils))
+ return tests
-del DocTest # necessary if we don't want it to be executed (we don't...)
-
if __name__ == '__main__':
unittest_main()
diff --git a/test/unittest_modutils.py b/test/unittest_modutils.py
index dfed2ff..384f582 100644
--- a/test/unittest_modutils.py
+++ b/test/unittest_modutils.py
@@ -19,6 +19,7 @@
unit tests for module modutils (module manipulation utilities)
"""
+import doctest
import sys
try:
__file__
@@ -279,11 +280,11 @@ class get_modules_files_tc(ModutilsTestCase):
self.assertTrue( hasattr(logilab.common, 'fileutils') )
self.assertTrue( m is logilab.common.fileutils )
-from logilab.common.testlib import DocTest
-class ModuleDocTest(DocTest):
- """test doc test in this module"""
- from logilab.common import modutils as module
-del DocTest # necessary if we don't want it to be executed (we don't...)
+
+def load_tests(loader, tests, ignore):
+ from logilab.common import modutils
+ tests.addTests(doctest.DocTestSuite(modutils))
+ return tests
if __name__ == '__main__':
diff --git a/test/unittest_textutils.py b/test/unittest_textutils.py
index db18d0d..8deb4ee 100644
--- a/test/unittest_textutils.py
+++ b/test/unittest_textutils.py
@@ -21,11 +21,12 @@ unit tests for module textutils
squeleton generated by /home/syt/cvs_work/logilab/pyreverse/py2tests.py on Sep 08 at 09:1:31
"""
+import doctest
import re
from os import linesep
-from logilab.common import textutils as tu # .textutils import *
-from logilab.common.testlib import TestCase, DocTest, unittest_main
+from logilab.common import textutils as tu
+from logilab.common.testlib import TestCase, unittest_main
if linesep != '\n':
@@ -256,11 +257,10 @@ class UnormalizeTC(TestCase):
self.assertEqual(tu.unormalize(u"\u8000", substitute=''), u'')
-class ModuleDocTest(DocTest):
- """test doc test in this module"""
- module = tu
- # from logilab.common import textutils as module
-del DocTest # necessary if we don't want it to be executed (we don't...)
+def load_tests(loader, tests, ignore):
+ tests.addTests(doctest.DocTestSuite(tu))
+ return tests
+
if __name__ == '__main__':
unittest_main()