| 1 |
How sure works |
| 2 |
============== |
| 3 |
|
| 4 |
The class ``sure.AssertionBuilder`` creates objects capable of doing |
| 5 |
assertions. The AssertionBuilder simply arranges a vast set of possible |
| 6 |
assertions that are composed by a ``source`` object and a |
| 7 |
``destination`` object. |
| 8 |
|
| 9 |
Every assertion, even implicitly if implicitly like in |
| 10 |
``(2 < 3).should.be.true``, is doing a source/destination matching. |
| 11 |
|
| 12 |
Chainability |
| 13 |
------------ |
| 14 |
|
| 15 |
Some specific assertion methods are chainable, it can be useful for |
| 16 |
short assertions like: |
| 17 |
|
| 18 |
.. code:: python |
| 19 |
|
| 20 |
PERSON = { |
| 21 |
"name": "John", |
| 22 |
"facebook_info": { |
| 23 |
"token": "abcd" |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
PERSON.should.have.key("facebook_info").being.a(dict) |
| 28 |
|
| 29 |
Monkey-patching |
| 30 |
=============== |
| 31 |
|
| 32 |
Lincoln Clarete has written the module [``sure/magic.py``] which I |
| 33 |
simply added to sure. The most exciting part of the story is that |
| 34 |
Lincoln exposed the code with a super clean API, it's called `forbidden |
| 35 |
fruit <http://clarete.github.io/forbiddenfruit/>`__ |
| 36 |
|
| 37 |
Why CPython-only ? |
| 38 |
------------------ |
| 39 |
|
| 40 |
Sure uses the `ctypes <http://docs.python.org/library/ctypes>`__ module |
| 41 |
to break in python protections against monkey patching. |
| 42 |
|
| 43 |
Although ctypes might also be available in other implementations such as |
| 44 |
`Jython <http://www.jython.org/>`__, only the CPython provide |
| 45 |
```ctypes.pythonapi`` <http://docs.python.org/library/ctypes#loading-shared-libraries>`__ |
| 46 |
the features required by sure. |