25 lines
758 B
Python
25 lines
758 B
Python
"""Regression for tests/_port_alloc.free_test_port."""
|
|
import os
|
|
import socket
|
|
import sys
|
|
import unittest
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
from _port_alloc import free_test_port # noqa: E402
|
|
|
|
|
|
class FreeTestPortTests(unittest.TestCase):
|
|
def test_two_calls_return_distinct_bindable_ports(self):
|
|
first = free_test_port()
|
|
second = free_test_port()
|
|
self.assertNotEqual(first, second)
|
|
for port in (first, second):
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as listener:
|
|
listener.bind(("127.0.0.1", port))
|
|
listener.listen(1)
|
|
self.assertEqual(listener.getsockname()[1], port)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|