Skip to content

Commit 19c0efe

Browse files
authored
Merge pull request #22 from blazelibs/deprecate-raises-decorator
Deprecate raises decorator
2 parents a0f0801 + 6eb5521 commit 19c0efe

File tree

55 files changed

+52
-40
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+52
-40
lines changed

blazeutils/testing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import sys
1212
import warnings
1313

14+
from blazeutils.decorators import deprecate
1415
from blazeutils.log import clear_handlers_by_attr
1516
from blazeutils.helpers import Tee, prettifysql
1617
import six
@@ -150,6 +151,7 @@ def decorate(fn, instance, args, kw):
150151
return decorate
151152

152153

154+
@deprecate('The @raises decorator is deprecated. Use pytest.raises instead.')
153155
def raises(arg1, arg2=None, re_esc=True, **kwargs): # noqa
154156
"""
155157
Decorate a test encorcing it emits the given Exception and message

blazeutils/tests/test_datastructures.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
import random
55

6+
import pytest
67
from six.moves import range
78
import six.moves.cPickle as pickle
89

910
from blazeutils.datastructures import DumbObject, OrderedProperties, OrderedDict, \
1011
LazyOrderedDict, LazyDict, UniqueList
11-
from blazeutils.testing import raises
1212

1313
# leave this here it ensures that LazyDict is available from .datastructures
1414
# even though the code was moved to .containers.
@@ -78,15 +78,15 @@ def test_pickle(self):
7878
assert po.b == 2
7979
assert list(po) == [1, 2]
8080

81-
@raises(AttributeError, 'foo')
8281
def test_attribute_error(self):
8382
o = OrderedProperties()
84-
o.foo
83+
with pytest.raises(AttributeError, match='foo'):
84+
o.foo
8585

86-
@raises(AttributeError, 'foo')
8786
def test_del_attribute_error(self):
8887
o = OrderedProperties()
89-
del o.foo
88+
with pytest.raises(AttributeError, match='foo'):
89+
del o.foo
9090

9191
def test_initilization(self):
9292
o = OrderedProperties(initialize=False)

blazeutils/tests/test_decorators.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import warnings
44

55
import logging
6+
7+
import pytest
68
from mock import Mock, patch, call
79

810
from blazeutils.decorators import curry, decorator
911
from blazeutils.decorators import exc_emailer, retry, hybrid_method
10-
from blazeutils.testing import raises
1112

1213

1314
def test_curry():
@@ -103,15 +104,15 @@ def myfunc():
103104
'then re-raising original exception'),
104105
])
105106

106-
@raises(ValueError)
107107
def test_catch_arg_usage(self):
108108
send_mail = Mock()
109109

110110
@exc_emailer(send_mail, catch=TypeError, print_to_stderr=False)
111111
def myfunc():
112112
raise ValueError('myfunc')
113113

114-
myfunc()
114+
with pytest.raises(ValueError):
115+
myfunc()
115116

116117
@patch('blazeutils.decorators.log')
117118
def test_custom_logger(self, m_log):
@@ -179,7 +180,6 @@ def myfunc():
179180
assert logger.log.call_count == 5
180181
assert logger.log.call_args.args[0] == 10
181182

182-
@raises(TypeError, 'myfunc error')
183183
def test_msg_param(self):
184184
logger = Mock()
185185

@@ -197,7 +197,8 @@ def myfunc():
197197
def myfunc():
198198
raise TypeError('myfunc error')
199199

200-
myfunc()
200+
with pytest.raises(TypeError, match='myfunc error'):
201+
myfunc()
201202

202203

203204
class MethodClass(object):

blazeutils/tests/test_rst.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
from importlib import reload
55
import sys
66

7+
import pytest
78
import blazeutils.rst
8-
from blazeutils.testing import FailLoader, raises
9+
from blazeutils.testing import FailLoader
910

1011
ds_rst = """
1112
Heading 1
@@ -97,9 +98,9 @@ def teardown_class(cls):
9798
sys.meta_path.remove(cls.fl)
9899
reload(blazeutils.rst)
99100

100-
@raises(ImportError, 'docutils library is required')
101101
def test_no_docutils(self):
102-
blazeutils.rst.rst2html('foo')
102+
with pytest.raises(ImportError, match='docutils library is required'):
103+
blazeutils.rst.rst2html('foo')
103104

104105

105106
toc_rst = """

blazeutils/tests/test_testing.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys
55

66
import mock
7+
import pytest
78

89
from blazeutils.testing import raises, assert_equal_sql, assert_equal_txt, \
910
mock_date_today, mock_datetime_now, mock_datetime_utcnow
@@ -133,14 +134,14 @@ def test_assert_equal_sql():
133134
assert_equal_sql(s1, s2)
134135

135136

136-
@raises(AssertionError, ".+!=", re_esc=False)
137137
def test_assert_equal_sql_diff():
138138
s2 = s1 = """
139139
select foo,
140140
bar,
141141
baz from bill"""
142142
s2 = s2[5:]
143-
assert_equal_sql(s1, s2)
143+
with pytest.raises(AssertionError, match=r'.+!='):
144+
assert_equal_sql(s1, s2)
144145

145146

146147
def test_assert_equal_txt():

requirements/common.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

requirements/development.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

requirements/testing.txt

Lines changed: 0 additions & 17 deletions
This file was deleted.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)