Skip to content

Commit

Permalink
fixed nasty bug in tree node equality
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgarel committed Oct 25, 2018
1 parent 7e3dfdf commit a424e0f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ and this project tries to adhere to `Semantic Versioning`_.
.. _`Keep a Changelog`: http://keepachangelog.com/en/1.0.0/
.. _`Semantic Versioning`: http://semver.org/spec/v2.0.0.html

UNRELEASED
==========

Fixed
-----

- fixed bug on equality, having more children in one tree than in the other,
was not triggering inequality if first nodes were the same !

0.7.4 - 2018-08-28
==================

Expand Down
2 changes: 1 addition & 1 deletion luqum/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-

__version__ = '0.7.4'
__version__ = '0.7.5a'
__version_info__ = tuple(__version__.split('.'))
17 changes: 17 additions & 0 deletions luqum/tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import collections
import copy
from decimal import Decimal
from unittest import TestCase

Expand Down Expand Up @@ -86,6 +87,12 @@ def test_equality_approx(self):
self.assertNotEqual(f1, f2)
self.assertEqual(f1, f3)

def test_not_equality(self):
# non regression test, adding a child should trigger non equality
tree1 = OrOperation(Word("bar"))
tree2 = OrOperation(Word("bar"), Word("foo"))
self.assertNotEqual(tree1, tree2)


class TestLexer(TestCase):
"""Test lexer
Expand Down Expand Up @@ -843,6 +850,16 @@ def test_silent_value_error(self):
new_tree,
AndOperation(Word("lol"), Word("lol")))

def test_repeating_expression(self):
# non regression test
tree = AndOperation(
Group(OrOperation(Word('bar'), Word('foo'))),
Group(OrOperation(Word('bar'), Word('foo'), Word('spam'))),
)
# basic transformer should not change tree
same_tree = LuceneTreeTransformer().visit(copy.deepcopy(tree))
self.assertEqual(same_tree, tree)


class TreeVisitorV2TestCase(TestCase):

Expand Down
1 change: 1 addition & 0 deletions luqum/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __eq__(self, other):
"""a basic equal operation
"""
return (self.__class__ == other.__class__ and
len(self.children) == len(other.children) and
all(getattr(self, a, _MARKER) == getattr(other, a, _MARKER)
for a in self._equality_attrs) and
all(c.__eq__(d) for c, d in zip(self.children, other.children)))
Expand Down

0 comments on commit a424e0f

Please sign in to comment.