|
@@ 1675-1694 (lines=20) @@
|
| 1672 |
|
def test_nonlocal3(self): |
| 1673 |
|
"""nonlocal must be used only when binding to non-global exists.""" |
| 1674 |
|
# NICE_TO_HAVE |
| 1675 |
|
version = (3, 0) |
| 1676 |
|
code = 'foo = 1\ndef func():\n\tdef nested():\n\t\tnonlocal foo' |
| 1677 |
|
self.throws(code, NOBINDING, [], from_version(version)) |
| 1678 |
|
self.throws(code, INVALIDSYNTAX, [], up_to_version(version)) |
| 1679 |
|
|
| 1680 |
|
def test_octal_literal(self): |
| 1681 |
|
"""Syntax for octal liberals has changed.""" |
| 1682 |
|
# NICE_TO_HAVE |
| 1683 |
|
version = (3, 0) |
| 1684 |
|
bad, good = '0720', '0o720' |
| 1685 |
|
self.runs(good) |
| 1686 |
|
self.runs(bad, up_to_version(version)) |
| 1687 |
|
self.throws(bad, INVALIDTOKEN, [], from_version(version), 'cython') |
| 1688 |
|
self.throws(bad, INVALIDSYNTAX, [], from_version(version), 'pypy') |
| 1689 |
|
|
| 1690 |
|
def test_extended_unpacking(self): |
| 1691 |
|
"""Extended iterable unpacking is added with Python 3.""" |
| 1692 |
|
version = (3, 0) |
| 1693 |
|
code = '(a, *rest, b) = range(5)' |
| 1694 |
|
self.throws(code, INVALIDSYNTAX, [], up_to_version(version)) |
| 1695 |
|
self.runs(code, from_version(version)) |
| 1696 |
|
|
| 1697 |
|
def test_ellipsis(self): |
|
@@ 920-939 (lines=20) @@
|
| 917 |
|
'raise AttributeError("unmatched ATTRIBUTEERROR")', |
| 918 |
|
UNKNOWN_ATTRIBUTEERROR) |
| 919 |
|
|
| 920 |
|
# TODO: Add sugg for situation where self/cls is the missing parameter |
| 921 |
|
|
| 922 |
|
|
| 923 |
|
class TypeErrorTests(GetSuggestionsTests): |
| 924 |
|
"""Class for tests related to TypeError.""" |
| 925 |
|
|
| 926 |
|
def test_unhashable(self): |
| 927 |
|
"""Test for UNHASHABLE exception.""" |
| 928 |
|
# NICE_TO_HAVE : suggest hashable equivalent |
| 929 |
|
self.throws('s = set([list()])', UNHASHABLE) |
| 930 |
|
self.throws('s = set([dict()])', UNHASHABLE) |
| 931 |
|
self.throws('s = set([set()])', UNHASHABLE) |
| 932 |
|
self.runs('s = set([tuple()])') |
| 933 |
|
self.runs('s = set([frozenset()])') |
| 934 |
|
|
| 935 |
|
def test_not_sub(self): |
| 936 |
|
"""Should be function call, not [] operator.""" |
| 937 |
|
typo, sugg = '[2]', '(2)' |
| 938 |
|
code = func_gen(param='a') + 'some_func{0}' |
| 939 |
|
bad_code, good_code = format_str(code, typo, sugg) |
| 940 |
|
suggestion = "'function(value)'" |
| 941 |
|
# Only Python 2.7 with cpython has a different error message |
| 942 |
|
# (leading to more suggestions based on fuzzy matches) |