Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def assertNoMatch(self, input: str) -> None:
m = _type_comment_re.match(input)
self.assertIsNone(m)
def assertMatch(self, input: str, *, type: str, nl: str) -> None:
m = _type_comment_re.match(input)
self.assertIsNotNone(m)
if m is not None:
self.assertEqual(m.group("type"), type)
self.assertEqual(m.group("nl"), nl)
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}")
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 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 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}")
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 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}")