Skip to content

Commit 0cecc69

Browse files
author
Justin Black
committed
Adds test of profiled function's name and docstring
1 parent ee2188d commit 0cecc69

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ PYTHON ?= python
55
test:
66
$(PYTHON) -m memory_profiler test/test_func.py
77
$(PYTHON) -m memory_profiler test/test_loop.py
8+
$(PYTHON) -m memory_profiler test/test_mprofile.py
89
$(PYTHON) -m memory_profiler test/test_as.py
910
$(PYTHON) -m memory_profiler test/test_global.py
1011
$(PYTHON) -m memory_profiler test/test_precision_command_line.py

test/test_mprofile.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
@profile
66
def test1(l):
7+
"""test1 docstring"""
78
a = [1] * l
89
time.sleep(1)
910
return a
@@ -14,8 +15,22 @@ def test2(l):
1415
time.sleep(1)
1516
return b
1617

18+
def test3(l):
19+
"""test3 docstring"""
20+
return l
21+
1722
if __name__ == "__main__":
1823
l = 100000
1924
test1(l)
2025
test2(2 * l)
2126

27+
# make sure that the function name and docstring are set
28+
# by functools.wraps
29+
# memory_profile.py def profile func is not None case
30+
assert (test1.__name__ == 'test1'), 'function name is incorrect'
31+
assert (test1.__doc__ == 'test1 docstring'), 'function docstring is incorrect'
32+
# memory_profile.py def profile func is None case
33+
profile_maker = profile()
34+
profiled_test3 = profile_maker(test3)
35+
assert (profiled_test3.__name__ == 'test3'), 'function name is incorrect'
36+
assert (profiled_test3.__doc__ == 'test3 docstring'), 'function docstring is incorrect'

0 commit comments

Comments
 (0)