当前位置: 首页>>代码示例>>Python>>正文


Python TestUtils.gen_buffer方法代码示例

本文整理汇总了Python中test_utils.TestUtils.gen_buffer方法的典型用法代码示例。如果您正苦于以下问题:Python TestUtils.gen_buffer方法的具体用法?Python TestUtils.gen_buffer怎么用?Python TestUtils.gen_buffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在test_utils.TestUtils的用法示例。


在下文中一共展示了TestUtils.gen_buffer方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: echo

# 需要导入模块: from test_utils import TestUtils [as 别名]
# 或者: from test_utils.TestUtils import gen_buffer [as 别名]
    def echo(self, binary):
        @server.websocket_handler
        def websocket_handler(ws):
            tu.check_context()
            @ws.data_handler
            def data_handler(buff):
                tu.check_context()
                ws.write_buffer(buff)
            
        server.listen(8080)

        if binary:
            self.buff = TestUtils.gen_buffer(1000)
        else:
            self.str_ = TestUtils.random_unicode_string(1000)

        def connect_handler(ws):
            tu.check_context()
            received = Buffer.create()

            @ws.data_handler
            def data_handler(buff):
                tu.check_context()
                received.append_buffer(buff)
                if received.length == buff.length:
                    tu.azzert(TestUtils.buffers_equal(buff, received))
                    tu.test_complete()
        
            if binary:
                ws.write_binary_frame(self.buff)
            else:
                ws.write_text_frame(self.str_)
        client.connect_web_socket("/someurl", connect_handler)
开发者ID:Findekano,项目名称:vert.x,代码行数:35,代码来源:test_client.py

示例2: open_handler

# 需要导入模块: from test_utils import TestUtils [as 别名]
# 或者: from test_utils.TestUtils import gen_buffer [as 别名]
 def open_handler(err, file):
     tu.check_context()
     tu.azzert(err == None)
     num_chunks = 100;
     chunk_size = 1000;
     tot_buff = Buffer.create()
     self.written = 0
     for i in range(0, num_chunks):
         buff = TestUtils.gen_buffer(chunk_size)
         tot_buff.append_buffer(buff)
         def write_handler(err, res):
             tu.check_context()
             self.written += 1
             if self.written == num_chunks:
               # all written
               tot_read = Buffer.create()
               self.read = 0
               for j in range(0, num_chunks):
                 pos = j * chunk_size
                 def read_handler(err, buff):
                     tu.check_context
                     tu.azzert(err == None)
                     self.read += 1
                     if self.read == num_chunks:
                         # all read
                         tu.azzert(TestUtils.buffers_equal(tot_buff, tot_read))
                         def close_handler(err, res):
                             tu.check_context()
                             tu.test_complete()
                         file.close(close_handler)
                 file.read(tot_read, pos, pos, chunk_size, read_handler)
         file.write(buff, i * chunk_size, write_handler)
开发者ID:aaronwalker,项目名称:vert.x,代码行数:34,代码来源:test_client.py

示例3: client_connect_handler

# 需要导入模块: from test_utils import TestUtils [as 别名]
# 或者: from test_utils.TestUtils import gen_buffer [as 别名]
        def client_connect_handler(socket):
            tu.check_context()
            sends = 10
            size = 100

            sent = Buffer.create()
            received = Buffer.create()

            @socket.data_handler
            def data_handler(data):
                tu.check_context()
                received.append_buffer(data)
                if received.length == sends * size:
                    tu.azzert(TestUtils.buffers_equal(sent, received))
                    tu.test_complete()
            @socket.drain_handler
            def drain_handler(stream):
                tu.check_context()
                #print "drained\n"

            @socket.end_handler
            def end_handler(stream):
                tu.check_context()
                #print "end\n"

            socket.pause()
            socket.resume()
            socket.write_queue_full
            socket.write_queue_max_size = 100000

            for i in range(0, sends):
                data = TestUtils.gen_buffer(size)
                sent.append_buffer(data)
                socket.write_buffer(data)
开发者ID:Findekano,项目名称:vert.x,代码行数:36,代码来源:test_client.py

示例4: test_hash

# 需要导入模块: from test_utils import TestUtils [as 别名]
# 或者: from test_utils.TestUtils import gen_buffer [as 别名]
    def test_hash(self):
        hash1 = SharedData.get_hash("map1")
        tu.azzert(hash1 != None)
        hash2 = SharedData.get_hash("map1")
        tu.azzert(hash2 != None)

        tu.azzert(hash1 == hash2)

        hash3 = SharedData.get_hash("map3")
        tu.azzert(hash3 != None)
        tu.azzert(hash1 != hash3)

        key = 'wibble'

        hash1[key] = 'hello'

        tu.azzert(hash1[key] == 'hello')
        tu.azzert(hash2[key] == 'hello')
        tu.azzert(isinstance(hash1[key], unicode)) # Make sure it's not a Java String

        hash1[key] = 12
        tu.azzert(hash1[key] == 12)
        tu.azzert(hash2[key] == 12)

        hash1[key] = 1.2344
        tu.azzert(hash1[key] == 1.2344)
        tu.azzert(hash2[key] == 1.2344)

        hash1[key] = True
        tu.azzert(hash1[key] == True)
        tu.azzert(hash2[key] == True)

        hash1[key] = False
        tu.azzert(hash1[key] == False)
        tu.azzert(hash2[key] == False)

        succeeded = False
        try:
            hash1[key] = SomeOtherClass()
            succeeded = True
        except:
            pass # OK
          
        tu.azzert(not succeeded, 'Should throw exception')

        # Make sure it deals with Ruby buffers ok, and copies them
        buff1 = TestUtils.gen_buffer(100)
        hash1[key] = buff1
        buff2 = hash1[key]
        tu.azzert(isinstance(buff2, Buffer))
        tu.azzert(buff1 != buff2)
        tu.azzert(TestUtils.buffers_equal(buff1, buff2))

        tu.azzert(SharedData.remove_hash("map1"))
        tu.azzert(not SharedData.remove_hash("map1"))
        tu.azzert(SharedData.remove_hash("map3"))
        tu.test_complete()
开发者ID:aaronwalker,项目名称:vert.x,代码行数:59,代码来源:test_client.py

示例5: listen_handler

# 需要导入模块: from test_utils import TestUtils [as 别名]
# 或者: from test_utils.TestUtils import gen_buffer [as 别名]
        def listen_handler(err, sock):
            tu.azzert(err is None)
            tu.azzert(sock == peer2)
            buffer = TestUtils.gen_buffer(128)

            @peer2.data_handler
            def data_handler(data):
                tu.check_thread()
                tu.azzert(TestUtils.buffers_equal(buffer, data.data))
                tu.test_complete()

            def send_handler(err, sock):
                tu.check_thread()
                tu.azzert(err is None)
                tu.azzert(sock == peer1)

            peer1.send('255.255.255.255', 1234, buffer, send_handler)
开发者ID:fregaham,项目名称:mod-lang-jython,代码行数:19,代码来源:test_client.py

示例6: client_connect_handler

# 需要导入模块: from test_utils import TestUtils [as 别名]
# 或者: from test_utils.TestUtils import gen_buffer [as 别名]
        def client_connect_handler(err, socket):
            tu.azzert(err == None)
            tu.check_thread()
            tu.azzert(socket.local_address[0] is not None)
            tu.azzert(socket.local_address[1] > -1)
            tu.azzert(socket.remote_address[0] is not None)
            tu.azzert(socket.remote_address[1] > -1)

            sends = 10
            size = 100

            sent = Buffer.create()
            received = Buffer.create()

            @socket.data_handler
            def data_handler(data):
                tu.check_thread()
                received.append_buffer(data)

                if received.length == sends * size:
                    tu.azzert(TestUtils.buffers_equal(sent, received))
                    tu.test_complete()

            #Just call the methods. Real testing is done in java tests
            @socket.drain_handler
            def drain_handler():
                tu.check_thread()

            @socket.end_handler
            def end_handler():
                tu.check_thread()

            @socket.close_handler
            def close_handler():
                tu.check_thread()

            socket.pause()
            socket.resume()
            socket.write_queue_full
            socket.write_queue_max_size = 100000

            for i in range(0, sends):
                data = TestUtils.gen_buffer(size)
                sent.append_buffer(data)
                socket.write(data)
开发者ID:fregaham,项目名称:mod-lang-jython,代码行数:47,代码来源:test_client.py

示例7: peer2_listen_handler

# 需要导入模块: from test_utils import TestUtils [as 别名]
# 或者: from test_utils.TestUtils import gen_buffer [as 别名]
        def peer2_listen_handler(err, serv):
            tu.check_thread()
            tu.azzert(err is None)
            tu.azzert(serv == peer2)
            buffer = TestUtils.gen_buffer(128)

            @peer2.data_handler
            def data_handler(data):
                tu.check_thread()
                tu.azzert(TestUtils.buffers_equal(buffer, data.data))
                tu.test_complete()


            def send_handler(err, result):
                tu.check_thread()
                tu.azzert(err is None)
                tu.azzert(result == peer1)

            peer1.send('127.0.0.1', 1234, buffer, send_handler)
开发者ID:fregaham,项目名称:mod-lang-jython,代码行数:21,代码来源:test_client.py

示例8: test_echo

# 需要导入模块: from test_utils import TestUtils [as 别名]
# 或者: from test_utils.TestUtils import gen_buffer [as 别名]
    def test_echo(self):
        @peer1.exception_handler
        def exception_handler(err):
            tu.azzert(False)

        @peer2.exception_handler
        def exception_handler(err):
            tu.azzert(False)

        buffer = TestUtils.gen_buffer(128)

        def peer2_listen_handler(err, sock):
            @peer2.data_handler
            def data_handler(data):
                tu.check_thread()
                tu.azzert(TestUtils.buffers_equal(buffer, data.data))

                def send_handler(err, sock):
                    tu.check_thread()
                    tu.azzert(err is None)
                    tu.azzert(sock == peer2)

                peer2.send('127.0.0.1', 1235, data.data, send_handler)


            def peer1_listen_handler(err, sock):
                @peer1.data_handler
                def data_handler(data):
                    tu.check_thread()
                    tu.azzert(TestUtils.buffers_equal(buffer, data.data))
                    tu.test_complete()

                def send_handler(err, sock):
                    tu.check_thread()
                    tu.azzert(err is None)
                    tu.azzert(sock ==  peer1)

                peer1.send('127.0.0.1', 1234, buffer, send_handler)
            peer1.listen(1235, '127.0.0.1', peer1_listen_handler)

        peer2.listen(1234, '127.0.0.1', peer2_listen_handler)
开发者ID:fregaham,项目名称:mod-lang-jython,代码行数:43,代码来源:test_client.py

示例9: http_method

# 需要导入模块: from test_utils import TestUtils [as 别名]
# 或者: from test_utils.TestUtils import gen_buffer [as 别名]
def http_method(ssl, method, chunked):

    logger.info("in http method %s"% method)

    if ssl:
        server.ssl = True
        server.key_store_path = './src/test/keystores/server-keystore.jks'
        server.key_store_password = 'wibble'
        server.trust_store_path = './src/test/keystores/server-truststore.jks'
        server.trust_store_password = 'wibble'
        server.client_auth_required = True

    path = "/someurl/blah.html"
    query = "param1=vparam1&param2=vparam2"
    uri = "http://localhost:8080" + path + "?" + query;

    @server.request_handler
    def request_handler(req):
        tu.check_context()
        tu.azzert(req.uri == uri)
        tu.azzert(req.method == method)
        tu.azzert(req.path == path)
        tu.azzert(req.query == query)
        tu.azzert(req.headers['header1'] == 'vheader1')
        tu.azzert(req.headers['header2'] == 'vheader2')
        tu.azzert(req.params['param1'] == 'vparam1')
        tu.azzert(req.params['param2'] == 'vparam2')
        req.response.put_header('rheader1', 'vrheader1')
        req.response.put_header('rheader2', 'vrheader2')
        body = Buffer.create()

        @req.data_handler
        def data_handler(data):
            tu.check_context()
            body.append_buffer(data)
        req.response.chunked = chunked

        @req.end_handler
        def end_handler(stream):
            tu.check_context()
            if not chunked:
                req.response.put_header('Content-Length', body.length)
            req.response.write_buffer(body)
            if chunked:
                req.response.put_trailer('trailer1', 'vtrailer1')
                req.response.put_trailer('trailer2', 'vtrailer2')
            req.response.end()

    server.listen(8080)

    if ssl:
        client.ssl = True
        client.key_store_path = './src/test/keystores/client-keystore.jks'
        client.key_store_password = 'wibble'
        client.trust_store_path = './src/test/keystores/client-truststore.jks'
        client.trust_store_password = 'wibble'

    sent_buff = TestUtils.gen_buffer(1000)

    def response_handler(resp):
        tu.check_context()
        tu.azzert(200 == resp.status_code)
        tu.azzert('vrheader1' == resp.headers['rheader1'])
        tu.azzert('vrheader2' == resp.headers['rheader2'])
        body = Buffer.create()
        
        @resp.data_handler
        def data_handler(data):
            tu.check_context()
            body.append_buffer(data)

        @resp.end_handler
        def end_handler(stream):
            tu.check_context()
            tu.azzert(TestUtils.buffers_equal(sent_buff, body))
            if chunked:
                tu.azzert('vtrailer1' == resp.trailers['trailer1'])
                tu.azzert('vtrailer2' == resp.trailers['trailer2'])
            tu.test_complete()

    request = client.request(method, uri, response_handler)
    
    request.chunked = chunked
    request.put_header('header1', 'vheader1')
    request.put_header('header2', 'vheader2')
    if not chunked:
        request.put_header('Content-Length', sent_buff.length) 

    request.write_buffer(sent_buff)
    request.end()
开发者ID:Findekano,项目名称:vert.x,代码行数:92,代码来源:test_client.py

示例10: http_method

# 需要导入模块: from test_utils import TestUtils [as 别名]
# 或者: from test_utils.TestUtils import gen_buffer [as 别名]
def http_method(ssl, method, chunked):

    logger.info("in http method %s" % method)

    if ssl:
        server.ssl = True
        server.key_store_path = "./src/test/keystores/server-keystore.jks"
        server.key_store_password = "wibble"
        server.trust_store_path = "./src/test/keystores/server-truststore.jks"
        server.trust_store_password = "wibble"
        server.client_auth_required = True

    path = "/someurl/blah.html"
    query = "param1=vparam1&param2=vparam2"
    uri = "http://localhost:8080" + path + "?" + query

    @server.request_handler
    def request_handler(req):
        tu.check_context()
        tu.azzert(req.uri == uri)
        tu.azzert(req.method == method)
        tu.azzert(req.path == path)
        tu.azzert(req.query == query)
        tu.azzert(req.headers["header1"] == "vheader1")
        tu.azzert(req.headers["header2"] == "vheader2")
        tu.azzert(req.params["param1"] == "vparam1")
        tu.azzert(req.params["param2"] == "vparam2")
        req.response.put_header("rheader1", "vrheader1")
        req.response.put_header("rheader2", "vrheader2")
        body = Buffer.create()

        @req.data_handler
        def data_handler(data):
            tu.check_context()
            body.append_buffer(data)

        req.response.chunked = chunked

        @req.end_handler
        def end_handler(stream):
            tu.check_context()
            if method != "HEAD" and method != "CONNECT":
                if not chunked:
                    req.response.put_header("Content-Length", body.length)
                req.response.write_buffer(body)
                if chunked:
                    req.response.put_trailer("trailer1", "vtrailer1")
                    req.response.put_trailer("trailer2", "vtrailer2")
            req.response.end()

    server.listen(8080)

    if ssl:
        client.ssl = True
        client.key_store_path = "./src/test/keystores/client-keystore.jks"
        client.key_store_password = "wibble"
        client.trust_store_path = "./src/test/keystores/client-truststore.jks"
        client.trust_store_password = "wibble"

    sent_buff = TestUtils.gen_buffer(1000)

    def response_handler(resp):
        tu.check_context()
        tu.azzert(200 == resp.status_code)
        tu.azzert("vrheader1" == resp.headers["rheader1"])
        tu.azzert("vrheader2" == resp.headers["rheader2"])
        body = Buffer.create()

        @resp.data_handler
        def data_handler(data):
            tu.check_context()
            body.append_buffer(data)

        @resp.end_handler
        def end_handler(stream):
            tu.check_context()
            if method != "HEAD" and method != "CONNECT":
                tu.azzert(TestUtils.buffers_equal(sent_buff, body))
                if chunked:
                    tu.azzert("vtrailer1" == resp.trailers["trailer1"])
                    tu.azzert("vtrailer2" == resp.trailers["trailer2"])
            tu.test_complete()

    request = client.request(method, uri, response_handler)

    request.chunked = chunked
    request.put_header("header1", "vheader1")
    request.put_header("header2", "vheader2")
    if not chunked:
        request.put_header("Content-Length", sent_buff.length)

    request.write_buffer(sent_buff)
    request.end()
开发者ID:jdonnerstag,项目名称:vert.x,代码行数:95,代码来源:test_client.py

示例11: create_buffer

# 需要导入模块: from test_utils import TestUtils [as 别名]
# 或者: from test_utils.TestUtils import gen_buffer [as 别名]
 def create_buffer(self, len):
     return TestUtils.gen_buffer(len)
开发者ID:aaronwalker,项目名称:vert.x,代码行数:4,代码来源:test_client.py

示例12: http_method

# 需要导入模块: from test_utils import TestUtils [as 别名]
# 或者: from test_utils.TestUtils import gen_buffer [as 别名]
def http_method(ssl, method, chunked):

    logger.info("in http method %s"% method)

    server.compression_supported = True
    tu.azzert(server.compression_supported)

    if ssl:
        server.ssl = True
        server.key_store_path = './src/test/keystores/server-keystore.jks'
        server.key_store_password = 'wibble'
        server.trust_store_path = './src/test/keystores/server-truststore.jks'
        server.trust_store_password = 'wibble'
        server.client_auth_required = True

    path = "/someurl/blah.html"
    query = "param1=vparam1&param2=vparam2"
    uri = "http://localhost:8080" + path + "?" + query;

    @server.request_handler
    def request_handler(req):
        tu.check_thread()
        tu.azzert(req.version == 'HTTP_1_1')
        tu.azzert(req.uri == uri)
        tu.azzert(req.method == method)
        tu.azzert(req.path == path)
        tu.azzert(req.query == query)
        tu.azzert(req.headers['header1'] == 'vheader1')
        tu.azzert(req.headers['header2'] == 'vheader2')
        tu.azzert(req.params['param1'] == 'vparam1')
        tu.azzert(req.params['param2'] == 'vparam2')


        headers = req.headers
        tu.azzert(headers.contains('header1'))
        tu.azzert(headers.contains('header2'))
        tu.azzert(headers.contains('header3'))
        tu.azzert(not headers.is_empty)

        headers.remove('header3')
        tu.azzert(not headers.contains('header3'))

        req.response.put_header('rheader1', 'vrheader1')
        req.response.put_header('rheader2', 'vrheader2')
        body = Buffer.create()

        @req.data_handler
        def data_handler(data):
            tu.check_thread()
            body.append_buffer(data)

        if method != 'HEAD' and method != 'CONNECT':
            req.response.chunked = chunked

        @req.end_handler
        def end_handler():
            tu.check_thread()
            if method != 'HEAD' and method != 'CONNECT':
                if not chunked:
                    req.response.put_header('Content-Length', str(body.length))
                req.response.write(body)
                if chunked:
                    req.response.put_trailer('trailer1', 'vtrailer1')
                    req.response.put_trailer('trailer2', 'vtrailer2')
            req.response.end()

    client.try_use_compression = False
    tu.azzert(client.try_use_compression == False)

    if ssl:
        client.ssl = True
        client.key_store_path = './src/test/keystores/client-keystore.jks'
        client.key_store_password = 'wibble'
        client.trust_store_path = './src/test/keystores/client-truststore.jks'
        client.trust_store_password = 'wibble'

    sent_buff = TestUtils.gen_buffer(1000)

    def response_handler(resp):
        tu.check_thread()
        tu.azzert(200 == resp.status_code)
        tu.azzert('vrheader1' == resp.headers['rheader1'])
        tu.azzert('vrheader2' == resp.headers['rheader2'])
        body = Buffer.create()
        
        @resp.data_handler
        def data_handler(data):
            tu.check_thread()
            body.append_buffer(data)

        @resp.end_handler
        def end_handler():
            tu.check_thread()
            if method != 'HEAD' and method != 'CONNECT':
                tu.azzert(TestUtils.buffers_equal(sent_buff, body))
                if chunked:
                    tu.azzert('vtrailer1' == resp.trailers['trailer1'])
                    tu.azzert('vtrailer2' == resp.trailers['trailer2'])

            resp.headers.clear()
#.........这里部分代码省略.........
开发者ID:fregaham,项目名称:mod-lang-jython,代码行数:103,代码来源:test_client.py

示例13: test_set

# 需要导入模块: from test_utils import TestUtils [as 别名]
# 或者: from test_utils.TestUtils import gen_buffer [as 别名]
    def test_set(self):
        set1 = SharedData.get_set("set1")
        tu.azzert(set1 != None)

        set2 = SharedData.get_set("set1")
        tu.azzert(set2 != None)

        tu.azzert(set1 == set2)

        set3 = SharedData.get_set("set3")
        tu.azzert(set3 != None)

        tu.azzert(set1 != set3)

        set1.add("foo")
        set1.add("bar")
        set1.add("quux")

        tu.azzert(3 == len(set1))

        tu.azzert("foo" in set1)
        tu.azzert("bar" in set1)
        tu.azzert("quux" in set1)
        tu.azzert(not ("wibble" in set1))
        tu.azzert(not set1.empty())

        set1.delete("foo")
        tu.azzert(2 == len(set1))
        tu.azzert(2 == set1.size())
        tu.azzert(not ("foo" in set1))
        tu.azzert("bar" in set1)
        tu.azzert("quux" in set1)
        tu.azzert(not set1.empty())

        set1.clear()
        tu.azzert(set1.empty())

        set1.add("foo")
        set1.add("bar")
        set1.add("quux")

        set2 = set()

        @set1.each
        def each(o):
            set2.add(o)
    
        tu.azzert("foo" in set2)
        tu.azzert("bar" in set2)
        tu.azzert("quux" in set2)

        set1.clear()
        set1.add(12)
        @set1.each
        def each2(elem):
            tu.azzert(elem == 12)

        set1.clear()
        set1.add(1.234)
        @set1.each
        def each3(elem):
            tu.azzert(elem == 1.234)

        set1.clear()
        set1.add("foo")
        @set1.each
        def each4(elem):
            tu.azzert(elem == "foo")
            tu.azzert(isinstance(elem, unicode))
        
        set1.clear()
        set1.add(True)
        @set1.each
        def each5(elem):
            tu.azzert(elem == True)

        set1.clear()
        set1.add(False)
        @set1.each
        def each6(elem):
            tu.azzert(elem == False)

        buff = TestUtils.gen_buffer(100)
        set1.clear()
        set1.add(buff)
        @set1.each
        def each7(elem):
            tu.azzert(TestUtils.buffers_equal(buff, elem))
            tu.azzert(buff != elem)
            tu.azzert(isinstance(elem, Buffer))

        set1.clear()
        succeeded = False
        try:
            set1.add(SomeOtherClass())
            succeeded = True
        except: 
            pass # OK
    
        tu.azzert(not succeeded, 'Should throw exception')
#.........这里部分代码省略.........
开发者ID:aaronwalker,项目名称:vert.x,代码行数:103,代码来源:test_client.py


注:本文中的test_utils.TestUtils.gen_buffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。