Permalink
Browse files

Fix search in gui

Searching inputs or outputs in the gui didn't work. It crashed on runs
with empty inputs or outputs, or when the file hash was None (I'm
not entirely sure this should happen). The code was refactored to
deal with these exceptions.

Also added tests.
  • Loading branch information...
jvdzwaan committed Aug 1, 2018
1 parent 339b685 commit f2d8cd428d1274ad8bd2c2adf745f7e0340356e3
Showing with 27 additions and 4 deletions.
  1. +9 −4 recipyCommon/tinydb_utils.py
  2. +18 −0 test/test_tinydb_utils.py
@@ -39,8 +39,13 @@ def listsearch(query, item):
"""
fh = ''
if not isinstance(item, six.string_types):
fh = item[1]
item = item[0]
try:
fh = item[1]
item = item[0]
except IndexError:
item = ''
return bool(re.search(query, item) or
re.search(query, fh))
if fh is None:
fh = ''
return bool(re.search(query, item) or re.search(query, fh))
View
@@ -36,3 +36,21 @@ def test_listsearch_list_of_lists_no_match(item):
msg = 'listsearch({}, {}) does not return false'.format(q, item)
assert not listsearch(q, item), msg
def test_listsearch_empty_item():
item = []
q = 'test'
msg = 'listsearch fails when item=[]'
assert not listsearch(q, item), msg
def test_listsearch_hash_is_none():
item = [u'test.csv', None]
q = 'test'
msg = 'listsearch fails when hash is None'
assert listsearch(q, item), msg

0 comments on commit f2d8cd4

Please sign in to comment.