Commits

Matt Chaput committed 9a2eb76

Added object identity comparison to BuildNode.__eq__().

Comments (0)

Files changed (2)

src/whoosh/support/dawg.py

         return h
 
     def __eq__(self, other):
+        if self is other:
+            return True
         if self.final != other.final:
             return False
-        mine, theirs = self._edges, other._edges
+        mine, theirs = self.all_edges(), other.all_edges()
         if len(mine) != len(theirs):
             return False
         for key in iterkeys(mine):

tests/test_spelling.py

 
 
 def test_dawg():
-    from whoosh.support.dawg import DawgBuilder
-
     with TempStorage() as st:
         df = st.create_file("test.dawg")
 
-        dw = DawgBuilder(field_root=True)
+        dw = dawg.DawgBuilder(field_root=True)
         dw.insert(["test"] + list("special"))
         dw.insert(["test"] + list("specials"))
         dw.write(df)
 
         assert_equal(list(dawg.flatten(dw.root.edge("test"))), ["special", "specials"])
 
+def test_node_eq():
+    st = RamStorage()
+    df = st.create_file("test.dawg")
+    dw = dawg.DawgBuilder()
+    dw.insert("alfa")
+    dw.insert("alpaca")
+    dw.insert("alpha")
+    dw.insert("bravo")
+    dw.insert("brief")
+    dw.insert("bro")
+
+    r = dw.root
+    assert r == r
+
 def test_fields_out_of_order():
     dw = dawg.DawgBuilder()
     dw.insert("alfa")