Debian Codegraph @

tests/test_ensure_ctxmgr.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 import sure
4
5
6 def test_ensure_simple_assertion():
7 """Test ensure simple assertion"""
8
9 def __test_something():
10 # same calculated value
11 name = 'Hodor'
12 with sure.ensure('the return value actually looks like: {0}', name):
13 sure.expect(name).should.contain('whatever')
14
15
16 # check if the test function raises the custom AssertionError
17 sure.expect(__test_something).when.called_with().should.throw(AssertionError, \
18 'the return value actually looks like: Hodor')
19
20
21 def test_ensure_just_assertion_error():
22 """Test that ensure only captures AssertionErrors"""
23 def __test_something():
24 # same calculated value
25 with sure.ensure('neverused'):
26 raise Exception('This is not an AssertionError')
27
28
29 # check if the test function does not override the original exception
30 # if it is not an AssertionError exception
31 sure.expect(__test_something).when.called_with().should.throw(Exception, \
32 'This is not an AssertionError')