-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from gabrielfalcao/feature/custom-assertion-msg
Add ensure context manager for custom assert messages
- Loading branch information
Showing
4 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import sure | ||
|
||
|
||
def test_ensure_simple_assertion(): | ||
"""Test ensure simple assertion""" | ||
|
||
def __test_something(): | ||
# same calculated value | ||
name = 'Hodor' | ||
with sure.ensure('the return value actually looks like: {0}', name): | ||
sure.expect(name).should.contain('whatever') | ||
|
||
|
||
# check if the test function raises the custom AssertionError | ||
sure.expect(__test_something).when.called_with().should.throw(AssertionError, \ | ||
'the return value actually looks like: Hodor') | ||
|
||
|
||
def test_ensure_just_assertion_error(): | ||
"""Test that ensure only captures AssertionErrors""" | ||
def __test_something(): | ||
# same calculated value | ||
with sure.ensure('neverused'): | ||
raise Exception('This is not an AssertionError') | ||
|
||
|
||
# check if the test function does not override the original exception | ||
# if it is not an AssertionError exception | ||
sure.expect(__test_something).when.called_with().should.throw(Exception, \ | ||
'This is not an AssertionError') |