@@ 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 | self.throws(bad4, UNSUPPORTEDOPERAND, [], up_to_version(v3), 'pypy') |
|
1591 | self.throws(bad4, ATTRIBUTEERROR, [], from_version(v3)) |
|
1592 | ||
1593 | def test_no_implicit_str_conv2(self): |
|
1594 | """Trying to concatenate a non-string value to a string.""" |
|
1595 | # NICE_TO_HAVE |
|
1596 | code = '"things " + {0}' |
|
1597 | typo, sugg = '12', 'str(12)' |
|
1598 | bad_code, good_code = format_str(code, typo, sugg) |
|
1599 | version = (3, 0) |
|
1600 | version2 = (3, 6) |
|
1601 | self.throws( |
|
1602 | bad_code, CANNOTCONCAT, [], up_to_version(version), 'cython') |
|
1603 | self.throws( |
|
1604 | bad_code, CANTCONVERT, [], (version, version2), 'cython') |
|
1605 | self.throws( |
|
1606 | bad_code, MUSTBETYPENOTTYPE, [], from_version(version2), 'cython') |
|
1607 | self.throws(bad_code, UNSUPPORTEDOPERAND, interpreters='pypy') |
|
1608 | self.runs(good_code) |
|
1609 | ||
1610 | def test_assignment_to_range(self): |
|
1611 | """Trying to assign to range works on list, not on range.""" |
|
@@ 2102-2112 (lines=11) @@ | ||
2099 | from_version(version)) |
|
2100 | self.throws(bad_code, INVALIDSYNTAX, [], up_to_version(version)) |
|
2101 | ||
2102 | def test_nonlocal4(self): |
|
2103 | """suggest close matches to variable name.""" |
|
2104 | # NICE_TO_HAVE (needs access to variable in enclosing scope) |
|
2105 | version = (3, 0) |
|
2106 | code = 'def func():\n\tfoo = 1\n\tdef nested():\n\t\tnonlocal {0}' |
|
2107 | typo, sugg = 'foob', 'foo' |
|
2108 | bad_code, good_code = format_str(code, typo, sugg) |
|
2109 | self.runs(good_code, from_version(version)) |
|
2110 | self.throws(good_code, INVALIDSYNTAX, [], up_to_version(version)) |
|
2111 | self.throws(bad_code, NOBINDING, [], from_version(version)) |
|
2112 | self.throws(bad_code, INVALIDSYNTAX, [], up_to_version(version)) |
|
2113 | ||
2114 | def test_nonlocal_at_module_level(self): |
|
2115 | """nonlocal must be used in function.""" |