Skip to content

Commit

Permalink
Refactor move tests to RenameRefactoringWithSuperclassTest
Browse files Browse the repository at this point in the history
  • Loading branch information
lieryan committed Feb 27, 2024
1 parent 0b3672b commit aa02352
Showing 1 changed file with 89 additions and 85 deletions.
174 changes: 89 additions & 85 deletions ropetest/refactor/renametest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ropetest import testutils


class RenameRefactoringTest(unittest.TestCase):
class RenameTestMixin:
def setUp(self):
super().setUp()
self.project = testutils.sample_project()
Expand All @@ -31,6 +31,8 @@ def _rename(self, resource, offset, new_name, **kwds):
changes = Rename(self.project, resource, offset).get_changes(new_name, **kwds)
self.project.do(changes)


class RenameRefactoringTest(RenameTestMixin, unittest.TestCase):
def test_local_variable_but_not_parameter(self):
code = dedent("""\
a = 10
Expand Down Expand Up @@ -726,90 +728,6 @@ def __init__(self):
mod2.read(),
)

def test_renaming_methods_in_subclasses(self):
mod = testutils.create_module(self.project, "mod1")
mod.write(dedent("""\
class A(object):
def a_method(self):
pass
class B(A):
def a_method(self):
pass
"""))

self._rename(
mod, mod.read().rindex("a_method") + 1, "new_method", in_hierarchy=True
)
self.assertEqual(
dedent("""\
class A(object):
def new_method(self):
pass
class B(A):
def new_method(self):
pass
"""),
mod.read(),
)

def test_renaming_methods_in_sibling_classes(self):
mod = testutils.create_module(self.project, "mod1")
mod.write(dedent("""\
class A(object):
def a_method(self):
pass
class B(A):
def a_method(self):
pass
class C(A):
def a_method(self):
pass
"""))

self._rename(
mod, mod.read().rindex("a_method") + 1, "new_method", in_hierarchy=True
)
self.assertEqual(
dedent("""\
class A(object):
def new_method(self):
pass
class B(A):
def new_method(self):
pass
class C(A):
def new_method(self):
pass
"""),
mod.read(),
)

def test_not_renaming_methods_in_hierarchies(self):
mod = testutils.create_module(self.project, "mod1")
mod.write(dedent("""\
class A(object):
def a_method(self):
pass
class B(A):
def a_method(self):
pass
"""))

self._rename(
mod, mod.read().rindex("a_method") + 1, "new_method", in_hierarchy=False
)
self.assertEqual(
dedent("""\
class A(object):
def a_method(self):
pass
class B(A):
def new_method(self):
pass
"""),
mod.read(),
)

def test_undoing_refactorings(self):
mod1 = testutils.create_module(self.project, "mod1")
mod1.write(dedent("""\
Expand Down Expand Up @@ -1473,6 +1391,92 @@ def test_renaming_modules_aliased_many_dots(self):
self.assertEqual("import new_json.utils.a as stdlib_json_utils\n", mod2.read())


class RenameRefactoringWithSuperclassTest(RenameTestMixin, unittest.TestCase):
def test_renaming_methods_in_subclasses(self):
mod = testutils.create_module(self.project, "mod1")
mod.write(dedent("""\
class A(object):
def a_method(self):
pass
class B(A):
def a_method(self):
pass
"""))

self._rename(
mod, mod.read().rindex("a_method") + 1, "new_method", in_hierarchy=True
)
self.assertEqual(
dedent("""\
class A(object):
def new_method(self):
pass
class B(A):
def new_method(self):
pass
"""),
mod.read(),
)

def test_renaming_methods_in_sibling_classes(self):
mod = testutils.create_module(self.project, "mod1")
mod.write(dedent("""\
class A(object):
def a_method(self):
pass
class B(A):
def a_method(self):
pass
class C(A):
def a_method(self):
pass
"""))

self._rename(
mod, mod.read().rindex("a_method") + 1, "new_method", in_hierarchy=True
)
self.assertEqual(
dedent("""\
class A(object):
def new_method(self):
pass
class B(A):
def new_method(self):
pass
class C(A):
def new_method(self):
pass
"""),
mod.read(),
)

def test_not_renaming_methods_in_hierarchies(self):
mod = testutils.create_module(self.project, "mod1")
mod.write(dedent("""\
class A(object):
def a_method(self):
pass
class B(A):
def a_method(self):
pass
"""))

self._rename(
mod, mod.read().rindex("a_method") + 1, "new_method", in_hierarchy=False
)
self.assertEqual(
dedent("""\
class A(object):
def a_method(self):
pass
class B(A):
def new_method(self):
pass
"""),
mod.read(),
)


class ChangeOccurrencesTest(unittest.TestCase):
def setUp(self):
self.project = testutils.sample_project()
Expand Down

0 comments on commit aa02352

Please sign in to comment.