示例#1
0
 def test_create_connection (self):
     # Issue #9792: errors raised by create_connection() should have
     # a proper errno attribute.
     port = test_support.find_unused_port()
     with self.assertRaises(socket.error) as cm:
         socket.create_connection((HOST, port))
     self.assertEqual(cm.exception.errno, errno.ECONNREFUSED)
示例#2
0
 def test_create_connection(self):
     # Issue #9792: errors raised by create_connection() should have
     # a proper errno attribute.
     port = test_support.find_unused_port()
     with self.assertRaises(socket.error) as cm:
         socket.create_connection((HOST, port))
     self.assertEqual(cm.exception.errno, errno.ECONNREFUSED)
示例#3
0
 def _testSourceAddress(self):
     self.cli = socket.create_connection(
         (HOST, self.port),
         timeout=30,
         source_address=('', self.source_port))
     self.addCleanup(self.cli.close)
     self.assertEqual(self.cli.getsockname()[1], self.source_port)
示例#4
0
 def _testTimeoutDefault (self):
     # passing no explicit timeout uses socket's global default
     self.assertTrue(socket.getdefaulttimeout() is None)
     socket.setdefaulttimeout(42)
     try:
         self.cli = socket.create_connection((HOST, self.port))
         self.addCleanup(self.cli.close)
     finally:
         socket.setdefaulttimeout(None)
     self.assertEqual(self.cli.gettimeout(), 42)
示例#5
0
 def _testTimeoutNone (self):
     # None timeout means the same as sock.settimeout(None)
     self.assertTrue(socket.getdefaulttimeout() is None)
     socket.setdefaulttimeout(30)
     try:
         self.cli = socket.create_connection((HOST, self.port), timeout = None)
         self.addCleanup(self.cli.close)
     finally:
         socket.setdefaulttimeout(None)
     self.assertEqual(self.cli.gettimeout(), None)
示例#6
0
 def _testTimeoutDefault(self):
     # passing no explicit timeout uses socket's global default
     self.assertTrue(socket.getdefaulttimeout() is None)
     socket.setdefaulttimeout(42)
     try:
         self.cli = socket.create_connection((HOST, self.port))
         self.addCleanup(self.cli.close)
     finally:
         socket.setdefaulttimeout(None)
     self.assertEqual(self.cli.gettimeout(), 42)
示例#7
0
 def _testTimeoutNone(self):
     # None timeout means the same as sock.settimeout(None)
     self.assertTrue(socket.getdefaulttimeout() is None)
     socket.setdefaulttimeout(30)
     try:
         self.cli = socket.create_connection((HOST, self.port),
                                             timeout=None)
         self.addCleanup(self.cli.close)
     finally:
         socket.setdefaulttimeout(None)
     self.assertEqual(self.cli.gettimeout(), None)
示例#8
0
 def _testFamily(self):
     self.cli = socket.create_connection((HOST, self.port), timeout=30)
     self.addCleanup(self.cli.close)
     self.assertEqual(self.cli.family, 2)
示例#9
0
 def test_create_connection_timeout(self):
     # Issue #9792: create_connection() should not recast timeout errors
     # as generic socket errors.
     with self.mocked_socket_module():
         with self.assertRaises(socket.timeout):
             socket.create_connection((HOST, 1234))
示例#10
0
 def _testInsideTimeout(self):
     self.cli = sock = socket.create_connection((HOST, self.port))
     data = sock.recv(5)
     self.assertEqual(data, "done!")
示例#11
0
 def _testTimeoutValueNamed(self):
     self.cli = socket.create_connection((HOST, self.port), timeout=30)
     self.assertEqual(self.cli.gettimeout(), 30)
示例#12
0
 def _testTimeoutValueNonamed (self):
     self.cli = socket.create_connection((HOST, self.port), 30)
     self.addCleanup(self.cli.close)
     self.assertEqual(self.cli.gettimeout(), 30)
示例#13
0
 def _testTimeoutValueNamed (self):
     self.cli = socket.create_connection((HOST, self.port), timeout = 30)
     self.assertEqual(self.cli.gettimeout(), 30)
示例#14
0
 def _testSourceAddress (self):
     self.cli = socket.create_connection((HOST, self.port), timeout = 30,
                                         source_address = ('', self.source_port))
     self.addCleanup(self.cli.close)
     self.assertEqual(self.cli.getsockname()[1], self.source_port)
示例#15
0
 def _testFamily (self):
     self.cli = socket.create_connection((HOST, self.port), timeout = 30)
     self.addCleanup(self.cli.close)
     self.assertEqual(self.cli.family, 2)
示例#16
0
 def test_create_connection_timeout (self):
     # Issue #9792: create_connection() should not recast timeout errors
     # as generic socket errors.
     with self.mocked_socket_module():
         with self.assertRaises(socket.timeout):
             socket.create_connection((HOST, 1234))
示例#17
0
 def _testInsideTimeout (self):
     self.cli = sock = socket.create_connection((HOST, self.port))
     data = sock.recv(5)
     self.assertEqual(data, "done!")
示例#18
0
 def _testOutsideTimeout (self):
     self.cli = sock = socket.create_connection((HOST, self.port), timeout = 1)
     self.assertRaises(socket.timeout, lambda: sock.recv(5))
示例#19
0
 def _testTimeoutValueNonamed(self):
     self.cli = socket.create_connection((HOST, self.port), 30)
     self.addCleanup(self.cli.close)
     self.assertEqual(self.cli.gettimeout(), 30)
示例#20
0
 def clientSetUp(self):
     # We're inherited below by BasicTCPTest2, which also inherits
     # BasicTCPTest, which defines self.port referenced below.
     self.cli = socket.create_connection((HOST, self.port))
     self.serv_conn = self.cli
示例#21
0
 def _testOutsideTimeout(self):
     self.cli = sock = socket.create_connection((HOST, self.port),
                                                timeout=1)
     self.assertRaises(socket.timeout, lambda: sock.recv(5))
示例#22
0
 def clientSetUp (self):
     # We're inherited below by BasicTCPTest2, which also inherits
     # BasicTCPTest, which defines self.port referenced below.
     self.cli = socket.create_connection((HOST, self.port))
     self.serv_conn = self.cli