Skip to content

Commit 480a7ff

Browse files
author
Sylvain MARIE
committed
Added test for stack overflow post
1 parent 9396e54 commit 480a7ff

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

mini_lambda/tests/test_so.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from __future__ import print_function
2+
3+
4+
def test_so1(capsys):
5+
"""Test for the solution at https://stackoverflow.com/a/55760092/7262247"""
6+
with capsys.disabled():
7+
8+
# your source code util
9+
10+
from mini_lambda import x, is_mini_lambda_expr
11+
import inspect
12+
13+
def get_source_code_str(f):
14+
if is_mini_lambda_expr(f):
15+
return f.to_string()
16+
else:
17+
return inspect.getsource(f)
18+
19+
# test it
20+
21+
def foo(arg1, arg2):
22+
# do something with args
23+
a = arg1 + arg2
24+
return a
25+
26+
print()
27+
print(get_source_code_str(foo))
28+
print(get_source_code_str(x ** 2))
29+
30+
captured = capsys.readouterr()
31+
32+
with capsys.disabled():
33+
print(captured.out)
34+
35+
assert captured.out == """
36+
def foo(arg1, arg2):
37+
# do something with args
38+
a = arg1 + arg2
39+
return a
40+
41+
x ** 2
42+
"""

0 commit comments

Comments
 (0)