Skip to content

Commit 9d4be8e

Browse files
Update README.md
1 parent 78170f5 commit 9d4be8e

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed

README.md

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,75 @@
44
![Python versions](https://img.shields.io/badge/python-3.5,%203.6%2C%203.7%2C%203.8-blue?logo=python)
55
![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)
66

7-
A simple API for unit testing a Python project's performances :zap::wheelchair:.
7+
A simple and lightweight API for unit testing a Python 🐍 project's performances :zap::wheelchair:.
8+
9+
From **Python 3.5 to 3.8**, easily improve your project's performances tests through the use of dedicated **decorators**.
10+
11+
### Table of contents
12+
13+
- [Memory testing](#Memory-testing)
14+
- [Memory overload assertions](#Memory-overload-assertions)
15+
- [Memory leaks assertions](#Memory-leaks-assertions)
16+
17+
### Memory testing
18+
19+
#### Memory overload assertions
20+
21+
The memory overload assertions are possible thanks to the `@memory_not_exceed` decorator.
22+
23+
A simple *TestCase* associated to this decorator does the job :
24+
25+
```python
26+
class TestLimitMemoryUsage(unittest.TestCase):
27+
"""
28+
This class illustrates the use of the memory_not_exceed decorator.
29+
"""
30+
@memory_not_exceed(threshold=0)
31+
def test_memory_usage_exceed(self):
32+
"""
33+
This test won't pass due to a very low threshold.
34+
"""
35+
return list(range(1000)) * 1
36+
37+
@memory_not_exceed(threshold=1000)
38+
def test_memory_usage_not_exceed(self):
39+
"""
40+
This test passes due to a very high threshold.
41+
"""
42+
return list(range(1000)) * 1
43+
```
44+
45+
#### Memory leaks assertions
46+
47+
The memory leaks assertions are possible thanks to the `@memory_not_leak` decorator.
48+
49+
Once again, a simple *TestCase* associated to this decorator does the job :
50+
51+
```python
52+
class TetsMemoryLeaksDetection(unittest.TestCase):
53+
"""
54+
This class illustrates the use of the memory_not_leak decorator.
55+
"""
56+
leaking_list = []
57+
58+
def leak(self):
59+
"""
60+
Generates a memory leak involving the leaking_list.
61+
"""
62+
self.leaking_list.append("will leak")
63+
64+
@memory_not_leak()
65+
def test_memory_leaks(self):
66+
"""
67+
This test won't pass due to a memory leak.
68+
"""
69+
self.leak()
70+
71+
@memory_not_leak()
72+
def test_memory_not_leak(self):
73+
"""
74+
This test passes due to the absence of memory leak.
75+
"""
76+
valid_list = []
77+
valid_list.append("won't leak")
78+
```

0 commit comments

Comments
 (0)