|
@@ 1145-1160 (lines=16) @@
|
| 1142 |
|
self.runs(set1, after) |
| 1143 |
|
|
| 1144 |
|
def test_unmatched_msg(self): |
| 1145 |
|
"""Test that arbitrary strings are supported.""" |
| 1146 |
|
code = 'raise AttributeError("unmatched ATTRIBUTEERROR")' |
| 1147 |
|
self.throws(code, UNKNOWN_ATTRIBUTEERROR) |
| 1148 |
|
|
| 1149 |
|
# TODO: Add sugg for situation where self/cls is the missing parameter |
| 1150 |
|
|
| 1151 |
|
|
| 1152 |
|
class TypeErrorTests(GetSuggestionsTests): |
| 1153 |
|
"""Class for tests related to TypeError.""" |
| 1154 |
|
|
| 1155 |
|
def test_unhashable(self): |
| 1156 |
|
"""Test for UNHASHABLE exception.""" |
| 1157 |
|
# NICE_TO_HAVE : suggest hashable equivalent |
| 1158 |
|
self.throws('s = set([list()])', UNHASHABLE) |
| 1159 |
|
self.throws('s = set([dict()])', UNHASHABLE) |
| 1160 |
|
self.throws('s = set([set()])', UNHASHABLE) |
| 1161 |
|
self.runs('s = set([tuple()])') |
| 1162 |
|
self.runs('s = set([frozenset()])') |
| 1163 |
|
|
|
@@ 2160-2172 (lines=13) @@
|
| 2157 |
|
|
| 2158 |
|
def test_nonlocal3(self): |
| 2159 |
|
"""nonlocal must be used only when binding to non-global exists.""" |
| 2160 |
|
# just a way to say that this_is_a_global_list is needed in globals |
| 2161 |
|
name = 'this_is_a_global_list' |
| 2162 |
|
this_is_a_global_list |
| 2163 |
|
self.assertFalse(name in locals()) |
| 2164 |
|
self.assertTrue(name in globals()) |
| 2165 |
|
before, after = before_and_after((3, 0)) |
| 2166 |
|
code = 'def func():\n\tdef nested():\n\t\t{0} ' + name |
| 2167 |
|
typo, good = 'nonlocal', 'global' |
| 2168 |
|
sugg = "'{0} {1}'".format(good, name) |
| 2169 |
|
bad_code, good_code = format_str(code, typo, good) |
| 2170 |
|
self.runs(good_code) |
| 2171 |
|
self.throws(bad_code, INVALIDSYNTAX, [], before) |
| 2172 |
|
self.throws(bad_code, NOBINDING, sugg, after) |
| 2173 |
|
|
| 2174 |
|
def test_nonlocal4(self): |
| 2175 |
|
"""suggest close matches to variable name.""" |