|
@@ 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 |
|
def test_str_cannot_be_interpreted_as_int(self): |
| 1474 |
|
"""Forget to convert str to int.""" |
| 1475 |
|
before, after = before_and_after((3, 0)) |
| 1476 |
|
suggs = ["'int(str)'", "'len(str)'"] |
| 1477 |
|
for code in self.RANGE_CODE_TEMPLATES: |
| 1478 |
|
bad_code, good_code = format_str(code, '"12"', 'int("12")') |
| 1479 |
|
self.runs(good_code) |
| 1480 |
|
self.throws(bad_code, INTEXPECTED, suggs, before) |
| 1481 |
|
self.throws(bad_code, CANNOTBEINTERPRETED, suggs, after) |
| 1482 |
|
|
| 1483 |
|
def test_float_cannot_be_interpreted_as_int(self): |
| 1484 |
|
"""Use float instead of int.""" |
| 1485 |
|
v27 = (2, 7) |
| 1486 |
|
v3 = (3, 0) |
| 1487 |
|
sugg = ["'int(float)'"] |
| 1488 |
|
suggs = ["'int(float)'", "'math.ceil(float)'", "'math.floor(float)'"] |
| 1489 |
|
for code in self.RANGE_CODE_TEMPLATES: |
| 1490 |
|
full_code = 'import math\n' + code |
| 1491 |
|
good1, good2, bad = format_str( |
| 1492 |
|
full_code, 'int(12.0)', 'math.floor(12.0)', '12.0') |
| 1493 |
|
self.runs(good1) |
| 1494 |
|
self.runs(good2, up_to_version(v27)) |
| 1495 |
|
# floor returns a float before Python 3 -_- |
| 1496 |
|
self.throws(good2, INTEXPECTED, sugg, (v27, v3)) |