Skip to content

Commit

Permalink
Merge pull request #22 from blazelibs/deprecate-raises-decorator
Browse files Browse the repository at this point in the history
Deprecate raises decorator
  • Loading branch information
guruofgentoo committed Jan 22, 2021
2 parents a0f0801 + 6eb5521 commit 19c0efe
Show file tree
Hide file tree
Showing 55 changed files with 52 additions and 40 deletions.
2 changes: 2 additions & 0 deletions blazeutils/testing.py
Expand Up @@ -11,6 +11,7 @@
import sys
import warnings

from blazeutils.decorators import deprecate
from blazeutils.log import clear_handlers_by_attr
from blazeutils.helpers import Tee, prettifysql
import six
Expand Down Expand Up @@ -150,6 +151,7 @@ def decorate(fn, instance, args, kw):
return decorate


@deprecate('The @raises decorator is deprecated. Use pytest.raises instead.')
def raises(arg1, arg2=None, re_esc=True, **kwargs): # noqa
"""
Decorate a test encorcing it emits the given Exception and message
Expand Down
10 changes: 5 additions & 5 deletions blazeutils/tests/test_datastructures.py
Expand Up @@ -3,12 +3,12 @@

import random

import pytest
from six.moves import range
import six.moves.cPickle as pickle

from blazeutils.datastructures import DumbObject, OrderedProperties, OrderedDict, \
LazyOrderedDict, LazyDict, UniqueList
from blazeutils.testing import raises

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

@raises(AttributeError, 'foo')
def test_attribute_error(self):
o = OrderedProperties()
o.foo
with pytest.raises(AttributeError, match='foo'):
o.foo

@raises(AttributeError, 'foo')
def test_del_attribute_error(self):
o = OrderedProperties()
del o.foo
with pytest.raises(AttributeError, match='foo'):
del o.foo

def test_initilization(self):
o = OrderedProperties(initialize=False)
Expand Down
11 changes: 6 additions & 5 deletions blazeutils/tests/test_decorators.py
Expand Up @@ -3,11 +3,12 @@
import warnings

import logging

import pytest
from mock import Mock, patch, call

from blazeutils.decorators import curry, decorator
from blazeutils.decorators import exc_emailer, retry, hybrid_method
from blazeutils.testing import raises


def test_curry():
Expand Down Expand Up @@ -103,15 +104,15 @@ def myfunc():
'then re-raising original exception'),
])

@raises(ValueError)
def test_catch_arg_usage(self):
send_mail = Mock()

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

myfunc()
with pytest.raises(ValueError):
myfunc()

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

@raises(TypeError, 'myfunc error')
def test_msg_param(self):
logger = Mock()

Expand All @@ -197,7 +197,8 @@ def myfunc():
def myfunc():
raise TypeError('myfunc error')

myfunc()
with pytest.raises(TypeError, match='myfunc error'):
myfunc()


class MethodClass(object):
Expand Down
7 changes: 4 additions & 3 deletions blazeutils/tests/test_rst.py
Expand Up @@ -4,8 +4,9 @@
from importlib import reload
import sys

import pytest
import blazeutils.rst
from blazeutils.testing import FailLoader, raises
from blazeutils.testing import FailLoader

ds_rst = """
Heading 1
Expand Down Expand Up @@ -97,9 +98,9 @@ def teardown_class(cls):
sys.meta_path.remove(cls.fl)
reload(blazeutils.rst)

@raises(ImportError, 'docutils library is required')
def test_no_docutils(self):
blazeutils.rst.rst2html('foo')
with pytest.raises(ImportError, match='docutils library is required'):
blazeutils.rst.rst2html('foo')


toc_rst = """
Expand Down
5 changes: 3 additions & 2 deletions blazeutils/tests/test_testing.py
Expand Up @@ -4,6 +4,7 @@
import sys

import mock
import pytest

from blazeutils.testing import raises, assert_equal_sql, assert_equal_txt, \
mock_date_today, mock_datetime_now, mock_datetime_utcnow
Expand Down Expand Up @@ -133,14 +134,14 @@ def test_assert_equal_sql():
assert_equal_sql(s1, s2)


@raises(AssertionError, ".+!=", re_esc=False)
def test_assert_equal_sql_diff():
s2 = s1 = """
select foo,
bar,
baz from bill"""
s2 = s2[5:]
assert_equal_sql(s1, s2)
with pytest.raises(AssertionError, match=r'.+!='):
assert_equal_sql(s1, s2)


def test_assert_equal_txt():
Expand Down
2 changes: 0 additions & 2 deletions requirements/common.txt

This file was deleted.

5 changes: 0 additions & 5 deletions requirements/development.txt

This file was deleted.

17 changes: 0 additions & 17 deletions requirements/testing.txt

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed requirements/wheelhouse/xlrd-1.0.0-py2-none-any.whl
Binary file not shown.
Binary file removed requirements/wheelhouse/xlrd-1.0.0-py3-none-any.whl
Binary file not shown.
Binary file not shown.
31 changes: 31 additions & 0 deletions setup.py
Expand Up @@ -14,6 +14,33 @@
with open(version_fpath) as fo:
exec(fo.read(), version_globals)


test_requires = [
'codecov',
'docutils',
'mock',
'openpyxl',
'pytest',
'pytest-cov',
'sqlalchemy',
'tox',
'wheel',
'xlwt',
'xlrd',
'xlsxwriter',

# pytest dep on windows
'colorama'
]


dev_requires = [
*test_requires,
'flake8',
'restview',
'wheel',
]

setup(
name="BlazeUtils",
version=version_globals['VERSION'],
Expand All @@ -38,4 +65,8 @@
zip_safe=False,
include_package_data=True,
install_requires=['six', 'wrapt'],
extras_require={
'dev': dev_requires,
'test': test_requires,
}
)
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -3,7 +3,7 @@ envlist = py36,py37,py38,flake8

[testenv]
commands =
pip install -r requirements/testing.txt
pip install --progress-bar off .[test]
py.test \
--tb native \
--strict \
Expand Down

0 comments on commit 19c0efe

Please sign in to comment.