Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def assertReapplyVisible(
self, pyi_txt, src_txt, expected_txt, *, incremental=False, replace_any=False
):
flags = ReApplyFlags(replace_any=replace_any, incremental=incremental)
pyi = ast3.parse(dedent(pyi_txt))
src = lib2to3_parse(dedent(src_txt))
expected = lib2to3_parse(dedent(expected_txt))
assert isinstance(pyi, ast3.Module)
reapply_all(pyi.body, src, flags)
fix_remaining_type_comments(src, flags)
self.longMessage = False
self.assertEqual(
str(expected), str(src), f"\n{str(expected)!r} != \n{str(src)!r}"
)
def assertReapplyRaises(
self,
pyi_txt,
src_txt,
expected_exception,
*,
incremental=False,
replace_any=False,
):
flags = ReApplyFlags(replace_any=replace_any, incremental=incremental)
with self.assertRaises(expected_exception) as ctx:
pyi = ast3.parse(dedent(pyi_txt))
src = lib2to3_parse(dedent(src_txt))
assert isinstance(pyi, ast3.Module)
reapply_all(pyi.body, src, flags)
fix_remaining_type_comments(src, flags)
return ctx.exception
def assertReapply(
self, pyi_txt, src_txt, expected_txt, *, incremental=False, replace_any=False
):
pyi = ast3.parse(dedent(pyi_txt))
src = lib2to3_parse(dedent(src_txt))
expected = lib2to3_parse(dedent(expected_txt))
assert isinstance(pyi, ast3.Module)
flags = ReApplyFlags(replace_any=replace_any, incremental=incremental)
reapply_all(pyi.body, src, flags)
fix_remaining_type_comments(src, flags)
self.longMessage = False
self.assertEqual(expected, src, f"\n{expected!r} != \n{src!r}")