コード例 #1
0
 def test_large_hash(self):
     with open('/dev/urandom', 'r+b') as f:
         buf = StringBuffer.from_file(f.fileno(), 4096 * 3)
     buf_sha = buf.hash()
     from hashlib import sha1
     outside = StringBuffer(sha1(buf.raw_read()).digest())
     self.assertEquals(outside.raw_read(), buf_sha.raw_read())
コード例 #2
0
 def test_fread(self):
     sb = StringBuffer(16)
     with TemporaryFile('w+b') as f:
         fd = f.fileno()
         f.write('hello world\n')
         f.seek(0)
         sb.fread(fd, 8)
         sb.seek(0)
         self.assertEquals(sb.raw_read(8), 'hello wo')
コード例 #3
0
    def test_overflow(self):
        sb = StringBuffer(24)
        with self.assertRaises(BufferOverflow):
            sb.write('this string is definitely longer than 24 characters and should raise an error')

        self.assertRaises(OverflowError, sb.seek, -1)

        sb = StringBuffer(8)
        sb.set('01234567')
        sb.seek(0)
        buf = sb.raw_read(8)
        self.assertEquals(buf, '01234567')
        self.assertRaises(BufferOverflow, sb.raw_read, 1)
コード例 #4
0
 def test_hash(self):
     buf = StringBuffer("Hello World")
     buf_sha = buf.hash()
     from hashlib import sha1
     outside = StringBuffer(sha1(buf.raw_read()).digest())
     self.assertEquals(outside.raw_read(), buf_sha.raw_read())