Debian Codegraph @

tests/test_coverup_12.py

raw symbols SCIP
1 # file scalene/scalene_jupyter.py:8-28
2 # lines [8, 9, 21, 22, 23, 24, 25, 26, 27, 28]
3 # branches ['21->22', '21->28']
4
5 import pytest
6 import socket
7 from scalene.scalene_jupyter import ScaleneJupyter
8
9
10 @pytest.fixture(scope="function")
11 def free_port():
12 with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
13 s.bind(("", 0))
14 return s.getsockname()[1]
15
16
17 @pytest.fixture(scope="function")
18 def occupied_port(free_port):
19 with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
20 s.bind(("", free_port))
21 yield free_port
22
23
24 def test_find_available_port(free_port):
25 # Test that the function finds an available port
26 port = ScaleneJupyter.find_available_port(free_port, free_port)
27 assert port == free_port
28
29
30 def test_find_available_port_with_occupied_port(occupied_port):
31 # Test that the function skips the occupied port and finds the next available one
32 port = ScaleneJupyter.find_available_port(occupied_port, occupied_port + 1)
33 assert port == occupied_port + 1
34
35
36 def test_no_available_ports(occupied_port):
37 # Test that the function returns None when no ports are available
38 port = ScaleneJupyter.find_available_port(occupied_port, occupied_port)
39 assert port is None