本文整理汇总了Python中test.test_support.HOST属性的典型用法代码示例。如果您正苦于以下问题:Python test_support.HOST属性的具体用法?Python test_support.HOST怎么用?Python test_support.HOST使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类test.test_support
的用法示例。
在下文中一共展示了test_support.HOST属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_getsockaddrarg
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import HOST [as 别名]
def test_getsockaddrarg(self):
sock = socket.socket()
self.addCleanup(sock.close)
port = test_support.find_unused_port()
big_port = port + 65536
neg_port = port - 65536
self.assertRaises(OverflowError, sock.bind, (HOST, big_port))
self.assertRaises(OverflowError, sock.bind, (HOST, neg_port))
# Since find_unused_port() is inherently subject to race conditions, we
# call it a couple times if necessary.
for i in itertools.count():
port = test_support.find_unused_port()
try:
sock.bind((HOST, port))
except OSError as e:
if e.errno != errno.EADDRINUSE or i == 5:
raise
else:
break
示例2: setUp
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import HOST [as 别名]
def setUp(self):
# temporarily replace sys.stdout to capture DebuggingServer output
self.old_stdout = sys.stdout
self.output = StringIO.StringIO()
sys.stdout = self.output
self._threads = test_support.threading_setup()
self.serv_evt = threading.Event()
self.client_evt = threading.Event()
# Pick a random unused port by passing 0 for the port number
self.serv = smtpd.DebuggingServer((HOST, 0), ('nowhere', -1))
# Keep a note of what port was assigned
self.port = self.serv.socket.getsockname()[1]
serv_args = (self.serv, self.serv_evt, self.client_evt)
self.thread = threading.Thread(target=debugging_server, args=serv_args)
self.thread.start()
# wait until server thread has assigned a port number
self.serv_evt.wait()
self.serv_evt.clear()
示例3: testSend
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import HOST [as 别名]
def testSend(self):
# connect and send mail
m = 'A test message'
smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
smtp.sendmail('John', 'Sally', m)
# XXX(nnorwitz): this test is flaky and dies with a bad file descriptor
# in asyncore. This sleep might help, but should really be fixed
# properly by using an Event variable.
time.sleep(0.01)
smtp.quit()
self.client_evt.set()
self.serv_evt.wait()
self.output.flush()
mexpect = '%s%s\n%s' % (MSG_BEGIN, m, MSG_END)
self.assertEqual(self.output.getvalue(), mexpect)
示例4: _test_read_any_eager_A
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import HOST [as 别名]
def _test_read_any_eager_A(self, func_name):
"""
read_very_eager()
Read all data available already queued or on the socket,
without blocking.
"""
want = [self.block_long, 'x' * 100, 'y' * 100, EOF_sigil]
expects = want[1] + want[2]
self.dataq.put(want)
telnet = telnetlib.Telnet(HOST, self.port)
self.dataq.join()
func = getattr(telnet, func_name)
data = ''
while True:
try:
data += func()
self.assertTrue(expects.startswith(data))
except EOFError:
break
self.assertEqual(expects, data)
示例5: test_read_lazy_A
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import HOST [as 别名]
def test_read_lazy_A(self):
want = ['x' * 100, EOF_sigil]
self.dataq.put(want)
telnet = telnetlib.Telnet(HOST, self.port)
self.dataq.join()
time.sleep(self.block_short)
self.assertEqual('', telnet.read_lazy())
data = ''
while True:
try:
read_data = telnet.read_lazy()
data += read_data
if not read_data:
telnet.fill_rawq()
except EOFError:
break
self.assertTrue(want[0].startswith(data))
self.assertEqual(data, want[0])
示例6: test_read_very_lazy_A
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import HOST [as 别名]
def test_read_very_lazy_A(self):
want = ['x' * 100, EOF_sigil]
self.dataq.put(want)
telnet = telnetlib.Telnet(HOST, self.port)
self.dataq.join()
time.sleep(self.block_short)
self.assertEqual('', telnet.read_very_lazy())
data = ''
while True:
try:
read_data = telnet.read_very_lazy()
except EOFError:
break
data += read_data
if not read_data:
telnet.fill_rawq()
self.assertEqual('', telnet.cookedq)
telnet.process_rawq()
self.assertTrue(want[0].startswith(data))
self.assertEqual(data, want[0])
示例7: _test_command
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import HOST [as 别名]
def _test_command(self, data):
""" helper for testing IAC + cmd """
self.setUp()
self.dataq.put(data)
telnet = telnetlib.Telnet(HOST, self.port)
self.dataq.join()
nego = nego_collector()
telnet.set_option_negotiation_callback(nego.do_nego)
txt = telnet.read_all()
cmd = nego.seen
self.assertTrue(len(cmd) > 0) # we expect at least one command
self.assertIn(cmd[0], self.cmds)
self.assertEqual(cmd[1], tl.NOOPT)
self.assertEqual(len(''.join(data[:-1])), len(txt + cmd))
nego.sb_getter = None # break the nego => telnet cycle
self.tearDown()
示例8: clientSetUp
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import HOST [as 别名]
def clientSetUp(self):
ThreadedTCPSocketTest.clientSetUp(self)
self.cli.connect((HOST, self.port))
self.serv_conn = self.cli
示例9: test_listen_backlog
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import HOST [as 别名]
def test_listen_backlog(self):
for backlog in 0, -1:
srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
srv.bind((HOST, 0))
srv.listen(backlog)
srv.close()
示例10: test_listen_backlog_overflow
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import HOST [as 别名]
def test_listen_backlog_overflow(self):
# Issue 15989
import _testcapi
srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
srv.bind((HOST, 0))
self.assertRaises(OverflowError, srv.listen, _testcapi.INT_MAX + 1)
srv.close()
示例11: _testRecvFrom
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import HOST [as 别名]
def _testRecvFrom(self):
self.cli.sendto(MSG, 0, (HOST, self.port))
示例12: _testRecvFromNegative
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import HOST [as 别名]
def _testRecvFromNegative(self):
self.cli.sendto(MSG, 0, (HOST, self.port))
示例13: _testClose
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import HOST [as 别名]
def _testClose(self):
self.cli.connect((HOST, self.port))
time.sleep(1.0)
示例14: _testAccept
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import HOST [as 别名]
def _testAccept(self):
# don't connect before event is set to check
# that non-blocking accept() raises socket.error
self.event.wait()
self.cli.connect((HOST, self.port))
示例15: _testConnect
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import HOST [as 别名]
def _testConnect(self):
self.cli.settimeout(10)
self.cli.connect((HOST, self.port))