|
@@ 1301-1327 (lines=27) @@
|
| 1298 |
|
self.throws(bad_code, UNSUPPORTEDOPERAND) |
| 1299 |
|
self.runs(good_code) |
| 1300 |
|
|
| 1301 |
|
def test_no_implicit_str_conv2(self): |
| 1302 |
|
"""Trying to concatenate a non-string value to a string.""" |
| 1303 |
|
# NICE_TO_HAVE |
| 1304 |
|
code = '"things " + {0}' |
| 1305 |
|
typo, sugg = '12', 'str(12)' |
| 1306 |
|
bad_code, good_code = format_str(code, typo, sugg) |
| 1307 |
|
version = (3, 0) |
| 1308 |
|
version2 = (3, 6) |
| 1309 |
|
self.throws( |
| 1310 |
|
bad_code, CANNOTCONCAT, [], up_to_version(version), 'cython') |
| 1311 |
|
self.throws( |
| 1312 |
|
bad_code, CANTCONVERT, [], (version, version2), 'cython') |
| 1313 |
|
self.throws( |
| 1314 |
|
bad_code, MUSTBETYPENOTTYPE, [], from_version(version2), 'cython') |
| 1315 |
|
self.throws( |
| 1316 |
|
bad_code, UNSUPPORTEDOPERAND, [], ALL_VERSIONS, 'pypy') |
| 1317 |
|
self.runs(good_code) |
| 1318 |
|
|
| 1319 |
|
def test_assignment_to_range(self): |
| 1320 |
|
"""Trying to assign to range works on list, not on range.""" |
| 1321 |
|
code = '{0}[2] = 1' |
| 1322 |
|
typo, sugg = 'range(4)', 'list(range(4))' |
| 1323 |
|
version = (3, 0) |
| 1324 |
|
bad_code, good_code = format_str(code, typo, sugg) |
| 1325 |
|
self.runs(good_code) |
| 1326 |
|
self.runs(bad_code, up_to_version(version)) |
| 1327 |
|
self.throws( |
| 1328 |
|
bad_code, |
| 1329 |
|
OBJECTDOESNOTSUPPORT, |
| 1330 |
|
'convert to list to edit the list', |
|
@@ 897-911 (lines=15) @@
|
| 894 |
|
('func_globals', '__globals__', []), |
| 895 |
|
('func_code', '__code__', [])] |
| 896 |
|
for (old_att, new_att, sugg) in attributes: |
| 897 |
|
old_code, new_code = format_str(code, old_att, new_att) |
| 898 |
|
self.runs(old_code, up_to_version(version)) |
| 899 |
|
self.throws(old_code, ATTRIBUTEERROR, sugg, from_version(version)) |
| 900 |
|
self.runs(new_code) |
| 901 |
|
|
| 902 |
|
def test_removed_method_attributes(self): |
| 903 |
|
"""Some methods attributes are removed.""" |
| 904 |
|
# NICE_TO_HAVE |
| 905 |
|
version = (3, 0) |
| 906 |
|
code = 'FoobarClass().some_method.{0}' |
| 907 |
|
attributes = [('im_func', '__func__', []), |
| 908 |
|
('im_self', '__self__', []), |
| 909 |
|
('im_class', '__self__.__class__', ["'__class__'"])] |
| 910 |
|
for (old_att, new_att, sugg) in attributes: |
| 911 |
|
old_code, new_code = format_str(code, old_att, new_att) |
| 912 |
|
self.runs(old_code, up_to_version(version)) |
| 913 |
|
self.throws(old_code, ATTRIBUTEERROR, sugg, from_version(version)) |
| 914 |
|
self.runs(new_code) |