Make update_classpath() util function return non-string objects

This commit is contained in:
Jakob de Maeyer 2015-11-06 22:18:10 +01:00
parent d18b6a61d7
commit 9f7fcf5582
2 changed files with 7 additions and 0 deletions

View File

@ -1,5 +1,6 @@
"""Some helpers for deprecation messages"""
import six
import warnings
import inspect
from scrapy.exceptions import ScrapyDeprecationWarning
@ -149,6 +150,8 @@ DEPRECATION_RULES = [
def update_classpath(path):
"""Update a deprecated path from an object with its new location"""
if not isinstance(path, six.string_types):
return path
for prefix, replacement in DEPRECATION_RULES:
if path.startswith(prefix):
new_path = path.replace(prefix, replacement, 1)

View File

@ -279,3 +279,7 @@ class UpdateClassPathTest(unittest.TestCase):
output = update_classpath('scrapy.unmatched.Path')
self.assertEqual(output, 'scrapy.unmatched.Path')
self.assertEqual(len(w), 0)
def test_returns_nonstring(self):
for notastring in [None, True, [1, 2, 3], object()]:
self.assertEqual(update_classpath(notastring), notastring)