Skip to content

Commit

Permalink
Wrap async with test in async def
Browse files Browse the repository at this point in the history
Bare `async with` only works in 3.7 and higher
  • Loading branch information
lieryan committed Oct 10, 2021
1 parent 8f3c225 commit ad3f285
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions ropetest/refactor/extracttest.py
Expand Up @@ -2960,31 +2960,32 @@ async def afunc():
async with open("test") as file1:
print(file1)
""")
start, end = self._convert_line_range_to_offset(code, 3, 3)
start, end = self._convert_line_range_to_offset(code, 2, 3)
refactored = self.do_extract_method(code, start, end, 'extracted', global_=True)
expected = dedent("""\
async def afunc():
async with open("test") as file1:
extracted(file1)
extracted()
def extracted(file1):
print(file1)
def extracted():
async with open("test") as file1:
print(file1)
""")
self.assertEqual(expected, refactored)

def test_extract_method_async_with_double_with_as(self):
code = dedent("""\
async with open("test") as file1, open("test") as file2:
print(file1, file2)
async def afunc():
async with open("test") as file1, open("test") as file2:
print(file1, file2)
""")
start, end = self._convert_line_range_to_offset(code, 2, 3)
start, end = self._convert_line_range_to_offset(code, 3, 3)
refactored = self.do_extract_method(code, start, end, 'extracted', global_=True)
expected = dedent("""\
async def afunc():
async with open("test") as file1, open("test") as file2:
extracted(file1, file2)
def extracted(file1, file2):
print(file1, file2)
async with open("test") as file1, open("test") as file2:
extracted(file1, file2)
""")
self.assertEqual(expected, refactored)

0 comments on commit ad3f285

Please sign in to comment.