コード例 #1
0
ファイル: testbuffer.py プロジェクト: JoyTeam/concurrence
 def testString2(self):
     b = Buffer(1024)
     self.assertEqual(0, b.position)
     self.assertEqual(1024, b.limit)                
     self.assertEqual('\0' * 10, b.read_bytes(10))
     b.clear()
     b.flip()
     #try read string past limit
     try:
         b.read_bytes(10)
         self.fail("expected buffer underflow")
     except BufferUnderflowError:
         pass #expected
コード例 #2
0
 def testString2(self):
     b = Buffer(1024)
     self.assertEqual(0, b.position)
     self.assertEqual(1024, b.limit)
     self.assertEqual('\0' * 10, b.read_bytes(10))
     b.clear()
     b.flip()
     #try read string past limit
     try:
         b.read_bytes(10)
         self.fail("expected buffer underflow")
     except BufferUnderflowError:
         pass  #expected
コード例 #3
0
ファイル: testbuffer.py プロジェクト: JoyTeam/concurrence
    def testReadLine(self):
        b = Buffer(1024)
        
        b.clear()
        b.write_bytes('hello world!\n')
        b.flip()
        self.assertEquals('hello world!', b.read_line())
        self.assertEquals(b.position, b.limit)

        b.clear()
        b.write_bytes('hello world!\r\n')
        b.flip()
        self.assertEquals('hello world!', b.read_line())
        self.assertEquals(b.position, b.limit)

        b.clear()
        b.write_bytes('hello world!\r')
        b.flip()
        try:
            b.read_line()
            self.fail('expected BufferUnderFlow')
        except BufferUnderflowError:
            pass
        

        b.clear()
        b.write_bytes('hello world!\n')
        b.flip()
        self.assertEquals('hello world!\n', b.read_line(True))
        self.assertEquals(b.position, b.limit)

        b.clear()
        b.write_bytes('hello world!\r\n')
        b.flip()
        self.assertEquals('hello world!\r\n', b.read_line(True))
        self.assertEquals(b.position, b.limit)

        b.clear()
        b.write_bytes('hello world!\r')
        b.flip()
        try:
            b.read_line(True)
            self.fail('expected BufferUnderFlow')
        except BufferUnderflowError:
            pass
        
        b.clear()
        b.write_bytes('line1\nline2\r\nline3\nline4\r\n')
        b.flip()
        self.assertEquals('line1', b.read_line())
        self.assertEquals('line2', b.read_line())
        self.assertEquals('line3', b.read_line())
        self.assertEquals('line4', b.read_line())
        self.assertEquals(b.position, b.limit)
        
        b.clear()
        b.write_bytes('line1\nline2\r\nline3\nline4\r\n')
        b.flip()
        self.assertEquals('line1\n', b.read_line(True))
        self.assertEquals('line2\r\n', b.read_line(True))
        self.assertEquals('line3\n', b.read_line(True))
        self.assertEquals('line4\r\n', b.read_line(True))
        self.assertEquals(b.position, b.limit)
コード例 #4
0
    def testReadLine(self):
        b = Buffer(1024)

        b.clear()
        b.write_bytes('hello world!\n')
        b.flip()
        self.assertEquals('hello world!', b.read_line())
        self.assertEquals(b.position, b.limit)

        b.clear()
        b.write_bytes('hello world!\r\n')
        b.flip()
        self.assertEquals('hello world!', b.read_line())
        self.assertEquals(b.position, b.limit)

        b.clear()
        b.write_bytes('hello world!\r')
        b.flip()
        try:
            b.read_line()
            self.fail('expected BufferUnderFlow')
        except BufferUnderflowError:
            pass

        b.clear()
        b.write_bytes('hello world!\n')
        b.flip()
        self.assertEquals('hello world!\n', b.read_line(True))
        self.assertEquals(b.position, b.limit)

        b.clear()
        b.write_bytes('hello world!\r\n')
        b.flip()
        self.assertEquals('hello world!\r\n', b.read_line(True))
        self.assertEquals(b.position, b.limit)

        b.clear()
        b.write_bytes('hello world!\r')
        b.flip()
        try:
            b.read_line(True)
            self.fail('expected BufferUnderFlow')
        except BufferUnderflowError:
            pass

        b.clear()
        b.write_bytes('line1\nline2\r\nline3\nline4\r\n')
        b.flip()
        self.assertEquals('line1', b.read_line())
        self.assertEquals('line2', b.read_line())
        self.assertEquals('line3', b.read_line())
        self.assertEquals('line4', b.read_line())
        self.assertEquals(b.position, b.limit)

        b.clear()
        b.write_bytes('line1\nline2\r\nline3\nline4\r\n')
        b.flip()
        self.assertEquals('line1\n', b.read_line(True))
        self.assertEquals('line2\r\n', b.read_line(True))
        self.assertEquals('line3\n', b.read_line(True))
        self.assertEquals('line4\r\n', b.read_line(True))
        self.assertEquals(b.position, b.limit)