def testReasonableInterval(self): # Check if the limit on maximum blocksize for processing still holds. dummy = io.BytesIO(b'') fp = fingerprint.Fingerprinter(dummy) big_finger = fingerprint.Finger(None, [fingerprint.Range(0, 1000001)], None) fp.fingers.append(big_finger) start, stop = fp._GetNextInterval() self.assertEqual(0, start) self.assertEqual(1000000, stop)
def testHashBlock(self): # Does it invoke a hash function? dummy = b'12345' fp = fingerprint.Fingerprinter(io.BytesIO(dummy)) big_finger = fingerprint.Finger(None, [fingerprint.Range(0, len(dummy))], None) hasher = self.MockHasher() big_finger.hashers = [hasher] fp.fingers.append(big_finger) # Let's process the block fp._HashBlock(dummy, 0, len(dummy)) self.assertEqual(hasher.seen, dummy)
def testAdjustments(self): dummy = io.BytesIO(b'') fp = fingerprint.Fingerprinter(dummy) big_finger = fingerprint.Finger(None, [fingerprint.Range(10, 20)], None) fp.fingers.append(big_finger) # The remaining range should not yet be touched... fp._AdjustIntervals(9, 10) self.assertEqual([fingerprint.Range(10, 20)], fp.fingers[0].ranges) # Trying to consume into the range. Blow up. self.assertRaises(RuntimeError, fp._AdjustIntervals, 9, 11) # We forgot a byte. Blow up. self.assertRaises(RuntimeError, fp._AdjustIntervals, 11, 12) # Consume a byte fp._AdjustIntervals(10, 11) self.assertEqual([fingerprint.Range(11, 20)], fp.fingers[0].ranges) # Consumed too much. Blow up. self.assertRaises(RuntimeError, fp._AdjustIntervals, 11, 21) # Consume exactly. fp._AdjustIntervals(11, 20) self.assertEmpty(fp.fingers[0].ranges)