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.8 and higher
  • Loading branch information
lieryan committed Oct 10, 2021
1 parent 8f3c225 commit 31d6bc4
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions ropetest/refactor/extracttest.py
Expand Up @@ -2954,37 +2954,40 @@ def extracted():
""")
self.assertEqual(expected, refactored)

@testutils.only_for_versions_higher('3.5')
def test_extract_method_async_with_simple(self):
code = dedent("""\
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):
@testutils.only_for_versions_higher('3.8')
def test_extract_method_containing_async_with(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 31d6bc4

Please sign in to comment.