releasetools: Fix a bug in blockimgdiff.HeapItem.
HeapItem defines __bool__(), which contains a logical error that should
return the opposite value.
Note that the bug only manifests while using Python 3, which calls
__bool__(). With Python 2, `if x:` or bool(x) actually calls
x.__nonzero__() or x.__len__(). If a class defines neither __len__() nor
__nonzero__(), as the case in HeapItem, it always returns True.
Test: python -m unittest test_blockimgdiff
Test: python3 -m unittest test_blockimgdiff
Test: Generate an incremental non-A/B OTA package successfully.
Change-Id: Ibe8430e0b495a7d2f430cfffb716d2536ffb53d2
diff --git a/tools/releasetools/test_blockimgdiff.py b/tools/releasetools/test_blockimgdiff.py
index e5a3694..7084e21 100644
--- a/tools/releasetools/test_blockimgdiff.py
+++ b/tools/releasetools/test_blockimgdiff.py
@@ -16,12 +16,43 @@
from __future__ import print_function
-import common
import unittest
-from blockimgdiff import BlockImageDiff, EmptyImage, Transfer
+import common
+from blockimgdiff import BlockImageDiff, EmptyImage, HeapItem, Transfer
from rangelib import RangeSet
+
+class HealpItemTest(unittest.TestCase):
+
+ class Item(object):
+ def __init__(self, score):
+ self.score = score
+
+ def test_init(self):
+ item1 = HeapItem(self.Item(15))
+ item2 = HeapItem(self.Item(20))
+ item3 = HeapItem(self.Item(15))
+ self.assertTrue(item1)
+ self.assertTrue(item2)
+ self.assertTrue(item3)
+
+ self.assertNotEqual(item1, item2)
+ self.assertEqual(item1, item3)
+ # HeapItem uses negated scores.
+ self.assertGreater(item1, item2)
+ self.assertLessEqual(item1, item3)
+ self.assertTrue(item1 <= item3)
+ self.assertFalse(item2 >= item1)
+
+ def test_clear(self):
+ item = HeapItem(self.Item(15))
+ self.assertTrue(item)
+
+ item.clear()
+ self.assertFalse(item)
+
+
class BlockImageDiffTest(unittest.TestCase):
def test_GenerateDigraphOrder(self):