|
@@ 1301-1327 (lines=27) @@
|
| 1298 |
|
"""Delete from string does not work.""" |
| 1299 |
|
code = "s = 'abc'\ndel s[1]" |
| 1300 |
|
good_code = "s = 'abc'\nl = list(s)\ndel l[1]\ns = ''.join(l)" |
| 1301 |
|
self.runs(good_code) |
| 1302 |
|
self.throws( |
| 1303 |
|
code, |
| 1304 |
|
OBJECTDOESNOTSUPPORT, |
| 1305 |
|
'convert to list to edit the list and use "join()" on the list') |
| 1306 |
|
|
| 1307 |
|
def test_object_indexing(self): |
| 1308 |
|
"""Index from object does not work if __getitem__ is not defined.""" |
| 1309 |
|
version = (3, 0) |
| 1310 |
|
code = "{0}[0]" |
| 1311 |
|
good_code, set_code, custom_code = \ |
| 1312 |
|
format_str(code, '"a_string"', "set()", "FoobarClass()") |
| 1313 |
|
self.runs(good_code) |
| 1314 |
|
sugg_for_iterable = 'convert to list first or use the iterator ' \ |
| 1315 |
|
'protocol to get the different elements' |
| 1316 |
|
self.throws(set_code, |
| 1317 |
|
OBJECTDOESNOTSUPPORT, |
| 1318 |
|
sugg_for_iterable, ALL_VERSIONS, 'cython') |
| 1319 |
|
self.throws(set_code, |
| 1320 |
|
UNSUBSCRIPTABLE, |
| 1321 |
|
sugg_for_iterable, ALL_VERSIONS, 'pypy') |
| 1322 |
|
self.throws(custom_code, |
| 1323 |
|
ATTRIBUTEERROR, [], up_to_version(version), 'pypy') |
| 1324 |
|
self.throws(custom_code, |
| 1325 |
|
UNSUBSCRIPTABLE, |
| 1326 |
|
'implement "__getitem__" on FoobarClass', |
| 1327 |
|
from_version(version), 'pypy') |
| 1328 |
|
self.throws(custom_code, |
| 1329 |
|
ATTRIBUTEERROR, [], up_to_version(version), 'cython') |
| 1330 |
|
self.throws(custom_code, |
|
@@ 897-911 (lines=15) @@
|
| 894 |
|
""" |
| 895 |
|
code = "['a', 'b'].join('-')" |
| 896 |
|
self.throws(code, ATTRIBUTEERROR, "'my_string.join(list)'") |
| 897 |
|
|
| 898 |
|
def test_set_dict_comprehension(self): |
| 899 |
|
"""{} creates a dict and not an empty set leading to errors.""" |
| 900 |
|
# NICE_TO_HAVE |
| 901 |
|
version = (2, 7) |
| 902 |
|
for method in set(dir(set)) - set(dir(dict)): |
| 903 |
|
if not method.startswith('__'): # boring suggestions |
| 904 |
|
code = "a = {0}\na." + method |
| 905 |
|
typo, dict1, dict2, sugg, set1 = format_str( |
| 906 |
|
code, "{}", "dict()", "{0: 0}", "set()", "{0}") |
| 907 |
|
self.throws(typo, ATTRIBUTEERROR) |
| 908 |
|
self.throws(dict1, ATTRIBUTEERROR) |
| 909 |
|
self.throws(dict2, ATTRIBUTEERROR) |
| 910 |
|
self.runs(sugg) |
| 911 |
|
self.throws(set1, INVALIDSYNTAX, [], up_to_version(version)) |
| 912 |
|
self.runs(set1, from_version(version)) |
| 913 |
|
|
| 914 |
|
def test_unmatched_msg(self): |