Пример #1
0
 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))
Пример #2
0
 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)
Пример #3
0
 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
Пример #4
0
 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))
Пример #5
0
 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))
Пример #6
0
 def test_add_data(self):
     assert_equal(True, self.sizedParserBuffer.add_data(IOBuffer('hello')))
     assert_equal('hell', self.sizedParserBuffer.result)
Пример #7
0
 def test_simple_strings_parser(self):
     data = IOBuffer('+OK\r\n')
     assert_equal('OK', self.parser.parser(data))
Пример #8
0
 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)
Пример #9
0
 def test_remaining(self):
     assert_equal(False, self.sizedParserBuffer.add_data(IOBuffer('hel')))
     assert_equal(1, self.sizedParserBuffer.remaining)
Пример #10
0
 def test_parser(self):
     data = IOBuffer('hello world')
     assert_equal('o wo', self.parser.parser(data))
     assert_equal(Uncomplete(), self.parser.parser(data))
Пример #11
0
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)
Пример #12
0
 def test_take_copy(self):
     assert_equal(IOBuffer('hello world'), self.iobuffer.take_copy)
Пример #13
0
 def test_integers_parser(self):
     data = IOBuffer(':0\r\n')
     assert_equal(0, self.parser.parser(data))
Пример #14
0
 def test_errors_parser(self):
     data = IOBuffer('-Error message\r\n')
     assert_equal('Error message', self.parser.parser(data))
Пример #15
0
 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))
Пример #16
0
 def test_received(self):
     assert_equal(False, self.sizedParserBuffer.add_data(IOBuffer('hel')))
     assert_equal(3, self.sizedParserBuffer.received)
Пример #17
0
 def setUp(self):
     self.iobuffer = IOBuffer('hello world')
Пример #18
0
 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))
Пример #19
0
 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)
Пример #20
0
 def test_parser(self):
     data1 = IOBuffer('hel')
     assert_equal(Uncomplete(), self.parser.parser(data1))
     data2 = IOBuffer('l')
     assert_equal('ll', self.parser.parser(data2))
Пример #21
0
 def test_reset(self):
     self.unsizedParserBufferSkiped.add_data(IOBuffer("somef"))
     self.unsizedParserBufferSkiped.reset()
     assert_equal(self.unsizedParserBufferSkiped,
                  UnsizedParserBuffer("foo", False, 2))
Пример #22
0
 def test_reset(self):
     self.sizedParserBuffer.add_data(IOBuffer('hel'))
     self.sizedParserBuffer.reset()
     assert_equal(self.sizedParserBuffer, SizedParserBuffer(4))
Пример #23
0
 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))
Пример #24
0
 def test_reset(self):
     self.unsizedParserBufferIncludeTerminal.add_data(IOBuffer("somef"))
     self.unsizedParserBufferIncludeTerminal.reset()
     assert_equal(self.unsizedParserBufferIncludeTerminal,
                  UnsizedParserBuffer("foo", True))
Пример #25
0
 def test_parser(self):
     data = IOBuffer('bar')
     assert_equal((), self.parser.parser(data))