File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 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+ """
You can’t perform that action at this time.
0 commit comments