|
@@ 1301-1327 (lines=27) @@
|
| 1298 |
|
bad_code, |
| 1299 |
|
OBJECTDOESNOTSUPPORT, |
| 1300 |
|
'convert to list to edit the list', |
| 1301 |
|
from_version(version)) |
| 1302 |
|
|
| 1303 |
|
def test_assignment_to_string(self): |
| 1304 |
|
"""Trying to assign to string does not work.""" |
| 1305 |
|
code = "s = 'abc'\ns[1] = 'd'" |
| 1306 |
|
good_code = "s = 'abc'\nl = list(s)\nl[1] = 'd'\ns = ''.join(l)" |
| 1307 |
|
self.runs(good_code) |
| 1308 |
|
self.throws( |
| 1309 |
|
code, |
| 1310 |
|
OBJECTDOESNOTSUPPORT, |
| 1311 |
|
'convert to list to edit the list and use "join()" on the list') |
| 1312 |
|
|
| 1313 |
|
def test_deletion_from_string(self): |
| 1314 |
|
"""Delete from string does not work.""" |
| 1315 |
|
code = "s = 'abc'\ndel s[1]" |
| 1316 |
|
good_code = "s = 'abc'\nl = list(s)\ndel l[1]\ns = ''.join(l)" |
| 1317 |
|
self.runs(good_code) |
| 1318 |
|
self.throws( |
| 1319 |
|
code, |
| 1320 |
|
OBJECTDOESNOTSUPPORT, |
| 1321 |
|
'convert to list to edit the list and use "join()" on the list') |
| 1322 |
|
|
| 1323 |
|
def test_object_indexing(self): |
| 1324 |
|
"""Index from object does not work if __getitem__ is not defined.""" |
| 1325 |
|
version = (3, 0) |
| 1326 |
|
code = "{0}[0]" |
| 1327 |
|
good_code, set_code, custom_code = \ |
| 1328 |
|
format_str(code, '"a_string"', "set()", "FoobarClass()") |
| 1329 |
|
self.runs(good_code) |
| 1330 |
|
sugg_for_iterable = 'convert to list first or use the iterator ' \ |
|
@@ 897-911 (lines=15) @@
|
| 894 |
|
code = 'import string\n{0}.maketrans' |
| 895 |
|
code_str, code_string = format_str(code, 'str', 'string') |
| 896 |
|
code_str2 = 'str.maketrans' # No 'string' import |
| 897 |
|
self.throws(code_str, ATTRIBUTEERROR, [], up_to_version(version1)) |
| 898 |
|
self.throws(code_str2, ATTRIBUTEERROR, [], up_to_version(version1)) |
| 899 |
|
self.runs(code_string, up_to_version(version1)) |
| 900 |
|
self.throws(code_string, ATTRIBUTEERROR, [], (version1, version2)) |
| 901 |
|
self.throws(code_string, MODATTRIBUTEERROR, [], from_version(version2)) |
| 902 |
|
self.runs(code_str, from_version(version1)) |
| 903 |
|
self.runs(code_str2, from_version(version1)) |
| 904 |
|
|
| 905 |
|
def test_join(self): |
| 906 |
|
"""Test what happens when join is used incorrectly. |
| 907 |
|
|
| 908 |
|
This can be frustrating to call join on an iterable instead of a |
| 909 |
|
string. |
| 910 |
|
""" |
| 911 |
|
code = "['a', 'b'].join('-')" |
| 912 |
|
self.throws(code, ATTRIBUTEERROR, "'my_string.join(list)'") |
| 913 |
|
|
| 914 |
|
def test_set_dict_comprehension(self): |