Skip to content

The Inline Method refactoring removed an import #826

@jonh-copin

Description

@jonh-copin

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:

  1. 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))
    )
  1. Apply the inline method to StringlikeMixin.find

  2. 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))
    )

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUnexpected or incorrect user-visible behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions