Skip to content
This repository has been archived by the owner on Mar 22, 2018. It is now read-only.

Commit

Permalink
relates to both #236 and #237. it's better support of Empty and needs…
Browse files Browse the repository at this point in the history
… being documented.
  • Loading branch information
mfrasca committed Dec 25, 2015
1 parent 4421b63 commit 11cf4f0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
12 changes: 11 additions & 1 deletion bauble/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ def __repr__(self):
def express(self):
return set()

def __eq__(self, other):
if isinstance(other, EmptyToken):
return True
if isinstance(other, set):
return len(other) == 0
return NotImplemented


class ValueABC(object):
## abstract base class.
Expand Down Expand Up @@ -1013,7 +1020,10 @@ def get_expression(self):
and_or = ''
if self.and_or_combo:
and_or = self.and_or_combo.get_active_text()
result = ' '.join([and_or, self.prop_button.props.label,
field_name = self.prop_button.props.label
if value == EmptyToken():
field_name = field_name.rsplit('.', 1)[0]
result = ' '.join([and_or, field_name,
self.cond_combo.get_active_text(),
repr(value)]).strip()
return result
Expand Down
16 changes: 16 additions & 0 deletions bauble/test/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,3 +959,19 @@ def test_parse_typed_value_empty_set(self):
def test_parse_typed_value_fallback(self):
result = search.parse_typed_value('whatever else')
self.assertEquals(result, 'whatever else')


class EmptySetEqualityTest(unittest.TestCase):
def test_EmptyToken_equals(self):
et1 = search.EmptyToken()
et2 = search.EmptyToken()
self.assertEquals(et1, et2)
self.assertTrue(et1 == et2)
self.assertTrue(et1 == set())

def test_empty_token_otherwise(self):
et1 = search.EmptyToken()
self.assertFalse(et1 is None)
self.assertFalse(et1 == 0)
self.assertFalse(et1 == '')
self.assertFalse(et1 == set([1, 2, 3]))

0 comments on commit 11cf4f0

Please sign in to comment.