Skip to content

Commit

Permalink
add tests for occurrences in f-string
Browse files Browse the repository at this point in the history
  • Loading branch information
lieryan committed Mar 5, 2024
1 parent 85fd303 commit 3d2cc6d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ropetest/refactor/renametest.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,28 @@ def test_renaming_occurrence_in_nested_f_string(self):
refactored = self._local_rename(code, 2, "new_var")
self.assertEqual(expected, refactored)

def test_renaming_attribute_occurrences_in_f_string(self):
code = dedent("""\
class MyClass:
def __init__(self):
self.abc = 123
def func(obj):
print(f'{obj.abc}')
return obj.abc
""")
expected = dedent("""\
class MyClass:
def __init__(self):
self.new_var = 123
def func(obj):
print(f'{obj.new_var}')
return obj.new_var
""")
refactored = self._local_rename(code, code.index('abc'), "new_var")
self.assertEqual(expected, refactored)

def test_not_renaming_string_contents_in_f_string(self):
refactored = self._local_rename(
"a_var = 20\na_string=f'{\"a_var\"}'\n", 2, "new_var"
Expand Down

0 comments on commit 3d2cc6d

Please sign in to comment.