rope
rope copied to clipboard
The Inline Method refactoring removed an import
The Inline Method refactoring removed an import from the test file, causing an error when the test file is run.
Steps to reproduce the behavior:
- Code before refactoring:
-- mixins.py
from __future__ import unicode_literals
class StringlikeMixin(object):
def __init__(self, text):
self._text = text
def _strkey(self):
return self._text
def find(self, sub, start=0, end=None):
if end is None:
end = len(self._strkey())
return self._strkey().find(sub, start, end)
-- test_mixins.py
from __future__ import unicode_literals, absolute_import
from nose.tools import *
from mixins import StringlikeMixin
def test_find():
text = 'Beautiful is better than ugly.'
blob = StringlikeMixin(text)
assert_equal(
blob.find('better', 5, len(blob._strkey())),
text.find('better', 5, len(text))
)
-
Apply the inline method to
StringlikeMixin.find -
Code after refactoring:
-- mixins.py
from __future__ import unicode_literals
class StringlikeMixin(object):
def __init__(self, text):
self._text = text
def _strkey(self):
return self._text
-- test_mixins.py
from __future__ import unicode_literals, absolute_import
from mixins import StringlikeMixin
def test_find():
text = 'Beautiful is better than ugly.'
blob = StringlikeMixin(text)
assert_equal(
blob._strkey().find('better', 5, len(blob._strkey())),
text.find('better', 5, len(text))
)