add tests

This commit is contained in:
Uriel
2026-03-08 06:32:22 -03:00
parent 9653c8d29c
commit 10d2908339
2 changed files with 103 additions and 3 deletions

View File

@@ -191,7 +191,7 @@ class GameRangePorts(typing.NamedTuple):
@functools.cache
def parse_game_ports(game_ports: tuple[str | int]) -> GameRangePorts:
def parse_game_ports(game_ports: tuple[str | int, ...]) -> GameRangePorts:
parsed_ports: list[range] = []
weights = []
ephemeral_allowed = False
@@ -220,10 +220,10 @@ def weighted_random(ranges: list[range], cum_weights: list[int]) -> int:
return random.randrange(picked.start, picked.stop, picked.step)
def create_random_port_socket(game_ports: tuple[str | int], host: str) -> socket.socket:
def create_random_port_socket(game_ports: tuple[str | int, ...], host: str) -> socket.socket:
parsed_ports, weights, ephemeral_allowed = parse_game_ports(game_ports)
used_ports = get_used_ports()
i = 1024
i = 1024 if len(parsed_ports) > 0 else 0
while i > 0:
port_num = weighted_random(parsed_ports, weights)
if port_num in used_ports: