| 1 |
# (C) Copyright 2005-2023 Enthought, Inc., Austin, TX |
| 2 |
# All rights reserved. |
| 3 |
# |
| 4 |
# This software is provided without warranty under the terms of the BSD |
| 5 |
# license included in LICENSE.txt and may be redistributed only under |
| 6 |
# the conditions described in the aforementioned license. The license |
| 7 |
# is also available online at http://www.enthought.com/licenses/BSD.txt |
| 8 |
# |
| 9 |
# Thanks for using Enthought open source! |
| 10 |
|
| 11 |
""" Non-standard functions for the 'nose' testing framework |
| 12 |
|
| 13 |
This module is deprecated, and will be removed in a future release. |
| 14 |
|
| 15 |
.. deprecated:: 6.1.0 |
| 16 |
|
| 17 |
""" |
| 18 |
|
| 19 |
import warnings |
| 20 |
|
| 21 |
try: |
| 22 |
from nose import DeprecatedTest, SkipTest |
| 23 |
from nose.tools import make_decorator |
| 24 |
|
| 25 |
def skip(f): |
| 26 |
""" Decorator to indicate a test should be skipped. |
| 27 |
|
| 28 |
.. deprecated:: 6.1.0 |
| 29 |
|
| 30 |
""" |
| 31 |
warnings.warn( |
| 32 |
"The traits.testing.nose_tools module and its contents " |
| 33 |
"are deprecated", |
| 34 |
DeprecationWarning, |
| 35 |
stacklevel=2, |
| 36 |
) |
| 37 |
|
| 38 |
def g(*args, **kw): |
| 39 |
raise SkipTest() |
| 40 |
|
| 41 |
return make_decorator(f)(g) |
| 42 |
|
| 43 |
def deprecated(f): |
| 44 |
""" Decorator to indicate a test is deprecated. |
| 45 |
|
| 46 |
.. deprecated:: 6.1.0 |
| 47 |
|
| 48 |
""" |
| 49 |
warnings.warn( |
| 50 |
"The traits.testing.nose_tools module and its contents " |
| 51 |
"are deprecated", |
| 52 |
DeprecationWarning, |
| 53 |
stacklevel=2, |
| 54 |
) |
| 55 |
|
| 56 |
def g(*args, **kw): |
| 57 |
raise DeprecatedTest() |
| 58 |
|
| 59 |
return make_decorator(f)(g) |
| 60 |
|
| 61 |
|
| 62 |
except ImportError: |
| 63 |
# Define stubs in case nose isn't installed. |
| 64 |
|
| 65 |
def skip(f): |
| 66 |
""" Stub replacement for marking a unit test to be skipped in the |
| 67 |
absence of 'nose'. |
| 68 |
|
| 69 |
.. deprecated:: 6.1.0 |
| 70 |
""" |
| 71 |
warnings.warn( |
| 72 |
"The traits.testing.nose_tools module and its contents " |
| 73 |
"are deprecated", |
| 74 |
DeprecationWarning, |
| 75 |
stacklevel=2, |
| 76 |
) |
| 77 |
|
| 78 |
warnings.warn("skipping unit tests requires the package 'nose'") |
| 79 |
return f |
| 80 |
|
| 81 |
def deprecated(f): |
| 82 |
""" Stub replacement for marking a unit test deprecated in the absence |
| 83 |
of 'nose'. |
| 84 |
|
| 85 |
.. deprecated:: 6.1.0 |
| 86 |
""" |
| 87 |
warnings.warn( |
| 88 |
"The traits.testing.nose_tools module and its contents " |
| 89 |
"are deprecated", |
| 90 |
DeprecationWarning, |
| 91 |
stacklevel=2, |
| 92 |
) |
| 93 |
|
| 94 |
warnings.warn( |
| 95 |
"skipping deprecated unit tests requires the package 'nose'" |
| 96 |
) |
| 97 |
return f |
| 98 |
|
| 99 |
|
| 100 |
def performance(f): |
| 101 |
""" Decorator to add an attribute to the test to mark it as |
| 102 |
a performance-measuring test. |
| 103 |
|
| 104 |
.. deprecated:: 6.1.0 |
| 105 |
|
| 106 |
""" |
| 107 |
warnings.warn( |
| 108 |
"The traits.testing.nose_tools module and its contents " |
| 109 |
"are deprecated", |
| 110 |
DeprecationWarning, |
| 111 |
stacklevel=2, |
| 112 |
) |
| 113 |
|
| 114 |
f.performance = True |
| 115 |
return f |