Skip to content

Commit

Permalink
Merge pull request #110 from ncmiller/master
Browse files Browse the repository at this point in the history
Handle None inputs same as empty string (Issue #94)
  • Loading branch information
josegonzalez committed Mar 14, 2016
2 parents 32adc6d + 10055f9 commit f9b3264
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
6 changes: 2 additions & 4 deletions fuzzywuzzy/utils.py
Expand Up @@ -18,10 +18,8 @@ def validate_string(s):
def check_for_none(func):
@functools.wraps(func)
def decorator(*args, **kwargs):
if args[0] is None:
raise TypeError("s1 is None")
if args[1] is None:
raise TypeError("s2 is None")
if args[0] is None or args[1] is None:
return 0
return func(*args, **kwargs)
return decorator

Expand Down
10 changes: 4 additions & 6 deletions test_fuzzywuzzy.py
Expand Up @@ -277,13 +277,11 @@ def testCheckForNone(self):
]
decorated_func = utils.check_for_none(self.testFunc)
for i in invalid_input:
self.assertRaises(TypeError, decorated_func, *i)
self.assertEqual(decorated_func(*i), 0)

try:
valid_input = ['Some', 'Some']
decorated_func(*valid_input)
except ValueError as e:
self.fail('check_for_none matched non-None input', valid_input, e)
valid_input = ('Some', 'Some')
actual = decorated_func(*valid_input)
self.assertNotEqual(actual, 0)

def testCheckEmptyString(self):
invalid_input = [
Expand Down

0 comments on commit f9b3264

Please sign in to comment.