File: how-it-works.rst

package info (click to toggle)
python-sure 2.0.1%2Bgit.2023.02.06.3aef950b7c-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 744 kB
  • sloc: python: 3,512; makefile: 255; sh: 12
file content (46 lines) | stat: -rw-r--r-- 1,391 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
How sure works
==============

The class ``sure.AssertionBuilder`` creates objects capable of doing
assertions. The AssertionBuilder simply arranges a vast set of possible
assertions that are composed by a ``source`` object and a
``destination`` object.

Every assertion, even implicitly if implicitly like in
``(2 < 3).should.be.true``, is doing a source/destination matching.

Chainability
------------

Some specific assertion methods are chainable, it can be useful for
short assertions like:

.. code:: python

    PERSON = {
      "name": "John",
      "facebook_info": {
        "token": "abcd"
      }
    }

    PERSON.should.have.key("facebook_info").being.a(dict)

Monkey-patching
===============

Lincoln Clarete has written the module [``sure/magic.py``] which I
simply added to sure. The most exciting part of the story is that
Lincoln exposed the code with a super clean API, it's called `forbidden
fruit <http://clarete.github.io/forbiddenfruit/>`__

Why CPython-only ?
------------------

Sure uses the `ctypes <http://docs.python.org/library/ctypes>`__ module
to break in python protections against monkey patching.

Although ctypes might also be available in other implementations such as
`Jython <http://www.jython.org/>`__, only the CPython provide
```ctypes.pythonapi`` <http://docs.python.org/library/ctypes#loading-shared-libraries>`__
the features required by sure.