本文整理汇总了Python中testrunner.run函数的典型用法代码示例。如果您正苦于以下问题:Python run函数的具体用法?Python run怎么用?Python run使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了run函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testfunc
#!/usr/bin/env python3
import os
import sys
def testfunc(child):
child.expect_exact('- User: johndoe')
child.expect_exact('- Admin: false')
child.expect_exact('- UID: 1000')
child.expect_exact('- Groups:')
child.expect_exact(' * users')
child.expect_exact(' * wheel')
child.expect_exact(' * audio')
child.expect_exact(' * video')
if __name__ == "__main__":
sys.path.append(os.path.join(os.environ['RIOTTOOLS'], 'testrunner'))
from testrunner import run
sys.exit(run(testfunc))
示例2: Copyright
#!/usr/bin/env python3
# Copyright (C) 2016 Freie Universität Berlin
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
import sys
from testrunner import run
def testfunc(child):
child.expect(r"TRACE_SIZE: (\d+)")
trace_size = int(child.match.group(1))
for i in range(trace_size):
child.expect("0x[0-9a-f]{7,8}")
print("All tests successful")
if __name__ == "__main__":
sys.exit(run(testfunc, timeout=1, echo=True, traceback=True))
示例3: Copyright
#!/usr/bin/env python3
# Copyright (C) 2019 Freie Universität Berlin
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
import sys
from testrunner import run
from pexpect import TIMEOUT
def testfunc(child):
res = child.expect([TIMEOUT, "Message was not written"])
# we actually want the timeout here. The application runs into an assertion
# pretty quickly when failing and runs forever on success
assert(res == 0)
if __name__ == "__main__":
sys.exit(run(testfunc, timeout=10))
示例4: log_request
"reason",
self.responses.get(
status,
(
"fail requested",
"Your request specified failure status %s " "without providing a reason" % status,
),
)[1],
)
self.send_error(status, reason)
def log_request(self, code, size=None):
# For present purposes, we don't want the request splattered onto
# stderr, as it would upset devs watching the test run
pass
def log_error(self, format, *args):
# Suppress error output as well
pass
class TestHTTPServer(Thread):
def run(self):
httpd = HTTPServer(("127.0.0.1", 8000), TestHTTPRequestHandler)
debug("Starting HTTP server...\n")
httpd.serve_forever()
if __name__ == "__main__":
sys.exit(run(server=TestHTTPServer(name="httpd"), *sys.argv[1:]))
示例5: assert
data, addr = s.recvfrom(RCVBUF_LEN)
assert(len(data) == (ZEP_DATA_HEADER_SIZE + len("Hello\0World\0") + FCS_LEN))
assert(b"Hello\0World\0" == data[ZEP_DATA_HEADER_SIZE:-2])
child.expect_exact("Waiting for an incoming message (use `make test`)")
s.sendto(b"\x45\x58\x02\x01\x1a\x44\xe0\x01\xff\xdb\xde\xa6\x1a\x00\x8b" +
b"\xfd\xae\x60\xd3\x21\xf1\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
b"\x00\x22\x41\xdc\x02\x23\x00\x38\x30\x00\x0a\x50\x45\x5a\x00" +
b"\x5b\x45\x00\x0a\x50\x45\x5a\x00Hello World\x3a\xf2",
("::1", zep_params['local_port']))
child.expect(r"RSSI: \d+, LQI: \d+, Data:")
child.expect_exact(r"00000000 41 DC 02 23 00 38 30 00 0A 50 45 5A 00 5B 45 00")
child.expect_exact(r"00000010 0A 50 45 5A 00 48 65 6C 6C 6F 20 57 6F 72 6C 64")
if __name__ == "__main__":
sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner'))
import testrunner
os.environ['TERMFLAGS'] = "-z [%s]:%d,[%s]:%d" % (
zep_params['local_addr'], zep_params['local_port'],
zep_params['remote_addr'], zep_params['remote_port'])
s = socket.socket(family=socket.AF_INET6, type=socket.SOCK_DGRAM)
s.bind(("::", zep_params['remote_port']))
res = testrunner.run(testfunc, timeout=1, echo=True, traceback=True)
s.close()
if (res == 0):
print("Run tests successful")
else:
print("Run tests failed")
sys.exit(res)
示例6: test_tcp_connect6__EINVAL_netif
child.expect_exact("Calling test_tcp_connect6__EINVAL_netif()")
child.expect_exact("Calling test_tcp_connect6__success_without_port()")
child.expect_exact("Calling test_tcp_connect6__success_local_port()")
if _reuse_tests(code):
child.expect_exact("Calling test_tcp_listen6__EADDRINUSE()")
child.expect_exact("Calling test_tcp_listen6__EAFNOSUPPORT()")
child.expect_exact("Calling test_tcp_listen6__EINVAL()")
child.expect_exact("Calling test_tcp_listen6__success_any_netif()")
child.expect_exact("Calling test_tcp_listen6__success_spec_netif()")
child.expect_exact("Calling test_tcp_accept6__EAGAIN()")
child.expect_exact("Calling test_tcp_accept6__EINVAL()")
child.expect_exact("Calling test_tcp_accept6__ETIMEDOUT()")
child.expect_exact(" * Calling sock_tcp_accept()")
child.expect(r" \* \(timed out with timeout \d+\)")
child.expect_exact("Calling test_tcp_accept6__success()")
child.expect_exact("Calling test_tcp_read6__EAGAIN()")
child.expect_exact("Calling test_tcp_read6__ECONNRESET()")
child.expect_exact("Calling test_tcp_read6__ENOTCONN()")
child.expect_exact("Calling test_tcp_read6__ETIMEDOUT()")
child.expect_exact(" * Calling sock_tcp_read()")
child.expect(r" \* \(timed out with timeout \d+\)")
child.expect_exact("Calling test_tcp_read6__success()")
child.expect_exact("Calling test_tcp_read6__success_with_timeout()")
child.expect_exact("Calling test_tcp_read6__success_non_blocking()")
child.expect_exact("Calling test_tcp_write6__ENOTCONN()")
child.expect_exact("Calling test_tcp_write6__success()")
child.expect_exact(u"ALL TESTS SUCCESSFUL")
if __name__ == "__main__":
sys.exit(testrunner.run(testfunc, timeout=60))
示例7: testfunc
def testfunc(child):
global sniffer
tap = get_bridge(os.environ["TAP"])
child.expect(r"OK \((\d+) tests\)") # wait for and check result of unittests
print("." * int(child.match.group(1)), end="", flush=True)
lladdr_src = get_host_lladdr(tap)
child.sendline("ifconfig")
child.expect("HWaddr: (?P<hwaddr>[A-Fa-f:0-9]+)")
hwaddr_dst = child.match.group("hwaddr").lower()
child.expect("(?P<lladdr>fe80::[A-Fa-f:0-9]+)")
lladdr_dst = child.match.group("lladdr").lower()
sniffer = Sniffer(tap)
sniffer.start()
def run(func):
if child.logfile == sys.stdout:
func(child, tap, hwaddr_dst, lladdr_dst, lladdr_src)
else:
try:
func(child, tap, hwaddr_dst, lladdr_dst, lladdr_src)
print(".", end="", flush=True)
except Exception as e:
print("FAILED")
raise e
run(test_wrong_type)
run(test_seg_left_gt_len_addresses)
run(test_multicast_dst)
run(test_multicast_addr)
run(test_multiple_addrs_of_mine_uncomp)
run(test_forward_uncomp)
run(test_forward_uncomp_not_first_ext_hdr)
# compressed tests hard to implement with scapy and also covered in
# unittests
run(test_seq_left_0)
run(test_time_exc)
print("SUCCESS")
sniffer.stop()
示例8: Server
print client_address
print '-'*40
if __name__ == "__main__":
do_valgrind = False
path_search = False
options, args = getopt.getopt(sys.argv[1:], "V", ["valgrind"])
for option, value in options:
if option == "-V" or option == "--valgrind":
do_valgrind = True
# Instantiate a Server(TestHTTPRequestHandler) on the first free port
# in the specified port range. Doing this inline is better than in a
# daemon thread: if it blows up here, we'll get a traceback. If it blew up
# in some other thread, the traceback would get eaten and we'd run the
# subject test program anyway.
httpd, port = freeport(xrange(8000, 8020),
lambda port: Server(('127.0.0.1', port), TestHTTPRequestHandler))
# Pass the selected port number to the subject test program via the
# environment. We don't want to impose requirements on the test program's
# command-line parsing -- and anyway, for C++ integration tests, that's
# performed in TUT code rather than our own.
os.environ["LL_TEST_PORT"] = str(port)
debug("$LL_TEST_PORT = %s", port)
if do_valgrind:
args = ["valgrind", "--log-file=./valgrind.log"] + args
path_search = True
sys.exit(run(server=Thread(name="httpd", target=httpd.serve_forever), use_path=path_search, *args))
示例9: InvalidTimeout
class InvalidTimeout(Exception):
pass
def testfunc(child):
try:
child.expect_exact("Please hit any key and then ENTER to continue")
child.sendline("a")
start_test = time.time()
child.expect_exact("5 x usleep(i++ * 500000)")
for i in range(5):
child.expect_exact("wake up")
child.expect_exact("5 x sleep(i++)")
for i in range(5):
child.expect_exact("wake up")
child.expect_exact("DONE")
testtime = (time.time() - start_test) * US_PER_SEC
exp = sum(i * 500000 for i in range(5)) + \
sum(i * US_PER_SEC for i in range(5))
lower_bound = exp - (exp * EXTERNAL_JITTER)
upper_bound = exp + (exp * EXTERNAL_JITTER)
if not (lower_bound < testtime < upper_bound):
raise InvalidTimeout("Host timer measured %d us (client measured %d us)" % \
(testtime, exp))
except InvalidTimeout as e:
print(e)
sys.exit(1)
if __name__ == "__main__":
sys.exit(testrunner.run(testfunc, echo=True))
示例10: testfunc
def testfunc(child):
global server
tap = get_bridge(os.environ["TAP"])
lladdr = get_host_lladdr(tap)
time.sleep(3)
try:
server = Server(family=socket.AF_INET6, type=socket.SOCK_DGRAM,
bind_addr=lladdr + "%" + tap, bind_port=SERVER_PORT)
server.start()
dns_server(child, lladdr, SERVER_PORT)
def run(func):
if child.logfile == sys.stdout:
print(func.__name__)
func(child)
else:
try:
func(child)
print(".", end="", flush=True)
except Exception as e:
print("FAILED")
raise e
run(test_success)
run(test_timeout)
run(test_too_short_response)
run(test_qdcount_too_large1)
run(test_qdcount_too_large2)
run(test_ancount_too_large1)
run(test_ancount_too_large2)
run(test_bad_compressed_message_query)
run(test_bad_compressed_message_answer)
run(test_malformed_hostname_query)
run(test_malformed_hostname_answer)
run(test_addrlen_too_large)
run(test_addrlen_wrong_ip6)
run(test_addrlen_wrong_ip4)
print("SUCCESS")
finally:
if server is not None:
server.stop()
示例11: makeoptions
from optparse import OptionParser
def makeoptions():
parser = OptionParser()
parser.add_option(
"-v",
"--verbosity",
type=int,
action="store",
dest="verbosity",
default=1,
help="Tests verbosity level, one of 0, 1, 2 or 3",
)
return parser
if __name__ == "__main__":
import djpcms
import sys
options, tags = makeoptions().parse_args()
verbosity = options.verbosity
p = os.path
path = p.join(p.split(p.abspath(__file__))[0], "tests")
sys.path.insert(0, path)
from testrunner import run
run(tags, verbosity=verbosity)
示例12: testfunc
def testfunc(child):
child.expect_exact("od_hex_dump(short_str, sizeof(short_str), OD_WIDTH_DEFAULT)")
child.expect_exact("00000000 41 42 00")
child.expect_exact("od_hex_dump(long_str, sizeof(long_str), OD_WIDTH_DEFAULT)")
child.expect_exact("00000000 FF 2C 61 FF 2E 62 63 64 65 66 67 68 69 6A 6B 6C")
child.expect_exact("00000010 6D 6E 6F 70 00")
child.expect_exact("od_hex_dump(long_str, sizeof(long_str), 4)")
child.expect_exact("00000000 FF 2C 61 FF")
child.expect_exact("00000004 2E 62 63 64")
child.expect_exact("00000008 65 66 67 68")
child.expect_exact("0000000C 69 6A 6B 6C")
child.expect_exact("00000010 6D 6E 6F 70")
child.expect_exact("00000014 00")
child.expect_exact("od_hex_dump(long_str, sizeof(long_str), 3)")
child.expect_exact("00000000 FF 2C 61")
child.expect_exact("00000003 FF 2E 62")
child.expect_exact("00000006 63 64 65")
child.expect_exact("00000009 66 67 68")
child.expect_exact("0000000C 69 6A 6B")
child.expect_exact("0000000F 6C 6D 6E")
child.expect_exact("00000012 6F 70 00")
child.expect_exact("od_hex_dump(long_str, sizeof(long_str), 8)")
child.expect_exact("00000000 FF 2C 61 FF 2E 62 63 64")
child.expect_exact("00000008 65 66 67 68 69 6A 6B 6C")
child.expect_exact("00000010 6D 6E 6F 70 00")
print("All tests successful")
if __name__ == "__main__":
sys.exit(testrunner.run(testfunc, timeout=1, echo=False))
示例13: Copyright
#!/usr/bin/env python3
# Copyright (C) 2016 Kaspar Schleiser <[email protected]>
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
import os
import sys
sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner'))
import testrunner
def testfunc(child):
child.expect(u"done")
if __name__ == "__main__":
sys.exit(testrunner.run(testfunc, 1200))
示例14: log_request
def log_request(self, code, size=None):
# For present purposes, we don't want the request splattered onto
# stderr, as it would upset devs watching the test run
pass
def log_error(self, format, *args):
# Suppress error output as well
pass
class Server(HTTPServer):
# This pernicious flag is on by default in HTTPServer. But proper
# operation of freeport() absolutely depends on it being off.
allow_reuse_address = False
if __name__ == "__main__":
# Instantiate a Server(TestHTTPRequestHandler) on the first free port
# in the specified port range. Doing this inline is better than in a
# daemon thread: if it blows up here, we'll get a traceback. If it blew up
# in some other thread, the traceback would get eaten and we'd run the
# subject test program anyway.
httpd, port = freeport(xrange(8000, 8020),
lambda port: Server(('127.0.0.1', port), TestHTTPRequestHandler))
# Pass the selected port number to the subject test program via the
# environment. We don't want to impose requirements on the test program's
# command-line parsing -- and anyway, for C++ integration tests, that's
# performed in TUT code rather than our own.
os.environ["PORT"] = str(port)
debug("$PORT = %s", port)
sys.exit(run(server=Thread(name="httpd", target=httpd.serve_forever), *sys.argv[1:]))
示例15: assert
data, addr = s.recvfrom(RCVBUF_LEN)
assert(len(data) == (ZEP_DATA_HEADER_SIZE + FCS_LEN))
child.expect_exact("Send 'Hello\\0World\\0'")
data, addr = s.recvfrom(RCVBUF_LEN)
assert(len(data) == (ZEP_DATA_HEADER_SIZE + len("Hello\0World\0") + FCS_LEN))
assert(b"Hello\0World\0" == data[ZEP_DATA_HEADER_SIZE:-2])
child.expect_exact("Waiting for an incoming message (use `make test`)")
s.sendto(b"\x45\x58\x02\x01\x1a\x44\xe0\x01\xff\xdb\xde\xa6\x1a\x00\x8b" +
b"\xfd\xae\x60\xd3\x21\xf1\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
b"\x00\x22\x41\xdc\x02\x23\x00\x38\x30\x00\x0a\x50\x45\x5a\x00" +
b"\x5b\x45\x00\x0a\x50\x45\x5a\x00Hello World\x3a\xf2",
("::1", zep_params['local_port']))
child.expect(r"RSSI: \d+, LQI: \d+, Data:")
child.expect_exact(r"00000000 41 DC 02 23 00 38 30 00 0A 50 45 5A 00 5B 45 00")
child.expect_exact(r"00000010 0A 50 45 5A 00 48 65 6C 6C 6F 20 57 6F 72 6C 64")
if __name__ == "__main__":
os.environ['TERMFLAGS'] = "-z [%s]:%d,[%s]:%d" % (
zep_params['local_addr'], zep_params['local_port'],
zep_params['remote_addr'], zep_params['remote_port'])
s = socket.socket(family=socket.AF_INET6, type=socket.SOCK_DGRAM)
s.bind(("::", zep_params['remote_port']))
res = run(testfunc, timeout=1, echo=True, traceback=True)
s.close()
if (res == 0):
print("Run tests successful")
else:
print("Run tests failed")
sys.exit(res)