Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Added simple fstring parsing testcase (#425)
Browse files Browse the repository at this point in the history
* Added simple fstring parsing testcase

* Added test case for fstring with args
  • Loading branch information
yoseft authored and Nurdok committed Oct 25, 2019
1 parent 145daec commit 8bfbf34
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/tests/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,78 @@ def do_something(pos_param0, pos_param1, kw_param0="default"):
assert str(function) == 'in public function `do_something`'


def test_simple_fstring():
"""Test parsing of a function with a simple fstring as a docstring."""
# fstrings are not supported in Python 3.5
if sys.version_info[0:2] == (3, 5):
return

parser = Parser()
code = CodeSnippet("""\
def do_something(pos_param0, pos_param1, kw_param0="default"):
f\"""Do something.\"""
return None
""")
module = parser.parse(code, 'file_path')
assert module.is_public
assert module.dunder_all is None

function, = module.children
assert function.name == 'do_something'
assert function.decorators == []
assert function.children == []
assert function.docstring == 'f"""Do something."""'
assert function.docstring.start == 2
assert function.docstring.end == 2
assert function.kind == 'function'
assert function.parent == module
assert function.start == 1
assert function.end == 3
assert function.error_lineno == 2
assert function.source == code.getvalue()
assert function.is_public
assert str(function) == 'in public function `do_something`'


def test_fstring_with_args():
"""Test parsing of a function with an fstring with args as a docstring."""
# fstrings are not supported in Python 3.5
if sys.version_info[0:2] == (3, 5):
return

parser = Parser()
code = CodeSnippet("""\
foo = "bar"
bar = "baz"
def do_something(pos_param0, pos_param1, kw_param0="default"):
f\"""Do some {foo} and some {bar}.\"""
return None
""")
module = parser.parse(code, 'file_path')
assert module.is_public
assert module.dunder_all is None

function, = module.children
assert function.name == 'do_something'
assert function.decorators == []
assert function.children == []
assert function.docstring == 'f"""Do some {foo} and some {bar}."""'
assert function.docstring.start == 4
assert function.docstring.end == 4
assert function.kind == 'function'
assert function.parent == module
assert function.start == 3
assert function.end == 5
assert function.error_lineno == 4
assert function.source == textwrap.dedent("""\
def do_something(pos_param0, pos_param1, kw_param0="default"):
f\"""Do some {foo} and some {bar}.\"""
return None
""")
assert function.is_public
assert str(function) == 'in public function `do_something`'


def test_decorated_function():
"""Test parsing of a simple function with a decorator."""
parser = Parser()
Expand Down

0 comments on commit 8bfbf34

Please sign in to comment.