@@ 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 | self.runs(good_code) |
|
2158 | self.throws(bad_code, INVALIDSYNTAX, [], before) |
|
2159 | self.throws(bad_code, NOBINDING, sugg, after) |
|
2160 | ||
2161 | def test_nonlocal4(self): |
|
2162 | """suggest close matches to variable name.""" |
|
2163 | # NICE_TO_HAVE (needs access to variable in enclosing scope) |
|
2164 | before, after = before_and_after((3, 0)) |
|
2165 | code = 'def func():\n\tfoo = 1\n\tdef nested():\n\t\tnonlocal {0}' |
|
2166 | typo, good = 'foob', 'foo' |
|
2167 | bad_code, good_code = format_str(code, typo, good) |
|
2168 | self.throws(good_code, INVALIDSYNTAX, [], before) |
|
2169 | self.runs(good_code, after) |
|
2170 | self.throws(bad_code, INVALIDSYNTAX, [], before) |
|
2171 | self.throws(bad_code, NOBINDING, [], after) |
|
2172 | ||
2173 | def test_nonlocal_at_module_level(self): |
|
2174 | """nonlocal must be used in function.""" |
|
2175 | before, mid, after = before_mid_and_after((2, 7), (3, 0)) |