def test_bulk_strings_parser(self): # data = IOBuffer('$-1\r\n') # assert_equal(None, self.parser.parser(data)) data = IOBuffer('$0\r\n\r\n') assert_equal('', self.parser.parser(data)) data = IOBuffer('$6\r\nfoobar\r\n') assert_equal('foobar', self.parser.parser(data))
def test_add_data(self): assert_equal( False, self.unsizedParserBufferIncludeTerminal.add_data( IOBuffer("somef"))) assert_equal( True, self.unsizedParserBufferIncludeTerminal.add_data(IOBuffer("oos"))) assert_equal("somefoo", self.unsizedParserBufferIncludeTerminal.result)
def __call__(self, data): if (self.buffer is None): self.buffer = IOBuffer(data) else: self.buffer = IOBuffer(self.buffer.take_all + data) while 1: result = self.parser.parser(self.buffer) if result is not Uncomplete(): self.callback(result) else: break
def test_array_string_parser(self): unexist_data = IOBuffer('*-1\r\n') assert_equal(None, self.parser.parser(unexist_data)) # empty array data0 = IOBuffer('*0\r\n') assert_equal((), self.parser.parser(data0)) # array with 1 element data1 = IOBuffer('*1\r\n$3\r\nfoo\r\n') assert_equal(('foo',), self.parser.parser(data1)) # array with >1 element data2 = IOBuffer('*2\r\n$3\r\nfoo\r\n$3\r\n') assert_equal(Uncomplete(), self.parser.parser(data2)) data3 = IOBuffer('bar\r\n') assert_equal(('foo', 'bar'), self.parser.parser(data3))
def test_parser(self): data1 = IOBuffer('\xff\xff\xff\xff') assert_equal(Uncomplete(), self.parser.parser(data1)) data2 = IOBuffer('\xff\xff\xff\xff') assert_equal(2**64 - 1, self.parser.parser(data2))
def test_add_data(self): assert_equal(True, self.sizedParserBuffer.add_data(IOBuffer('hello'))) assert_equal('hell', self.sizedParserBuffer.result)
def test_simple_strings_parser(self): data = IOBuffer('+OK\r\n') assert_equal('OK', self.parser.parser(data))
def test_is_finished(self): assert_equal(False, self.sizedParserBuffer.add_data(IOBuffer('hel'))) assert_equal(False, self.sizedParserBuffer.is_finished) assert_equal(True, self.sizedParserBuffer.add_data(IOBuffer('lo'))) assert_equal(True, self.sizedParserBuffer.is_finished)
def test_remaining(self): assert_equal(False, self.sizedParserBuffer.add_data(IOBuffer('hel'))) assert_equal(1, self.sizedParserBuffer.remaining)
def test_parser(self): data = IOBuffer('hello world') assert_equal('o wo', self.parser.parser(data)) assert_equal(Uncomplete(), self.parser.parser(data))
class TestIOBuffer(object): def setUp(self): self.iobuffer = IOBuffer('hello world') def test_next(self): assert_equal('h', self.iobuffer.next) def test_skip(self): self.iobuffer.skip(1) assert_equal(10, self.iobuffer.remaining) self.iobuffer.skip(12) assert_equal(0, self.iobuffer.remaining) def test_skip_all(self): self.iobuffer.skip_all() assert_equal(0, self.iobuffer.remaining) def test_take(self): assert_equal('hello', self.iobuffer.take(5)) def test_take_all(self): assert_equal('hello world', self.iobuffer.take_all) def test_take_copy(self): assert_equal(IOBuffer('hello world'), self.iobuffer.take_copy) def test_remaining(self): self.iobuffer.take(5) assert_equal(6, self.iobuffer.remaining) def test_has_next(self): self.iobuffer.take(6) assert_equal(True, self.iobuffer.has_next) self.iobuffer.take(5) assert_equal(False, self.iobuffer.has_next) def test_taken(self): self.iobuffer.take(5) assert_equal(5, self.iobuffer.taken) def test_write_to(self): class MockTransport(object): def write(self, data): return len(data) self.iobuffer.write_to(MockTransport()) assert_equal(0, self.iobuffer.remaining)
def test_take_copy(self): assert_equal(IOBuffer('hello world'), self.iobuffer.take_copy)
def test_integers_parser(self): data = IOBuffer(':0\r\n') assert_equal(0, self.parser.parser(data))
def test_errors_parser(self): data = IOBuffer('-Error message\r\n') assert_equal('Error message', self.parser.parser(data))
def test_parser(self): data1 = IOBuffer("hello") assert_equal(Uncomplete(), self.parser.parser(data1)) data2 = IOBuffer("\nworld\n") assert_equal('hello', self.parser.parser(data2)) assert_equal('world', self.parser.parser(data2))
def test_received(self): assert_equal(False, self.sizedParserBuffer.add_data(IOBuffer('hel'))) assert_equal(3, self.sizedParserBuffer.received)
def setUp(self): self.iobuffer = IOBuffer('hello world')
def test_parser(self): data1 = IOBuffer('h') assert_equal(Uncomplete(), self.parser.parser(data1)) data2 = IOBuffer('ello world') assert_equal('hehehe', self.parser.parser(data2))
def test_add_data(self): assert_equal( False, self.unsizedParserBufferSkiped.add_data(IOBuffer("somef"))) assert_equal(True, self.unsizedParserBufferSkiped.add_data(IOBuffer("oos"))) assert_equal("me", self.unsizedParserBufferSkiped.result)
def test_parser(self): data1 = IOBuffer('hel') assert_equal(Uncomplete(), self.parser.parser(data1)) data2 = IOBuffer('l') assert_equal('ll', self.parser.parser(data2))
def test_reset(self): self.unsizedParserBufferSkiped.add_data(IOBuffer("somef")) self.unsizedParserBufferSkiped.reset() assert_equal(self.unsizedParserBufferSkiped, UnsizedParserBuffer("foo", False, 2))
def test_reset(self): self.sizedParserBuffer.add_data(IOBuffer('hel')) self.sizedParserBuffer.reset() assert_equal(self.sizedParserBuffer, SizedParserBuffer(4))
def test_parser(self): data = IOBuffer('hi') assert_equal('h', self.parser.parser(data)) assert_equal('i', self.parser.parser(data)) assert_equal(Uncomplete(), self.parser.parser(data))
def test_reset(self): self.unsizedParserBufferIncludeTerminal.add_data(IOBuffer("somef")) self.unsizedParserBufferIncludeTerminal.reset() assert_equal(self.unsizedParserBufferIncludeTerminal, UnsizedParserBuffer("foo", True))
def test_parser(self): data = IOBuffer('bar') assert_equal((), self.parser.parser(data))