[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.

authorDenis Laxalde <denis.laxalde@logilab.fr>
changeset03ef72ac6fdb
branchdefault
phasepublic
hiddenno
parent revision#f3c053de3a0a Deprecate logilab-pytest
child revision#9a8f910ac6f9 [configuration] Fix multi-line strings handling
files modified by this revision
logilab/common/fileutils.py
logilab/common/testlib.py
test/unittest_fileutils.py
test/unittest_modutils.py
test/unittest_textutils.py
# HG changeset patch
# User Denis Laxalde <denis.laxalde@logilab.fr>
# Date 1453211253 -3600
# Tue Jan 19 14:47:33 2016 +0100
# Node ID 03ef72ac6fdb07a0461ddee4d91cb850e6b46407
# Parent f3c053de3a0a29e94a7334595599e9fe77209002
[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.

diff --git a/logilab/common/fileutils.py b/logilab/common/fileutils.py
@@ -65,17 +65,11 @@
1          return tail
2      # path was absolute, head is the fs root
3      return head
4 
5  def abspath_listdir(path):
6 -    """Lists path's content using absolute paths.
7 -
8 -    >>> os.listdir('/home')
9 -    ['adim', 'alf', 'arthur', 'auc']
10 -    >>> abspath_listdir('/home')
11 -    ['/home/adim', '/home/alf', '/home/arthur', '/home/auc']
12 -    """
13 +    """Lists path's content using absolute paths."""
14      path = abspath(path)
15      return [join(path, filename) for filename in listdir(path)]
16 
17 
18  def is_binary(filename):
diff --git a/logilab/common/testlib.py b/logilab/common/testlib.py
@@ -54,14 +54,14 @@
19  import warnings
20  from shutil import rmtree
21  from operator import itemgetter
22  from inspect import isgeneratorfunction
23 
24 -from six import PY2, string_types
25 +from six import PY2, add_metaclass, string_types
26  from six.moves import builtins, range, configparser, input
27 
28 -from logilab.common.deprecation import deprecated
29 +from logilab.common.deprecation import class_deprecated, deprecated
30 
31  import unittest as unittest_legacy
32  if not getattr(unittest_legacy, "__package__", None):
33      try:
34          import unittest2 as unittest
@@ -548,15 +548,17 @@
35              return None
36          return doctest.DocTestFinder._get_test(self, obj, name, module,
37                                                 globs, source_lines)
38 
39 
40 +@add_metaclass(class_deprecated)
41  class DocTest(TestCase):
42      """trigger module doctest
43      I don't know how to make unittest.main consider the DocTestSuite instance
44      without this hack
45      """
46 +    __deprecation_warning__ = 'use stdlib doctest module with unittest API directly'
47      skipped = ()
48      def __call__(self, result=None, runcondition=None, options=None):\
49          # pylint: disable=W0613
50          try:
51              finder = DocTestFinder(skipped=self.skipped)
diff --git a/test/unittest_fileutils.py b/test/unittest_fileutils.py
@@ -15,10 +15,11 @@
52  #
53  # You should have received a copy of the GNU Lesser General Public License along
54  # with logilab-common.  If not, see <http://www.gnu.org/licenses/>.
55  """unit tests for logilab.common.fileutils"""
56 
57 +import doctest
58  import sys, os, tempfile, shutil
59  from stat import S_IWRITE
60  from os.path import join
61 
62  from logilab.common.testlib import TestCase, unittest_main, unittest
@@ -130,18 +131,14 @@
63          wp_file.close()
64          #self.assertTrue(not os.access(self.rpath, os.W_OK))
65          self.assertTrue(not os.stat(self.rpath).st_mode & S_IWRITE)
66 
67 
68 -from logilab.common.testlib import DocTest
69  if sys.version_info < (3, 0):
70 -    # skip if python3, test fail because of traceback display incompatibility :(
71 -    class ModuleDocTest(DocTest):
72 -        """relative_path embed tests in docstring"""
73 -        from logilab.common import fileutils as module
74 -        skipped = ('abspath_listdir',)
75 +    def load_tests(loader, tests, ignore):
76 +        from logilab.common import fileutils
77 +        tests.addTests(doctest.DocTestSuite(fileutils))
78 +        return tests
79 
80 
81 -del DocTest # necessary if we don't want it to be executed (we don't...)
82 -
83  if __name__ == '__main__':
84      unittest_main()
diff --git a/test/unittest_modutils.py b/test/unittest_modutils.py
@@ -17,10 +17,11 @@
85  # with logilab-common.  If not, see <http://www.gnu.org/licenses/>.
86  """
87  unit tests for module modutils (module manipulation utilities)
88  """
89 
90 +import doctest
91  import sys
92  try:
93      __file__
94  except NameError:
95      __file__ = sys.argv[0]
@@ -277,14 +278,14 @@
96          m = modutils.load_module_from_modpath(['logilab', 'common', 'fileutils'])
97          self.assertTrue( hasattr(logilab, 'common') )
98          self.assertTrue( hasattr(logilab.common, 'fileutils') )
99          self.assertTrue( m is logilab.common.fileutils )
100 
101 -from logilab.common.testlib import DocTest
102 -class ModuleDocTest(DocTest):
103 -    """test doc test in this module"""
104 -    from logilab.common import modutils as module
105 -del DocTest # necessary if we don't want it to be executed (we don't...)
106 +
107 +def load_tests(loader, tests, ignore):
108 +    from logilab.common import modutils
109 +    tests.addTests(doctest.DocTestSuite(modutils))
110 +    return tests
111 
112 
113  if __name__ == '__main__':
114      unittest_main()
diff --git a/test/unittest_textutils.py b/test/unittest_textutils.py
@@ -19,15 +19,16 @@
115  """
116  unit tests for module textutils
117  squeleton generated by /home/syt/cvs_work/logilab/pyreverse/py2tests.py on Sep 08 at 09:1:31
118 
119  """
120 +import doctest
121  import re
122  from os import linesep
123 
124 -from logilab.common import textutils as tu # .textutils import *
125 -from logilab.common.testlib import TestCase, DocTest, unittest_main
126 +from logilab.common import textutils as tu
127 +from logilab.common.testlib import TestCase, unittest_main
128 
129 
130  if linesep != '\n':
131      import re
132      LINE_RGX = re.compile(linesep)
@@ -254,13 +255,12 @@
133      def test_unormalize_backward_compat(self):
134          self.assertRaises(ValueError, tu.unormalize, u"\u8000")
135          self.assertEqual(tu.unormalize(u"\u8000", substitute=''), u'')
136 
137 
138 -class ModuleDocTest(DocTest):
139 -    """test doc test in this module"""
140 -    module = tu
141 -    # from logilab.common import textutils as module
142 -del DocTest # necessary if we don't want it to be executed (we don't...)
143 +def load_tests(loader, tests, ignore):
144 +    tests.addTests(doctest.DocTestSuite(tu))
145 +    return tests
146 +
147 
148  if __name__ == '__main__':
149      unittest_main()