|
@@ 1123-1142 (lines=20) @@
|
| 1120 |
|
self.runs('s = set([tuple()])') |
| 1121 |
|
self.runs('s = set([frozenset()])') |
| 1122 |
|
|
| 1123 |
|
def test_not_sub(self): |
| 1124 |
|
"""Should be function call, not [] operator.""" |
| 1125 |
|
# https://twitter.com/raymondh/status/772957699478663169 |
| 1126 |
|
typo, sugg = '[2]', '(2)' |
| 1127 |
|
code = func_gen(param='a') + 'some_func{0}' |
| 1128 |
|
bad_code, good_code = format_str(code, typo, sugg) |
| 1129 |
|
suggestion = "'function(value)'" |
| 1130 |
|
# Only Python 2.7 with cpython has a different error message |
| 1131 |
|
# (leading to more suggestions based on fuzzy matches) |
| 1132 |
|
version1 = (2, 7) |
| 1133 |
|
version2 = (3, 0) |
| 1134 |
|
self.throws(bad_code, UNSUBSCRIPTABLE, suggestion, interpreters='pypy') |
| 1135 |
|
self.throws(bad_code, UNSUBSCRIPTABLE, suggestion, |
| 1136 |
|
up_to_version(version1), 'cython') |
| 1137 |
|
self.throws(bad_code, UNSUBSCRIPTABLE, suggestion, |
| 1138 |
|
from_version(version2), 'cython') |
| 1139 |
|
self.throws(bad_code, NOATTRIBUTE_TYPEERROR, |
| 1140 |
|
["'__get__'", "'__getattribute__'", suggestion], |
| 1141 |
|
(version1, version2), 'cython') |
| 1142 |
|
self.runs(good_code) |
| 1143 |
|
|
| 1144 |
|
def test_method_called_on_class(self): |
| 1145 |
|
"""Test where a method is called on a class and not an instance. |
|
@@ 1593-1608 (lines=16) @@
|
| 1590 |
|
typo, sugg = '12', 'str(12)' |
| 1591 |
|
bad_code, good_code = format_str(code, typo, sugg) |
| 1592 |
|
version = (3, 0) |
| 1593 |
|
version2 = (3, 6) |
| 1594 |
|
self.throws( |
| 1595 |
|
bad_code, CANNOTCONCAT, [], up_to_version(version), 'cython') |
| 1596 |
|
self.throws( |
| 1597 |
|
bad_code, CANTCONVERT, [], (version, version2), 'cython') |
| 1598 |
|
self.throws( |
| 1599 |
|
bad_code, MUSTBETYPENOTTYPE, [], from_version(version2), 'cython') |
| 1600 |
|
self.throws(bad_code, UNSUPPORTEDOPERAND, interpreters='pypy') |
| 1601 |
|
self.runs(good_code) |
| 1602 |
|
|
| 1603 |
|
def test_assignment_to_range(self): |
| 1604 |
|
"""Trying to assign to range works on list, not on range.""" |
| 1605 |
|
code = '{0}[2] = 1' |
| 1606 |
|
typo, good = 'range(4)', 'list(range(4))' |
| 1607 |
|
sugg = 'convert to list to edit the list' |
| 1608 |
|
before, after = before_and_after((3, 0)) |
| 1609 |
|
bad_code, good_code = format_str(code, typo, good) |
| 1610 |
|
self.runs(good_code) |
| 1611 |
|
self.runs(bad_code, before) |