|
@@ 1404-1430 (lines=27) @@
|
| 1401 |
|
|
| 1402 |
|
def test_assignment_to_string(self): |
| 1403 |
|
"""Trying to assign to string does not work.""" |
| 1404 |
|
code = "s = 'abc'\ns[1] = 'd'" |
| 1405 |
|
good_code = "s = 'abc'\nl = list(s)\nl[1] = 'd'\ns = ''.join(l)" |
| 1406 |
|
self.runs(good_code) |
| 1407 |
|
self.throws( |
| 1408 |
|
code, |
| 1409 |
|
OBJECTDOESNOTSUPPORT, |
| 1410 |
|
'convert to list to edit the list and use "join()" on the list') |
| 1411 |
|
|
| 1412 |
|
def test_deletion_from_string(self): |
| 1413 |
|
"""Delete from string does not work.""" |
| 1414 |
|
code = "s = 'abc'\ndel s[1]" |
| 1415 |
|
good_code = "s = 'abc'\nl = list(s)\ndel l[1]\ns = ''.join(l)" |
| 1416 |
|
self.runs(good_code) |
| 1417 |
|
self.throws( |
| 1418 |
|
code, |
| 1419 |
|
OBJECTDOESNOTSUPPORT, |
| 1420 |
|
'convert to list to edit the list and use "join()" on the list') |
| 1421 |
|
|
| 1422 |
|
def test_object_indexing(self): |
| 1423 |
|
"""Index from object does not work if __getitem__ is not defined.""" |
| 1424 |
|
version = (3, 0) |
| 1425 |
|
code = "{0}[0]" |
| 1426 |
|
good_code, set_code, custom_code = \ |
| 1427 |
|
format_str(code, '"a_string"', "set()", "FoobarClass()") |
| 1428 |
|
self.runs(good_code) |
| 1429 |
|
sugg_for_iterable = 'convert to list first or use the iterator ' \ |
| 1430 |
|
'protocol to get the different elements' |
| 1431 |
|
self.throws(set_code, |
| 1432 |
|
OBJECTDOESNOTSUPPORT, |
| 1433 |
|
sugg_for_iterable, ALL_VERSIONS, 'cython') |
|
@@ 981-995 (lines=15) @@
|
| 978 |
|
self.throws(null, NAMEERROR, |
| 979 |
|
RELOAD_REMOVED_MSG, from_version(version3)) |
| 980 |
|
self.runs(code_imp) |
| 981 |
|
self.throws(code_importlib, NOMODULE, [], version26) |
| 982 |
|
self.throws(code_importlib, ATTRIBUTEERROR, |
| 983 |
|
"'reload(module)'", (version27, version3)) |
| 984 |
|
self.throws(code_importlib, ATTRIBUTEERROR, |
| 985 |
|
[], (version3, (3, 4))) |
| 986 |
|
self.runs(code_importlib, from_version((3, 4))) |
| 987 |
|
|
| 988 |
|
def test_join(self): |
| 989 |
|
"""Test what happens when join is used incorrectly. |
| 990 |
|
|
| 991 |
|
This can be frustrating to call join on an iterable instead of a |
| 992 |
|
string. |
| 993 |
|
""" |
| 994 |
|
code = "['a', 'b'].join('-')" |
| 995 |
|
self.throws(code, ATTRIBUTEERROR, "'my_string.join(list)'") |
| 996 |
|
|
| 997 |
|
def test_set_dict_comprehension(self): |
| 998 |
|
"""{} creates a dict and not an empty set leading to errors.""" |