Skip to content

Commit

Permalink
Add slightly more detail to this test of f-strings on Python 3.12+
Browse files Browse the repository at this point in the history
This demonstrates what (little) information we do get about the
child nodes within the JoinedStr.
  • Loading branch information
PeterJCLaw committed Oct 29, 2023
1 parent 23f67f3 commit 1c42c83
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/test_mark_tokens.py
Expand Up @@ -342,6 +342,8 @@ def test_adjacent_joined_strings(self):

if sys.version_info >= (3, 12):
def test_fstrings_3_12_plus(self):
const = 'Const' if self.is_astroid_test else 'Constant'

m = self.create_mark_checker(
'x = (f"Wobble {f"{func(kwarg=f"{boo!r}")}"!r}.",)',
)
Expand All @@ -350,6 +352,19 @@ def test_fstrings_3_12_plus(self):
'JoinedStr:f"Wobble {f"{func(kwarg=f"{boo!r}")}"!r}."',
})

# Nodes within an f-string don't have tokens attached so we don't get
# their text ranges.
node, = m.get_nodes_at(1, 6)
self.assertEqual(
[
const + ':',
'FormattedValue:',
const + ':',
],
[m.view_node(x) for x in node.values],
"Wrong children within JoinedStr",
)

m.verify_all_nodes(self)

def test_bytes_smoke(self):
Expand Down

0 comments on commit 1c42c83

Please sign in to comment.