Skip to content

Commit

Permalink
BUG FIX: Python implementation did not handle PORT4ME_LIST; added pac…
Browse files Browse the repository at this point in the history
…kage tests for this. Changed the default for argument 'list' to None - was 0
  • Loading branch information
HenrikBengtsson committed Jun 21, 2023
1 parent 1980c72 commit 7cbe65e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 5 additions & 1 deletion python/port4me/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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))

Expand Down
3 changes: 1 addition & 2 deletions python/tests/test_port4me.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')


Expand Down

0 comments on commit 7cbe65e

Please sign in to comment.