本文整理汇总了Python中test_utils.TestUtils类的典型用法代码示例。如果您正苦于以下问题:Python TestUtils类的具体用法?Python TestUtils怎么用?Python TestUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: echo
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)
示例2: test_hash
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()
示例3: 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()
示例4: 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()
示例5: client_connect_handler
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)
示例6: open_handler
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)
示例7: end_handler
def end_handler(stream):
tu.azzert(TestUtils.buffers_equal(tot_buff, tot_read))
tu.check_context
def close_handler2(err, result):
tu.check_context()
tu.test_complete()
file.close(close_handler2)
示例8: 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()
示例9: 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)
示例10: read_handler
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)
示例11: 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()
tu.azzert(resp.headers.is_empty)
tu.test_complete()
示例12: listen_handler
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)
示例13: client_connect_handler
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)
示例14: peer2_listen_handler
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)
示例15: test_echo
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)