def test_resumable_hashing(self):
        """Resuming hash has the same result as hashlib."""
        results = []
        hexresults = []
        data = "Freedom is slavery" * 1000

        sha = hashlib.sha1()
        sha.update(data)
        results.append(sha.digest())
        hexresults.append(sha.hexdigest())

        sha = rhashlib.sha1()
        sha.update(data[:500])

        sha2 = rhashlib.sha1()
        sha2.set_context(sha.get_context())
        sha2.update(data[500:])

        results.append(sha2.digest())
        hexresults.append(sha2.hexdigest())

        self.assertEqual(*results)
        self.assertEqual(*hexresults)
    def test_context(self):
        """get/set context work."""
        ctx = rhashlib.sha1()
        h0 = ctx.h0

        # get content works
        old = ctx.get_context()

        # change it
        ctx.h0 = 1
        self.assertEqual(ctx.h0, 1)

        # set works
        ctx.set_context(old)
        self.assertEquals(old, ctx.get_context())
        self.assertEqual(ctx.h0, h0)
 def test_copy(self):
     """copied hashes have the same context."""
     s = rhashlib.sha1("Thoughtcrime does not entail death: "
                       "thoughtcrime is death.")
     self.assertEqual(s.get_context(), s.copy().get_context())