##// END OF EJS Templates
Merge pull request #13304 from Kojoley/remove-bunch-of-deprecated-and-unused-testing-decorators...
Matthias Bussonnier -
r27112:1ed2ee03 merge
parent child Browse files
Show More
@@ -61,93 +61,6 b' def as_unittest(func):'
61
61
62 # Utility functions
62 # Utility functions
63
63
64 def apply_wrapper(wrapper, func):
65 """Apply a wrapper to a function for decoration.
66
67 This mixes Michele Simionato's decorator tool with nose's make_decorator,
68 to apply a wrapper in a decorator so that all nose attributes, as well as
69 function signature and other properties, survive the decoration cleanly.
70 This will ensure that wrapped functions can still be well introspected via
71 IPython, for example.
72 """
73 warnings.warn("The function `apply_wrapper` is deprecated since IPython 4.0",
74 DeprecationWarning, stacklevel=2)
75 import nose.tools
76
77 return decorator(wrapper,nose.tools.make_decorator(func)(wrapper))
78
79
80 def make_label_dec(label, ds=None):
81 """Factory function to create a decorator that applies one or more labels.
82
83 Parameters
84 ----------
85 label : string or sequence
86 One or more labels that will be applied by the decorator to the functions
87 it decorates. Labels are attributes of the decorated function with their
88 value set to True.
89
90 ds : string
91 An optional docstring for the resulting decorator. If not given, a
92 default docstring is auto-generated.
93
94 Returns
95 -------
96 A decorator.
97
98 Examples
99 --------
100
101 A simple labeling decorator:
102
103 >>> slow = make_label_dec('slow')
104 >>> slow.__doc__
105 "Labels a test as 'slow'."
106
107 And one that uses multiple labels and a custom docstring:
108
109 >>> rare = make_label_dec(['slow','hard'],
110 ... "Mix labels 'slow' and 'hard' for rare tests.")
111 >>> rare.__doc__
112 "Mix labels 'slow' and 'hard' for rare tests."
113
114 Now, let's test using this one:
115 >>> @rare
116 ... def f(): pass
117 ...
118 >>>
119 >>> f.slow
120 True
121 >>> f.hard
122 True
123 """
124
125 warnings.warn("The function `make_label_dec` is deprecated since IPython 4.0",
126 DeprecationWarning, stacklevel=2)
127 if isinstance(label, str):
128 labels = [label]
129 else:
130 labels = label
131
132 # Validate that the given label(s) are OK for use in setattr() by doing a
133 # dry run on a dummy function.
134 tmp = lambda : None
135 for label in labels:
136 setattr(tmp,label,True)
137
138 # This is the actual decorator we'll return
139 def decor(f):
140 for label in labels:
141 setattr(f,label,True)
142 return f
143
144 # Apply the user's docstring, or autogenerate a basic one
145 if ds is None:
146 ds = "Labels a test as %r." % label
147 decor.__doc__ = ds
148
149 return decor
150
151
64
152 def skipif(skip_condition, msg=None):
65 def skipif(skip_condition, msg=None):
153 """Make function raise SkipTest exception if skip_condition is true
66 """Make function raise SkipTest exception if skip_condition is true
@@ -223,20 +136,6 b' def module_not_available(module):'
223 return mod_not_avail
136 return mod_not_avail
224
137
225
138
226 def decorated_dummy(dec, name):
227 """Return a dummy function decorated with dec, with the given name.
228
229 Examples
230 --------
231 import IPython.testing.decorators as dec
232 setup = dec.decorated_dummy(dec.skip_if_no_x11, __name__)
233 """
234 warnings.warn("The function `decorated_dummy` is deprecated since IPython 4.0",
235 DeprecationWarning, stacklevel=2)
236 dummy = lambda: None
237 dummy.__name__ = name
238 return dec(dummy)
239
240 #-----------------------------------------------------------------------------
139 #-----------------------------------------------------------------------------
241 # Decorators for public use
140 # Decorators for public use
242
141
@@ -268,12 +167,6 b' skip_if_no_x11 = skipif(_x11_skip_cond, _x11_skip_msg)'
268 skip_win32_py38 = skipif(sys.version_info > (3,8) and os.name == 'nt')
167 skip_win32_py38 = skipif(sys.version_info > (3,8) and os.name == 'nt')
269
168
270
169
271 # not a decorator itself, returns a dummy function to be used as setup
272 def skip_file_no_x11(name):
273 warnings.warn("The function `skip_file_no_x11` is deprecated since IPython 4.0",
274 DeprecationWarning, stacklevel=2)
275 return decorated_dummy(skip_if_no_x11, name) if _x11_skip_cond else None
276
277 # Other skip decorators
170 # Other skip decorators
278
171
279 # generic skip without module
172 # generic skip without module
@@ -317,15 +210,3 b' def onlyif_cmds_exist(*commands):'
317
210
318 return pytest.mark.skip(reason=reason)
211 return pytest.mark.skip(reason=reason)
319 return null_deco
212 return null_deco
320
321 def onlyif_any_cmd_exists(*commands):
322 """
323 Decorator to skip test unless at least one of `commands` is found.
324 """
325 warnings.warn("The function `onlyif_any_cmd_exists` is deprecated since IPython 4.0",
326 DeprecationWarning, stacklevel=2)
327 for cmd in commands:
328 if shutil.which(cmd):
329 return null_deco
330 return skip("This test runs only if one of the commands {0} "
331 "is installed".format(commands))
General Comments 0
You need to be logged in to leave comments. Login now