Skip to content

Commit

Permalink
Add idea
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainDe committed May 31, 2015
1 parent d956d6a commit 177b5d8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
3 changes: 3 additions & 0 deletions didyoumean/didyoumean_re.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@
CANNOT_CONCAT_RE = r"^cannot concatenate '(\w+)' and '(\w+)' objects$"
CANT_CONVERT_RE = r"Can't convert '(\w+)' object to (\w+) implicitly$"
NOT_CALLABLE_RE = r"^'(\w+)' object is not callable$"
DESCRIPT_REQUIRES_TYPE_RE = r"^descriptor '(\w+)' requires a '(\w+)' " \
r"object but received a '(\w+)'$"
ARG_NOT_ITERABLE_RE = r"^argument of type '(\w+)' is not iterable$"
13 changes: 12 additions & 1 deletion didyoumean/didyoumean_re_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
MISSING_POS_ARG_RE, FUTURE_FIRST_RE, FUTURE_FEATURE_NOT_DEF_RE,\
RESULT_TOO_MANY_ITEMS_RE, UNQUALIFIED_EXEC_RE, IMPORTSTAR_RE,\
UNSUPPORTED_OP_RE, OBJ_DOES_NOT_SUPPORT_RE, CANNOT_CONCAT_RE,\
CANT_CONVERT_RE, NOT_CALLABLE_RE
CANT_CONVERT_RE, NOT_CALLABLE_RE, DESCRIPT_REQUIRES_TYPE_RE,\
ARG_NOT_ITERABLE_RE
import unittest2
import re
import sys
Expand Down Expand Up @@ -321,6 +322,16 @@ def test_not_callable(self):
msg = "'list' object is not callable"
self.regex_matches(msg, NOT_CALLABLE_RE, ('list',))

def test_descriptor_requires(self):
""" Test DESCRIPT_REQUIRES_TYPE_RE ."""
msg = "descriptor 'add' requires a 'set' object but received a 'int'"
self.regex_matches(
msg, DESCRIPT_REQUIRES_TYPE_RE, ('add', 'set', 'int'))

def test_argument_not_iterable(self):
""" Test ARG_NOT_ITERABLE_RE ."""
msg = "argument of type 'type' is not iterable"
self.regex_matches(msg, ARG_NOT_ITERABLE_RE, ('type',))

if __name__ == '__main__':
print(sys.version_info)
Expand Down
17 changes: 16 additions & 1 deletion didyoumean/didyoumean_sugg_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
MISSING_POS_ARG_RE, FUTURE_FIRST_RE, FUTURE_FEATURE_NOT_DEF_RE,\
RESULT_TOO_MANY_ITEMS_RE, UNQUALIFIED_EXEC_RE, IMPORTSTAR_RE,\
UNSUPPORTED_OP_RE, OBJ_DOES_NOT_SUPPORT_RE, CANNOT_CONCAT_RE,\
CANT_CONVERT_RE, NOT_CALLABLE_RE
CANT_CONVERT_RE, NOT_CALLABLE_RE, DESCRIPT_REQUIRES_TYPE_RE,\
ARG_NOT_ITERABLE_RE
import sys
import math

Expand Down Expand Up @@ -150,6 +151,8 @@ def get_exception(code):
CANNOTCONCAT = (TypeError, CANNOT_CONCAT_RE)
CANTCONVERT = (TypeError, CANT_CONVERT_RE)
NOTCALLABLE = (TypeError, NOT_CALLABLE_RE)
DESCREXPECT = (TypeError, DESCRIPT_REQUIRES_TYPE_RE)
ARGNOTITERABLE = (TypeError, ARG_NOT_ITERABLE_RE)
UNKNOWN_TYPEERROR = (TypeError, None)
# ImportError for ImportErrorTests
NOMODULE = (ImportError, NOMODULE_RE)
Expand Down Expand Up @@ -689,6 +692,18 @@ def test_not_sub(self):
self.throws(bad_code, UNSUBSCRIBTABLE, "'function(value)'")
self.runs(good_code)

def test_method_called_on_class(self):
# NICE_TO_HAVE
"""Forgetting parenthesis makes the difference between using an
instance and using a type."""
for code, error in [
('set{0}.add(0)', DESCREXPECT),
('list{0}.append(0)', DESCREXPECT),
('0 in list{0}', ARGNOTITERABLE)]:
bad_code, good_code = format_str(code, '', '()')
self.runs(good_code)
self.throws(bad_code, error)

def test_set_add(self):
""" set + set doesn't work. A suggestion would be nice."""
# NICE_TO_HAVE
Expand Down

0 comments on commit 177b5d8

Please sign in to comment.