hamcrest/PyHamcrest — pull request #30 by perfa (2013-01-25 21:45:03+00:00)
Title: Created calling/raises matcher

New functional implementation of assert raises that uses the matcher style of hamcrest to check that exceptions are being raised as expected with the new matcher `raises`. There is a helper called `calling` that wraps a call with arguments to delay execution to where the matcher can catch any raised exception, but you can happily use `raises` on any function that takes no arguments. As a bonus, you can provide a regex to `raises` and it will look for that pattern in the stringification of the assertion - important in cases where a verification stage may throw variations of the same assertion.

Accepts any subclass of the exception provided. Does not try to run uncallable actuals.

```python
assert_that(calling(parse, bad_data), raises(ValueError))
assert_that(calling(translate).with_(curse_words), raises(LanguageError, "\w+very naughty"))
assert_that(broken, raises(Exception))
# This will fail and complain that 23 is not callable
# assert_that(23, raises(IOError))
```