@@ -49,6 +49,78 @@ def do_something(pos_param0, pos_param1, kw_param0="default"):
49
49
assert str (function ) == 'in public function `do_something`'
50
50
51
51
52
+ def test_simple_fstring ():
53
+ """Test parsing of a function with a simple fstring as a docstring."""
54
+ # fstrings are not supported in Python 3.5
55
+ if sys .version_info [0 :2 ] == (3 , 5 ):
56
+ return
57
+
58
+ parser = Parser ()
59
+ code = CodeSnippet ("""\
60
+ def do_something(pos_param0, pos_param1, kw_param0="default"):
61
+ f\" ""Do something.\" ""
62
+ return None
63
+ """ )
64
+ module = parser .parse (code , 'file_path' )
65
+ assert module .is_public
66
+ assert module .dunder_all is None
67
+
68
+ function , = module .children
69
+ assert function .name == 'do_something'
70
+ assert function .decorators == []
71
+ assert function .children == []
72
+ assert function .docstring == 'f"""Do something."""'
73
+ assert function .docstring .start == 2
74
+ assert function .docstring .end == 2
75
+ assert function .kind == 'function'
76
+ assert function .parent == module
77
+ assert function .start == 1
78
+ assert function .end == 3
79
+ assert function .error_lineno == 2
80
+ assert function .source == code .getvalue ()
81
+ assert function .is_public
82
+ assert str (function ) == 'in public function `do_something`'
83
+
84
+
85
+ def test_fstring_with_args ():
86
+ """Test parsing of a function with an fstring with args as a docstring."""
87
+ # fstrings are not supported in Python 3.5
88
+ if sys .version_info [0 :2 ] == (3 , 5 ):
89
+ return
90
+
91
+ parser = Parser ()
92
+ code = CodeSnippet ("""\
93
+ foo = "bar"
94
+ bar = "baz"
95
+ def do_something(pos_param0, pos_param1, kw_param0="default"):
96
+ f\" ""Do some {foo} and some {bar}.\" ""
97
+ return None
98
+ """ )
99
+ module = parser .parse (code , 'file_path' )
100
+ assert module .is_public
101
+ assert module .dunder_all is None
102
+
103
+ function , = module .children
104
+ assert function .name == 'do_something'
105
+ assert function .decorators == []
106
+ assert function .children == []
107
+ assert function .docstring == 'f"""Do some {foo} and some {bar}."""'
108
+ assert function .docstring .start == 4
109
+ assert function .docstring .end == 4
110
+ assert function .kind == 'function'
111
+ assert function .parent == module
112
+ assert function .start == 3
113
+ assert function .end == 5
114
+ assert function .error_lineno == 4
115
+ assert function .source == textwrap .dedent ("""\
116
+ def do_something(pos_param0, pos_param1, kw_param0="default"):
117
+ f\" ""Do some {foo} and some {bar}.\" ""
118
+ return None
119
+ """ )
120
+ assert function .is_public
121
+ assert str (function ) == 'in public function `do_something`'
122
+
123
+
52
124
def test_decorated_function ():
53
125
"""Test parsing of a simple function with a decorator."""
54
126
parser = Parser ()
0 commit comments