|
1 | 1 | Python Asserts |
2 | 2 | ============== |
3 | 3 |
|
4 | | -.. image:: https://img.shields.io/pypi/l/asserts.svg |
5 | | - :target: https://pypi.python.org/pypi/asserts/ |
6 | | -.. image:: https://img.shields.io/github/release/srittau/python-asserts/all.svg |
7 | | - :target: https://github.com/srittau/python-asserts/releases/ |
8 | | -.. image:: https://img.shields.io/pypi/v/asserts.svg |
9 | | - :target: https://pypi.python.org/pypi/asserts/ |
10 | | -.. image:: https://travis-ci.org/srittau/python-asserts.svg?branch=master |
11 | | - :target: https://travis-ci.org/srittau/python-asserts |
| 4 | +[](https://pypi.python.org/pypi/asserts/) |
| 5 | +[](https://github.com/srittau/python-asserts/releases/) |
| 6 | +[](https://pypi.python.org/pypi/asserts/) |
| 7 | +[](https://travis-ci.org/srittau/python-asserts) |
12 | 8 |
|
13 | 9 | Stand-alone Assertions for Python |
14 | 10 |
|
15 | 11 | This package provides a few advantages over the assertions provided by |
16 | 12 | unittest.TestCase: |
17 | 13 |
|
18 | 14 | * Can be used stand-alone, for example: |
19 | | - |
20 | | - * In test cases, not derived from TestCase. |
21 | | - * In fake and mock classes. |
22 | | - * In implementations as rich alternative to the assert statement. |
23 | | - |
| 15 | + * In test cases, not derived from TestCase. |
| 16 | + * In fake and mock classes. |
| 17 | + * In implementations as rich alternative to the assert statement. |
24 | 18 | * PEP 8 compliance. |
25 | 19 | * Custom stand-alone assertions can be written easily. |
26 | 20 | * Arguably a better separation of concerns, since TestCase is responsible |
27 | 21 | for test running only, if assertion functions are used exclusively. |
28 | 22 |
|
29 | 23 | There are a few regressions compared to assertions from TestCase: |
30 | 24 |
|
31 | | -* The default assertion class (AssertionError) can not be overwritten. This |
| 25 | +* The default assertion class (`AssertionError`) can not be overwritten. This |
32 | 26 | is rarely a problem in practice. |
33 | | -* asserts does not support the addTypeEqualityFunc() functionality. |
| 27 | +* asserts does not support the `addTypeEqualityFunc()` functionality. |
34 | 28 |
|
35 | 29 | Usage: |
36 | 30 |
|
| 31 | +```python |
37 | 32 | >>> from asserts import assert_true, assert_equal, assert_raises |
38 | 33 | >>> my_var = 13 |
39 | 34 | >>> assert_equal(13, my_var) |
40 | 35 | >>> assert_true(True, msg="custom failure message") |
41 | 36 | >>> with assert_raises(KeyError): |
42 | 37 | ... raise KeyError() |
| 38 | +``` |
43 | 39 |
|
44 | 40 | Failure messages can be customized: |
45 | 41 |
|
| 42 | +```python |
46 | 43 | >>> assert_equal(13, 14, msg_fmt="{got} is wrong, expected {expected}") |
47 | 44 | Traceback (most recent call last): |
48 | 45 | ... |
49 | 46 | AssertionError: 14 is wrong, expected 13 |
| 47 | +``` |
0 commit comments