| 1 |
|
| 2 |
|
| 3 |
import sure |
| 4 |
|
| 5 |
|
| 6 |
def test_ensure_simple_assertion(): |
| 7 |
"""Test ensure simple assertion""" |
| 8 |
|
| 9 |
def __test_something(): |
| 10 |
|
| 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 |
|
| 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 |
|
| 25 |
with sure.ensure('neverused'): |
| 26 |
raise Exception('This is not an AssertionError') |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
sure.expect(__test_something).when.called_with().should.throw(Exception, \ |
| 32 |
'This is not an AssertionError') |