def test_resumable_hashing(self): """Resuming hash has the same result as hashlib.""" results = [] data = "Freedom is slavery" * 1000 sha = magic_hash_factory() sha.update(data) results.append(sha.content_hash()._magic_hash) sha = rhashlib.resumable_magic_hash_factory() sha.update(data[:500]) sha2 = rhashlib.resumable_magic_hash_factory() sha2.set_context(sha.get_context()) sha2.update(data[500:]) results.append(sha2.content_hash()._magic_hash) self.assertEqual(*results)
def test_context(self): """get/set context work.""" ctx = rhashlib.resumable_magic_hash_factory() h0 = ctx.hash_object.h0 # get content works old = ctx.get_context() # change it ctx.hash_object.h0 = 1 self.assertEqual(ctx.hash_object.h0, 1) # set works ctx.set_context(old) self.assertEquals(old, ctx.get_context()) self.assertEqual(ctx.hash_object.h0, h0)
def test_copy(self): """copied hashes have the same context.""" s = rhashlib.resumable_magic_hash_factory() s.update("Thoughtcrime does not entail death: thoughtcrime is death.") self.assertEqual(s.get_context(), s.copy().get_context())