-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add first unit tests for process_pool_worker
The only change of note is to move the ArgumentParser to a function to enable writing unit tests for it. No user-functional change.
- Loading branch information
1 parent
e724d13
commit a517a83
Showing
3 changed files
with
193 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
74 changes: 74 additions & 0 deletions
74
parsl/tests/unit/executors/high_throughput/test_process_worker_pool.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import sys | ||
from argparse import ArgumentError | ||
|
||
import pytest | ||
|
||
from parsl.executors.high_throughput import process_worker_pool | ||
|
||
if sys.version_info < (3, 12): | ||
# exit_on_error bug; see https://github.com/python/cpython/issues/121018 | ||
# "argparse.ArgumentParser.parses_args does not honor exit_on_error=False when | ||
# given unrecognized arguments" | ||
pytest.skip(allow_module_level=True, reason="exit_on_error argparse bug") | ||
|
||
# due to above pytest.skip, mypy on < Py312 thinks this is unreachable. :facepalm: | ||
_known_required = ( # type: ignore[unreachable] | ||
"--cert_dir", | ||
"--cpu-affinity", | ||
"--result_port", | ||
"--task_port", | ||
) | ||
|
||
|
||
@pytest.mark.local | ||
def test_arg_parser_exits_on_error(): | ||
p = process_worker_pool.get_arg_parser() | ||
assert p.exit_on_error | ||
|
||
|
||
@pytest.mark.local | ||
def test_arg_parser_known_required(): | ||
p = process_worker_pool.get_arg_parser() | ||
reqd = [a for a in p._actions if a.required] | ||
for a in reqd: | ||
assert a.option_strings[-1] in _known_required, "Update _known_required?" | ||
|
||
|
||
@pytest.mark.local | ||
@pytest.mark.parametrize("req", _known_required) | ||
def test_arg_parser_required(req): | ||
p = process_worker_pool.get_arg_parser() | ||
p.exit_on_error = False | ||
with pytest.raises(ArgumentError) as pyt_exc: | ||
p.parse_args([]) | ||
|
||
e_msg = pyt_exc.value.args[1] | ||
assert req in e_msg | ||
|
||
|
||
@pytest.mark.local | ||
@pytest.mark.parametrize("valid,val", ( | ||
(True, "NoNe"), | ||
(True, "none"), | ||
(True, "block"), | ||
(True, "alternating"), | ||
(True, "block-reverse"), | ||
(True, "list"), | ||
(False, "asdf"), | ||
(False, ""), | ||
)) | ||
def test_arg_parser_validates_cpu_affinity(valid, val): | ||
reqd_args = [] | ||
reqd_args.extend(("--cert_dir", "/some/path")) | ||
reqd_args.extend(("--result_port", "123")) | ||
reqd_args.extend(("--task_port", "123")) | ||
reqd_args.extend(("--cpu-affinity", val)) | ||
|
||
p = process_worker_pool.get_arg_parser() | ||
p.exit_on_error = False | ||
if valid: | ||
p.parse_args(reqd_args) | ||
else: | ||
with pytest.raises(ArgumentError) as pyt_exc: | ||
p.parse_args(reqd_args) | ||
assert "must be one of" in pyt_exc.value.args[1] |