bebraw
2/28/2010 - 4:55 PM

gistfile1.py

>>> from expecter import expect

# Expecter Gadget (note verbose error):
>>> expect(1) > 100
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python26\lib\site-packages\expecter.py", line 24, in __gt__
    % (repr(other), repr(self._value)))
AssertionError: Expected something greater than 100 but got 1

# Regular Assert:
>>> assert 1 > 100
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError

# Exception tests:
>>> with expect.raises(KeyError):
...     pass
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "C:\Python26\lib\site-packages\expecter.py", line 54, in __exit__
    % self._exception_class.__name__)
AssertionError: Expected an exception of type KeyError but got none
>>> with expect.raises(KeyError):
...     {}['foobar']
...