-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
29 lines (18 loc) · 657 Bytes
/
test.py
File metadata and controls
29 lines (18 loc) · 657 Bytes
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
import unittest
import numpy as np
from py_limit_memory import limit_memory
class Test(unittest.TestCase):
def test(self):
"""check if decorator works only for the function it decorates"""
size_in_bytes = 2 * 1024**3 # 2 GB in bytes
dtype_size = np.dtype(np.float64).itemsize
num_elements = size_in_bytes // dtype_size
@limit_memory("1GB")
def f1():
array = np.empty(num_elements, dtype=np.float64)
def f2():
array = np.empty(num_elements, dtype=np.float64)
f2()
self.assertRaises(MemoryError, f1)
if __name__ == "__main__":
unittest.main()