aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_asyncio/test_unix_events.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_asyncio/test_unix_events.py')
-rw-r--r--Lib/test/test_asyncio/test_unix_events.py40
1 files changed, 21 insertions, 19 deletions
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index 2f68459d30c..23d2e8ad401 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -315,11 +315,15 @@ class SelectorEventLoopUnixSocketTests(test_utils.TestCase):
self.loop.run_until_complete(coro)
def test_create_unix_server_existing_path_nonsock(self):
- with tempfile.NamedTemporaryFile() as file:
- coro = self.loop.create_unix_server(lambda: None, file.name)
- with self.assertRaisesRegex(OSError,
- 'Address.*is already in use'):
- self.loop.run_until_complete(coro)
+ path = test_utils.gen_unix_socket_path()
+ self.addCleanup(os_helper.unlink, path)
+ # create the file
+ open(path, "wb").close()
+
+ coro = self.loop.create_unix_server(lambda: None, path)
+ with self.assertRaisesRegex(OSError,
+ 'Address.*is already in use'):
+ self.loop.run_until_complete(coro)
def test_create_unix_server_ssl_bool(self):
coro = self.loop.create_unix_server(lambda: None, path='spam',
@@ -356,20 +360,18 @@ class SelectorEventLoopUnixSocketTests(test_utils.TestCase):
'no socket.SOCK_NONBLOCK (linux only)')
@socket_helper.skip_unless_bind_unix_socket
def test_create_unix_server_path_stream_bittype(self):
- sock = socket.socket(
- socket.AF_UNIX, socket.SOCK_STREAM | socket.SOCK_NONBLOCK)
- with tempfile.NamedTemporaryFile() as file:
- fn = file.name
- try:
- with sock:
- sock.bind(fn)
- coro = self.loop.create_unix_server(lambda: None, path=None,
- sock=sock)
- srv = self.loop.run_until_complete(coro)
- srv.close()
- self.loop.run_until_complete(srv.wait_closed())
- finally:
- os.unlink(fn)
+ fn = test_utils.gen_unix_socket_path()
+ self.addCleanup(os_helper.unlink, fn)
+
+ sock = socket.socket(socket.AF_UNIX,
+ socket.SOCK_STREAM | socket.SOCK_NONBLOCK)
+ with sock:
+ sock.bind(fn)
+ coro = self.loop.create_unix_server(lambda: None, path=None,
+ sock=sock)
+ srv = self.loop.run_until_complete(coro)
+ srv.close()
+ self.loop.run_until_complete(srv.wait_closed())
def test_create_unix_server_ssl_timeout_with_plain_sock(self):
coro = self.loop.create_unix_server(lambda: None, path='spam',