Example #1
0
    def test_asynchronous(self):
        """
        L{stream.MD5Stream} also supports L{IByteStream} providers which return
        L{Deferreds} from their C{read} method.
        """
        dataStream = AsynchronousDummyStream()
        md5Stream = stream.MD5Stream(dataStream)

        result = md5Stream.read()
        dataStream._write(self.data)
        result.addCallback(self.assertEquals, self.data)

        def cbRead(ignored):
            result = md5Stream.read()
            dataStream._write(None)
            result.addCallback(self.assertIdentical, None)
            return result

        result.addCallback(cbRead)

        def cbClosed(ignored):
            md5Stream.close()
            self.assertEquals(md5Stream.getMD5(), self.digest)

        result.addCallback(cbClosed)

        return result
Example #2
0
 def test_getMD5FailsBeforeClose(self):
     """
     L{stream.MD5Stream.getMD5} raises L{RuntimeError} if called before
     L{stream.MD5Stream.close}.
     """
     dataStream = stream.MemoryStream(self.data)
     md5Stream = stream.MD5Stream(dataStream)
     self.assertRaises(RuntimeError, md5Stream.getMD5)
Example #3
0
 def test_readAfterClose(self):
     """
     L{stream.MD5Stream.read} raises L{RuntimeError} if called after
     L{stream.MD5Stream.close}.
     """
     dataStream = stream.MemoryStream(self.data)
     md5Stream = stream.MD5Stream(dataStream)
     md5Stream.close()
     self.assertRaises(RuntimeError, md5Stream.read)
Example #4
0
    def test_synchronous(self):
        """
        L{stream.MD5Stream} computes the MD5 hash of the contents of the stream
        around which it is wrapped.  It supports L{IByteStream} providers which
        return C{str} from their C{read} method.
        """
        dataStream = stream.MemoryStream(self.data)
        md5Stream = stream.MD5Stream(dataStream)

        self.assertEquals(str(md5Stream.read()), self.data)
        self.assertIdentical(md5Stream.read(), None)
        md5Stream.close()

        self.assertEquals(self.digest, md5Stream.getMD5())