예제 #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