How to use the deal.raises function in deal

To help you get started, we’ve selected a few deal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github life4 / deal / tests / test_aliases.py View on Github external
    @deal.raises(ValueError)
    @deal.offline()
    @deal.offline
    @deal.safe
    @deal.safe()
    @deal.silent
    @deal.silent()
    @deal.pure
    @deal.chain(deal.safe, deal.silent)
    def func(x: int) -> int:
        """docs were before docker
        """
        return x
github life4 / deal / tests / test_decorators / test_raises.py View on Github external
    @deal.raises(ZeroDivisionError)
    @deal.offline
    def func(do, number):
        if do:
            http = urllib3.PoolManager()
            http.request('GET', 'http://httpbin.org/robots.txt')
        yield 1 / number
github life4 / deal / tests.py View on Github external
        @deal.raises(ZeroDivisionError)
        @deal.pre(lambda a, b: a > 0 and b > 0)
        def div(a: int, b: int) -> float:
            assert isinstance(a, int)
            assert isinstance(b, int)
            assert a > 0
            assert b > 0
            return a / b
github life4 / deal / tests / test_case.py View on Github external
@deal.raises(ZeroDivisionError)
@deal.pre(lambda a, b: a > 0)
@deal.pre(lambda a, b: b > 0, message='b must be positive')
def div(a: int, b: int) -> float:
    assert isinstance(a, int)
    assert isinstance(b, int)
    assert a > 0
    assert b > 0
    return a / b
github life4 / deal / tests.py View on Github external
def test_main(self):
        func = deal.raises(ZeroDivisionError)(lambda x: 1 / x)
        with self.subTest(text='good'):
            with pytest.raises(ZeroDivisionError):
                func(0)
        with self.subTest(text='good'):
            func(2)

        func = deal.raises(KeyError)(lambda x: 1 / x)
        with self.subTest(text='error'):
            with pytest.raises(deal.RaisesContractError):
                func(0)
github life4 / deal / tests / test_decorators / test_raises.py View on Github external
def test_raises_expects_function_to_raise_error():
    func = deal.raises(ZeroDivisionError)(lambda x: 1 / x)
    with pytest.raises(ZeroDivisionError):
        func(0)
    func(2)

    func = deal.raises(KeyError)(lambda x: 1 / x)
    with pytest.raises(deal.RaisesContractError):
        func(0)
github life4 / deal / tests / test_decorators / test_raises.py View on Github external
    @deal.raises(ZeroDivisionError)
    def func(x):
        if x == -1:
            raise KeyError
        yield 1 / x
github life4 / deal / example.py View on Github external
@deal.raises()
def f():
    a
    1 / 0
    return getfile(deal)