From 7cbe65e38e44abde421a4233a81a2cca66f2d1ca Mon Sep 17 00:00:00 2001 From: Henrik Bengtsson Date: Wed, 21 Jun 2023 14:43:46 +0200 Subject: [PATCH] BUG FIX: Python implementation did not handle PORT4ME_LIST; added package tests for this. Changed the default for argument 'list' to None - was 0 --- python/port4me/__init__.py | 6 +++++- python/tests/test_port4me.py | 3 +-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/python/port4me/__init__.py b/python/port4me/__init__.py index ad99614..23d1f40 100644 --- a/python/port4me/__init__.py +++ b/python/port4me/__init__.py @@ -107,7 +107,7 @@ def port4me_gen(tool="", user="", prepend=None, include=None, exclude=None, min_ _list = list # necessary to avoid conflicts with list() and the parameter which is named list -def port4me(tool="", user="", prepend=None, include=None, exclude=None, skip=None, list=0, test=None, max_tries=65536, must_work=True, min_port=1024, max_port=65535): +def port4me(tool="", user="", prepend=None, include=None, exclude=None, skip=None, list=None, test=None, max_tries=65536, must_work=True, min_port=1024, max_port=65535): """ Find a free TCP port using a deterministic sequence of ports based on the current username. @@ -153,6 +153,10 @@ def port4me(tool="", user="", prepend=None, include=None, exclude=None, skip=Non skip = int(skip) gen = islice(gen, skip, None) + if list is None: + list = getenv("PORT4ME_LIST", 0) + list = int(list) + if list: return _list(islice(gen, list)) diff --git a/python/tests/test_port4me.py b/python/tests/test_port4me.py index 87107ec..47184fc 100644 --- a/python/tests/test_port4me.py +++ b/python/tests/test_port4me.py @@ -19,10 +19,9 @@ def test_alice_list_five(): assert port4me('', 'alice', list=5) == [30845, 19654, 32310, 63992, 15273] -## FIXME: HB /2023-06-21 def test_alice_list_five_env(): environ['PORT4ME_LIST'] = '5' -# assert port4me('', 'alice') == [30845, 19654, 32310, 63992, 15273] + assert port4me('', 'alice') == [30845, 19654, 32310, 63992, 15273] environ.pop('PORT4ME_LIST')