Replace 'unicode()' function with 'six.text_type'
'unicode' is absent in py3 Closes-Bug: #1470596 Change-Id: Iee127133603d98a7cbe1d14fa54c1203a950018e
This commit is contained in:
parent
3760f40ec1
commit
c1cc54fd85
@ -25,4 +25,5 @@ Rally Specific Commandments
|
||||
* [N341] - Ensure that we are importing oslo_xyz packages instead of deprecated oslo.xyz ones
|
||||
* [N350] - Ensure that single quotes are not used
|
||||
* [N351] - Ensure that data structs (i.e Lists and Dicts) are declared literally rather than using constructors
|
||||
* [N353] - Ensure that string formatting only uses a mapping if multiple mapping keys are used.
|
||||
* [N352] - Ensure that string formatting only uses a mapping if multiple mapping keys are used.
|
||||
* [N353] - Ensure that unicode() function is not uset because of absence in py3
|
||||
|
@ -427,6 +427,18 @@ def check_dict_formatting_in_string(logical_line, tokens):
|
||||
current_string = ""
|
||||
|
||||
|
||||
@skip_ignored_lines
|
||||
def check_using_unicode(logical_line, filename):
|
||||
"""Check crosspython unicode usage
|
||||
|
||||
N353
|
||||
"""
|
||||
|
||||
if re.search(r"\bunicode\(", logical_line):
|
||||
yield (0, "N353 'unicode' function is absent in python3. Please "
|
||||
"use 'six.text_type' instead.")
|
||||
|
||||
|
||||
def factory(register):
|
||||
register(check_assert_methods_from_mock)
|
||||
register(check_import_of_logging)
|
||||
@ -442,3 +454,4 @@ def factory(register):
|
||||
register(check_quotes)
|
||||
register(check_no_constructor_data_struct)
|
||||
register(check_dict_formatting_in_string)
|
||||
register(check_using_unicode)
|
||||
|
@ -306,3 +306,15 @@ class HackingTestCase(test.TestCase):
|
||||
self.assertEqual(
|
||||
[],
|
||||
list(checks.check_dict_formatting_in_string(sample, tokens)))
|
||||
|
||||
def test_check_using_unicode(self):
|
||||
|
||||
checkres = checks.check_using_unicode("text = unicode('sometext')",
|
||||
"fakefile")
|
||||
self.assertIsNotNone(next(checkres))
|
||||
self.assertEqual([], list(checkres))
|
||||
|
||||
checkres = checks.check_using_unicode(
|
||||
"text = process(unicode('sometext'))", "fakefile")
|
||||
self.assertIsNotNone(next(checkres))
|
||||
self.assertEqual([], list(checkres))
|
||||
|
Loading…
Reference in New Issue
Block a user