# Path: smarkets/errors.py
# def swallow(exceptions, default=None):
#     '''
#     Swallow exception(s) when executing something. Works as function decorator and
#     as a context manager:
# 
#     >>> @swallow(NameError, default=2)
#     ... def fun():
#     ...     a = b  # noqa
#     ...     return 1
#     ...
#     >>> fun()
#     2
#     >>> with swallow(KeyError):
#     ...    raise KeyError('key')
#     ...
# 
#     :type exceptions: iterable of Exception or Exception
#     :param default: value to return in case of an exception
#     '''
#     if isinstance(exceptions, type):
#         exceptions = (exceptions,)
#     else:
#         exceptions = tuple(exceptions)
# 
#     return _SwallowHandler(exceptions, default)


from nose.tools import eq_, raises
from smarkets.errors import swallow
from __future__ import absolute_import




def throw_or_return(to_raise=None, to_return=None):
    if to_raise:
        raise to_raise  # pylint: disable=E0702

    if to_return:
        return to_return


class TestSwallow(object):

    def setup(self):

# Path: smarkets/errors.py
# def swallow(exceptions, default=None):
#     '''
#     Swallow exception(s) when executing something. Works as function decorator and
#     as a context manager:
# 
#     >>> @swallow(NameError, default=2)
#     ... def fun():
#     ...     a = b  # noqa
#     ...     return 1
#     ...
#     >>> fun()
#     2
#     >>> with swallow(KeyError):
#     ...    raise KeyError('key')
#     ...
# 
#     :type exceptions: iterable of Exception or Exception
#     :param default: value to return in case of an exception
#     '''
#     if isinstance(exceptions, type):
#         exceptions = (exceptions,)
#     else:
#         exceptions = tuple(exceptions)
# 
#     return _SwallowHandler(exceptions, default)


# Path: smarkets/tests/errors.py
from nose.tools import eq_, raises
from smarkets.errors import swallow

from __future__ import absolute_import




def throw_or_return(to_raise=None, to_return=None):
    if to_raise:
        raise to_raise  # pylint: disable=E0702

    if to_return:
        return to_return


class TestSwallow(object):

    def setup(self):

        self.fun = swallow(exceptions=Exception, default='default_value')(throw_or_return)