Skip to content

Commit d46125c

Browse files
committed
Update documentation structure
1 parent 84cde6a commit d46125c

File tree

4 files changed

+139
-2
lines changed

4 files changed

+139
-2
lines changed

docs/api_reference.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
`unittest_extensions.TestCase` extends `unittest.TestCase` with the below methods.
2+
3+
**assertResult(self, value)**
4+
Fail if the result is unequal to the value as determined by the '==' operator.
5+
Equivalent to `assertEqual(self.result(), value)`.
6+
7+
**assertResultAlmost(self, value, places=None, delta=None)**
8+
Fail if the result is unequal to the value as determined by their difference rounded
9+
to the given number of decimal places (default 7) and comparing to zero, or by
10+
comparing that the difference between the two objects is more than the given delta.
11+
Equivalent to `assertAlmostEqual(self.result(), value, places, delta=delta)`.
12+
13+
**assertResultCount(self, iterable)**
14+
Assert that the result has the same elements as the iterable without regard to order.
15+
Equivalent to `assertCountEqual(self.result(), iterable)`.
16+
17+
**assertResultDict(self, dct)**
18+
Assert that the result is equal to dct.
19+
Equivalent to `assertDictEqual(self.result(), dct)`.
20+
21+
**assertResultFalse(self)**
22+
Check that the result is false.
23+
Equivalent to `assertFalse(self.result())`.
24+
25+
**assertResultGreater(self, value)**
26+
Just like self.assertTrue(self.result() > value), but with a nicer default message.
27+
Equivalent to `assertGreater(self, result(), value)`.
28+
29+
**assertResultGreaterEqual(self, value)**
30+
Just like self.assertTrue(self.result() >= value), but with a nicer default message.
31+
Equivalent to `assertGreaterEqual(self.result(), value)`.
32+
33+
**assertResultIn(self, container)**
34+
Just like self.assertTrue(self.result() in container), but with a nicer default message.
35+
Equivalent to `assertIn(self.result(), container)`.
36+
37+
**assertResultIs(self, value)**
38+
Just like self.assertTrue(self.result() is value), but with a nicer default message.
39+
Equivalent to `assertIs(self.result(), value)`.
40+
41+
**assertResultIsInstance(self, cls)**
42+
Just like self.assertTrue(self.result() in container), but with a nicer default message.
43+
Equivalent to `assertIsInstance(self.result(), cls)`.
44+
45+
**assertResultIsNot(self, value)**
46+
Just like self.assertTrue(self.result() is not value), but with a nicer default message.
47+
Equivalent to `assertIsNot(self.result(), value)`.
48+
49+
**assertResultIsNotInstance(self, cls)**
50+
Just like self.assertTrue(self.result() not in container), but with a nicer default message.
51+
Equivalent to `assertNotIsInstance(self.result(), cls)`.
52+
53+
**assertResultLess(self, value)**
54+
Just like self.assertTrue(self.result() < value), but with a nicer default message.
55+
Equivalent to `assertLess(self.result(), value)`.
56+
57+
**assertResultLessEqual(self, value)**
58+
Just like self.assertTrue(self.result() <= value), but with a nicer default message.
59+
Equivalent to `assertLessEqual(self.result(), value)`.
60+
61+
**assertResultList(self, lst)**
62+
Assert that the result is equal to lst.
63+
Equivalent to `assertListEqual(self.result(), lst)`.
64+
65+
**assertResultNot(self, value)**
66+
Fail if the result is equal to the value as determined by the '==' operator.
67+
Equivalent to `assertNotEqual(self.result(), value)`.
68+
69+
**assertResultNotAlmost(self, value, places=None, delta=None)**
70+
Fail if the result is equal to the value as determined by their difference rounded
71+
to the given number of decimal places (default 7) and comparing to zero, or by
72+
comparing that the difference between the two objects is less than the given delta.
73+
Equivalent to `assertNotAlmostEqual(self.result(), value)`.
74+
75+
**assertResultNotIn(self, container)**
76+
Just like self.assertTrue(self.result() not in container), but with a nicer default message.
77+
Equivalent to `assertNotIn(self.result(), container)`.
78+
79+
**assertResultNotRegex(self, unexpected_regex)**
80+
Fail the test if the result matches the regular expression.
81+
Equivalent to `assertNotRegex(self.result(), unexpected_regex)`.
82+
83+
**assertResultRaises(self, expected_exception)**
84+
Fail unless an exception of class expected_exception is raised by the result. If
85+
a different type of exception is raised, it will not be caught, and the test case
86+
will be deemed to have suffered an error, exactly as for an unexpected exception.
87+
Equivalent to
88+
```py
89+
with self.assertRaises(expected_exception):
90+
self.result()
91+
```
92+
93+
**assertResultRaisesRegex(self, expected_exception, expected_regex)**
94+
Fail unless an exception of class expected_exception is raised by the result and the message matches the regex.
95+
Equivalent to
96+
```py
97+
with self.assertRaisesRegex(expected_exception, expected_regex):
98+
self.result()
99+
```
100+
101+
**assertResultRegex(self, expected_regex)**
102+
Fail the test unless the result matches the regular expression.
103+
Equivalent to `self.assertRegex(self.result(), expected_regex)`.
104+
105+
**assertResultSet(self, st)**
106+
Assert that the result is equal to st.
107+
Equivalent to `self.assertSetEqual(self.result(), st)`.
108+
109+
**assertResultTrue(self)**
110+
Check that the result is true.
111+
Equivalent to `self.assertTrue(self.result())`.
112+
113+
**assertResultTuple(self, tpl)**
114+
Assert that the result is equal to tpl.
115+
Equivalent to `self.assertTupleEqual(self.result(), tpl)`.
116+
117+
**cachedResult(self) -> Any**
118+
Return the result of the last `subject` call. Use this function when you want to
119+
assert different attributes of your subject without executing it multiple times.
120+
121+
Raises `unittest_extensions.TestError` if subject has not been called.
122+
123+
**result(self) -> Any**
124+
Result of the `subject` called with arguments defined by the `args` decorator.

docs/examples.md

Whitespace-only changes.

docs/index.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
# unittest-extensions
22

3-
Short description similar to repo readme.
3+
Extension of Python's standard unittest library.
4+
5+
This minimal library aims to simplify behavioural testing with Python's standard
6+
[`unittest`](https://docs.python.org/3/library/unittest.html) library by separating
7+
object and data creation from behaviour assertion. Furthermore, it is intended to serve users that want to write really small test functions where what is being asserted is quickly comprehended and easily visible.
8+
9+
`unittest-extensions` does not have any dependencies, it is solely based on the
10+
Python standard library.
11+
12+
### Usage
13+
In order to make use of `unittest-extensions`' methods, each `TestCase` must define
14+
a `subject` method. The subject is what you would like to assert in each case.
15+
Moreover, each test method should be decorated with the `args` decorator, whereby the arguments
16+
to your `subject` method are defined. Then, you can use the `assertResult*` methods ([API Reference](api_reference.md))
17+
to assert your subject.

mkdocs.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ site_name: unittest-extensions Documentation
22
site_url: https://maxcode123.github.io/unittest-extensions/
33
nav:
44
- Home: index.md
5-
- Examples: examples.md
65
- API Reference: api_reference.md
76
theme: readthedocs

0 commit comments

Comments
 (0)