Skip to content

Commit f1861e1

Browse files
authored
Merge pull request #66 from sgissinger/master
RST update: fixes #57, splitted operator page, added mock operators, other doc refactor
2 parents 0c535b7 + e442f1f commit f1861e1

File tree

11 files changed

+961
-994
lines changed

11 files changed

+961
-994
lines changed

README.rst

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ lightweight assertion library for Python_ that aims to make testing more product
1717
It also comes with a detailed, human-friendly `error reporting`_ system that aims to reduce friction,
1818
provide better feedback and improve human speed and agility while identifying and fixing errors.
1919

20-
To get started, take a look to the `showcase`_ code, `tutorial`_, available `plugins`_ and `operators documentation`_.
20+
To get started, take a look to the `showcase`_ code, `getting started`_, available `plugins`_ and operators documentation (`accessors`_, `attributes`_, `matchers`_).
2121

2222
For HTTP protocol assertions, see `grappa-http`_.
2323

@@ -33,7 +33,7 @@ Showcase
3333
--------
3434

3535
A small example demonstrating some `grappa` features.
36-
See `documentation`_ and `tutorial`_ for more examples.
36+
See `documentation`_ and `getting started`_ for more examples.
3737

3838
.. code-block:: python
3939
@@ -105,26 +105,11 @@ Let's see how the error report looks like in ``grappa`` running in ``pytest``.
105105

106106
See `error reporting`_ documentation for more details about how ``grappa`` error report system works.
107107

108-
.. code-block:: python
108+
.. code-block:: bash
109109
110110
======================================================================
111111
FAIL: tests.should_test.test_grappa_assert
112112
======================================================================
113-
Traceback (most recent call last):
114-
File ".pyenv/versions/3.6.0/lib/python3.6/site-packages/nose/case.py", line 198, in runTest
115-
self.test(*self.arg)
116-
File "grappa/tests/should_test.py", line 16, in test_grappa_assert
117-
x | should.be.have.length.of(4)
118-
File "grappa/grappa/test.py", line 248, in __ror__
119-
return self.__overload__(value)
120-
File "grappa/grappa/test.py", line 236, in __overload__
121-
return self.__call__(subject, overload=True)
122-
File "grappa/grappa/test.py", line 108, in __call__
123-
return self._trigger() if overload else Test(subject)
124-
File "grappa/grappa/test.py", line 153, in _trigger
125-
raise err
126-
AssertionError: Oops! Something went wrong!
127-
128113
The following assertion was not satisfied
129114
subject "[1, 2, 3]" should be have length of "4"
130115
@@ -167,14 +152,6 @@ See `error reporting`_ documentation for more details about how ``grappa`` error
167152
21| False | should.be.false | should.be.equal.to(False)
168153
22| False | should.be.false | should.not_be.equal.to(True)
169154
170-
Demo
171-
----
172-
173-
.. image:: https://asciinema.org/a/d6yd2475m41thdku7d3ntkeir.png
174-
:width: 900
175-
:alt: showcase
176-
:align: center
177-
:target: https://asciinema.org/a/d6yd2475m41thdku7d3ntkeir?autoplay=1&speed=3&size=small
178155
179156
Why grappa?
180157
-----------
@@ -206,7 +183,7 @@ Features
206183
- Behavior-oriented expressive fluent API.
207184
- Built-in assertion DSL with English lexicon and semantics.
208185
- Supports both ``expect`` and ``should`` assertion styles.
209-
- Full-featured built-in `assertion operators`_.
186+
- Full-featured built-in `accessors`_, `attributes`_ and `matchers`_ operators.
210187
- Human-friendly and detailed `error reporting`_.
211188
- Built-in expectations difference comparison between subject and expected values.
212189
- Extensible assertions supporting third-party `plugins`_.
@@ -236,12 +213,13 @@ Or install the latest sources from Github:
236213
237214
.. _Python: http://python.org
238215
.. _`documentation`: http://grappa.readthedocs.io
239-
.. _`operators documentation`: http://grappa.readthedocs.io/en/latest/operators.html
240-
.. _`tutorial`: http://grappa.readthedocs.io/en/latest/tutorial.html
216+
.. _`accessors`: http://grappa.readthedocs.io/en/latest/accessors-operators.html
217+
.. _`attributes`: http://grappa.readthedocs.io/en/latest/attributes-operators.html
218+
.. _`matchers`: http://grappa.readthedocs.io/en/latest/matchers-operators.html
219+
.. _`getting started`: http://grappa.readthedocs.io/en/latest/getting-started.html
241220
.. _`plugins`: http://grappa.readthedocs.io/en/latest/plugins.html
242-
.. _`error reporting`: http://grappa.readthedocs.io/en/latest/errors.html
221+
.. _`error reporting`: http://grappa.readthedocs.io/en/latest/error-reporting.html
243222
.. _`assertion styles`: http://grappa.readthedocs.io/en/latest/style.html
244-
.. _`assertion operators`: http://grappa.readthedocs.io/en/latest/operators.html
245223
.. _`grappa-http`: https://github.com/grappa-py/http
246224

247225
.. |Build Status| image:: https://travis-ci.org/grappa-py/grappa.svg?branch=master

docs/accessors-operators.rst

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
Accessors Operators
2+
===================
3+
4+
These operators do not accept expectation arguments but performs assertion logic.
5+
6+
Example operators: none_, true_, false_, empty_, callable_ ...
7+
8+
9+
true
10+
----
11+
12+
Asserts if a given subject is `True` value.
13+
14+
======================= ========================
15+
**Related operators** false_
16+
======================= ========================
17+
18+
.. code-block:: python
19+
20+
'foo' | should.be.true
21+
'foo' | should.not_be.true
22+
23+
.. code-block:: python
24+
25+
expect('foo').to.be.true
26+
expect('foo').to_not.be.true
27+
28+
29+
false
30+
-----
31+
32+
Asserts if a given subject is `False` value.
33+
34+
======================= ========================
35+
**Related operators** true_
36+
======================= ========================
37+
38+
.. code-block:: python
39+
40+
'foo' | should.be.false
41+
'foo' | should.not_be.false
42+
43+
.. code-block:: python
44+
45+
expect('foo').to.be.false
46+
expect('foo').to_not.be.false
47+
48+
49+
callable
50+
--------
51+
52+
Asserts if a given subject is a callable type or an object that
53+
implements ``__call__()`` magic method.
54+
55+
======================= ========================
56+
**Related operators** implements_
57+
======================= ========================
58+
59+
.. code-block:: python
60+
61+
(lambda x: x) | should.be.callable
62+
None | should.not_be.callable
63+
64+
.. code-block:: python
65+
66+
expect(lambda x: x).to.be.callable
67+
expect(None).to_not.be.callable
68+
69+
70+
empty
71+
-----
72+
73+
Asserts if a given subject is an empty object.
74+
75+
A subject is considered empty if it's ``None``, ``0`` or ``len(subject)``
76+
is equals to ``0``.
77+
78+
======================= ========================
79+
**Related operators** present_ none_
80+
======================= ========================
81+
82+
.. code-block:: python
83+
84+
[] | should.be.empty
85+
[1, 2, 3] | should.not_be.empty
86+
87+
.. code-block:: python
88+
89+
expect(tuple()).to.be.empty
90+
expect((1, 2, 3)).to_not.be.empty
91+
92+
93+
none
94+
----
95+
96+
Asserts if a given subject is ``None``.
97+
98+
======================= ========================
99+
**Related operators** present_ empty_
100+
======================= ========================
101+
102+
.. code-block:: python
103+
104+
None | should.be.none
105+
'foo' | should.not_be.none
106+
107+
.. code-block:: python
108+
109+
expect(None).to.be.none
110+
expect('foo').to_not.be.none
111+
112+
113+
exists
114+
------
115+
present
116+
-------
117+
118+
Asserts if a given subject is not ``None`` or a negative value
119+
if evaluated via logical unary operator.
120+
121+
This operator is the opposite of empty_.
122+
123+
======================= ========================
124+
**Related operators** none_ empty_
125+
======================= ========================
126+
127+
.. code-block:: python
128+
129+
'foo' | should.be.present
130+
'' | should.not_be.present
131+
132+
.. code-block:: python
133+
134+
expect('foo').to.be.present
135+
expect(False).to_not.be.present
136+
137+
138+
.. _`implements`: http://grappa.readthedocs.io/en/latest/matchers-operators.html#implements

docs/attributes-operators.rst

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
Attributes Operators
2+
====================
3+
4+
These operators provides assertion/negation logic.
5+
6+
Example operators: to_, be_ not_be_, which_ ...
7+
8+
9+
Assertion
10+
---------
11+
12+
be
13+
^^
14+
to
15+
^^
16+
has
17+
^^^
18+
have
19+
^^^^
20+
do
21+
^^
22+
include
23+
^^^^^^^
24+
satisfy
25+
^^^^^^^
26+
satisfies
27+
^^^^^^^^^
28+
_is
29+
^^^
30+
which
31+
^^^^^
32+
that
33+
^^^^
34+
that_is
35+
^^^^^^^
36+
which_is
37+
^^^^^^^^
38+
39+
Semantic chainable attributes that defines non-negative assertions.
40+
41+
Typically, you will use them implicitly in order to semantically describe your assertions.
42+
43+
======================= ========================
44+
**Assertion mode** positive
45+
----------------------- ------------------------
46+
**Resets context** no
47+
======================= ========================
48+
49+
.. code-block:: python
50+
51+
'foo' | should.be.equal.to('bar')
52+
'foo' | should.have.length.of(3)
53+
54+
{'foo': 'bar'} | should.have.key('foo').which.should.be.equal.to('bar')
55+
{'foo': 'bar'} | should.have.key('foo').that.should.have.length.of(3)
56+
57+
.. code-block:: python
58+
59+
expect('foo').to.equal.to('bar')
60+
expect('foo').to.have.length.of(3)
61+
62+
expect({'foo': 'bar'}).to.have.key('foo').which.expect.to.be.equal('bar')
63+
expect({'foo': 'bar'}).to.have.key('foo').which.expect.to.have.length.of(3)
64+
65+
66+
Negation
67+
--------
68+
69+
not_be
70+
^^^^^^
71+
not_present
72+
^^^^^^^^^^^
73+
not_to
74+
^^^^^^
75+
to_not
76+
^^^^^^
77+
does_not
78+
^^^^^^^^
79+
do_not
80+
^^^^^^
81+
dont
82+
^^^^
83+
have_not
84+
^^^^^^^^
85+
not_have
86+
^^^^^^^^
87+
has_not
88+
^^^^^^^
89+
not_has
90+
^^^^^^^
91+
that_not
92+
^^^^^^^^
93+
which_not
94+
^^^^^^^^^
95+
is_not
96+
^^^^^^
97+
_not
98+
^^^^
99+
not_satisfy
100+
^^^^^^^^^^^
101+
102+
Semantic chainable attributes that defines negative assertions.
103+
104+
Typically, you will use them implicitly in order to semantically describe your assertions.
105+
106+
======================= ========================
107+
**Assertion mode** negation
108+
----------------------- ------------------------
109+
**Resets context** no
110+
======================= ========================
111+
112+
.. code-block:: python
113+
114+
'foo' | should.not_be.equal.to('bar')
115+
'foo' | should.have_not.length.of(3)
116+
117+
.. code-block:: python
118+
119+
expect('foo').to_not.equal.to('bar')
120+
expect('foo').to.not_have.length.of(3)

docs/composition.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ Use ``|`` operator for composing assertions that matches the following condition
1414
- Assertions that DO tests the same subject.
1515
- Assertions that uses operators that DOES NOT yield a new test subject.
1616

17-
Example
18-
^^^^^^^
19-
2017
.. code-block:: python
2118
2219
'foo' | should.have.length.of(3) | should.contain('o')
@@ -33,9 +30,6 @@ Use ``>`` operator for composing assertions that matches the following condition
3330
- Assertions that DOES NOT test the same subject.
3431
- Assertions that uses operators that YIELDS a new test subject in the assertion chain.
3532

36-
Example
37-
^^^^^^^
38-
3933
.. code-block:: python
4034
4135
[1, 2, 3] | should.be.a(list) > should.have.index.at(2) | should.be.equal.to(3)

0 commit comments

Comments
 (0)