@@ 1043-1065 (lines=23) @@ | ||
1040 | code_str, code_string = format_str(code, 'str', 'string') |
|
1041 | code_str2 = 'str.maketrans' # No 'string' import |
|
1042 | code_str3 = 'import string as my_string\nstr.maketrans' # Named import |
|
1043 | self.throws(code_str, ATTRIBUTEERROR, [], up_to_version(version1)) |
|
1044 | self.throws(code_str2, ATTRIBUTEERROR, [], up_to_version(version1)) |
|
1045 | self.throws(code_str3, ATTRIBUTEERROR, [], up_to_version(version1)) |
|
1046 | self.runs(code_string, up_to_version(version1)) |
|
1047 | self.throws(code_string, ATTRIBUTEERROR, [], (version1, version2)) |
|
1048 | self.throws(code_string, MODATTRIBUTEERROR, [], from_version(version2)) |
|
1049 | self.runs(code_str, from_version(version1)) |
|
1050 | self.runs(code_str2, from_version(version1)) |
|
1051 | self.runs(code_str3, from_version(version1)) |
|
1052 | ||
1053 | def test_moved_between_imp_importlib(self): |
|
1054 | """Some methods have been moved from imp to importlib.""" |
|
1055 | # NICE_TO_HAVE |
|
1056 | # reload removed from Python 3 |
|
1057 | # importlib module new in Python 2.7 |
|
1058 | # importlib.reload new in Python 3.4 |
|
1059 | # imp.reload new in Python 3.2 |
|
1060 | version27 = (2, 7) |
|
1061 | version3 = (3, 0) |
|
1062 | version26 = up_to_version(version27) |
|
1063 | code = '{0}reload(math)' |
|
1064 | null, code_imp, code_importlib = format_str( |
|
1065 | code, '', 'import imp\nimp.', 'import importlib\nimportlib.') |
|
1066 | self.runs(null, up_to_version(version3)) |
|
1067 | self.throws(null, NAMEERROR, |
|
1068 | RELOAD_REMOVED_MSG, from_version(version3)) |
|
@@ 1476-1493 (lines=18) @@ | ||
1473 | INDEX_CODE_TEMPLATES = ['[1, 2, 3][{0}]', '(1, 2, 3)[{0}]'] |
|
1474 | ||
1475 | def test_str_cannot_be_interpreted_as_int(self): |
|
1476 | """Forget to convert str to int.""" |
|
1477 | v3 = (3, 0) |
|
1478 | suggs = ["'int(str)'", "'len(str)'"] |
|
1479 | for code in self.RANGE_CODE_TEMPLATES: |
|
1480 | bad_code, good_code = format_str(code, '"12"', 'int("12")') |
|
1481 | self.runs(good_code) |
|
1482 | self.throws(bad_code, INTEXPECTED, suggs, up_to_version(v3)) |
|
1483 | self.throws(bad_code, CANNOTBEINTERPRETED, suggs, from_version(v3)) |
|
1484 | ||
1485 | def test_float_cannot_be_interpreted_as_int(self): |
|
1486 | """Use float instead of int.""" |
|
1487 | v27 = (2, 7) |
|
1488 | v3 = (3, 0) |
|
1489 | sugg = ["'int(float)'"] |
|
1490 | suggs = ["'int(float)'", "'math.ceil(float)'", "'math.floor(float)'"] |
|
1491 | for code in self.RANGE_CODE_TEMPLATES: |
|
1492 | full_code = 'import math\n' + code |
|
1493 | good1, good2, bad = format_str( |
|
1494 | full_code, 'int(12.0)', 'math.floor(12.0)', '12.0') |
|
1495 | self.runs(good1) |
|
1496 | self.runs(good2, up_to_version(v27)) |