def test_remove_misplaced_type_comments_bytes(self) -> None: original = b""" \xbf def f(x): # type: (int) -> int def g(x): # type: (int) -> int pass def h(): # type: int pass x = 1 # type: int """ dest = b""" \xbf def f(x): # type: (int) -> int def g(x): # type: (int) -> int pass def h(): pass x = 1 # type: int """ assert_equal(remove_misplaced_type_comments(original), dest)
def test_remove_misplaced_type_comments_4(self) -> None: bad = """ def f(x): '''docstring''' # type: (int) -> int pass def g(x): '''docstring ''' # type: (int) -> int pass """ bad_fixed = """ def f(x): '''docstring''' pass def g(x): '''docstring ''' pass """ assert_equal(remove_misplaced_type_comments(bad), bad_fixed)
def test_remove_misplaced_type_comments_3(self) -> None: bad = ''' def f(x): """docstring""" # type: (int) -> int pass def g(x): """docstring """ # type: (int) -> int pass ''' bad_fixed = ''' def f(x): """docstring""" pass def g(x): """docstring """ pass ''' assert_equal(remove_misplaced_type_comments(bad), bad_fixed)
def test_remove_misplaced_type_comments_1(self) -> None: good = """ \u1234 def f(x): # type: (int) -> int def g(x): # type: (int) -> int def h(): # type: () int x = 1 # type: int """ assert_equal(remove_misplaced_type_comments(good), good)
def test_remove_misplaced_type_comments_5(self) -> None: bad = """ def f(x): # type: (int, List[Any], # float, bool) -> int pass def g(x): # type: (int, List[Any]) pass """ bad_fixed = """ def f(x): # float, bool) -> int pass def g(x): pass """ assert_equal(remove_misplaced_type_comments(bad), bad_fixed)
def test_remove_misplaced_type_comments_2(self) -> None: bad = """ def f(x): # type: Callable[[int], int] pass # type: "foo" # type: 'bar' x = 1 # type: int """ bad_fixed = """ def f(x): pass x = 1 """ assert_equal(remove_misplaced_type_comments(bad), bad_fixed)