Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions tests/test_threadpoolctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,12 +604,15 @@ def test_libomp_libiomp_warning(recwarn):
assert "multiple_openmp.md" in str(wm.message)


def test_command_line_empty_or_system_openmp():
@pytest.mark.parametrize("import_args", [[], ["-i"], ["--import"], ["-i", "--import"]])
def test_command_line_empty_or_system_openmp(import_args):
# When the command line is called without arguments, no library should be
# detected. The only exception is a system OpenMP library that can be
# linked to the Python interpreter, for instance via the libb2.so BLAKE2
# library that can itself be linked to an OpenMP runtime on Gentoo.
output = subprocess.check_output((sys.executable + " -m threadpoolctl").split())
output = subprocess.check_output(
[sys.executable, "-m", "threadpoolctl", *import_args]
)
results = json.loads(output.decode("utf-8"))
conda_prefix = os.getenv("CONDA_PREFIX")
managed_by_conda = conda_prefix and sys.executable.startswith(conda_prefix)
Expand All @@ -632,18 +635,44 @@ def test_command_line_command_flag():
assert lib_info in this_process_info


def test_command_line_import_flag():
result = subprocess.run(
@pytest.mark.parametrize(
"import_args",
[
["-i", "numpy", "scipy.linalg", "invalid_package", "numpy.invalid_sumodule"],
[
sys.executable,
"-m",
"threadpoolctl",
"-i",
"numpy",
"invalid_package",
"-i",
"scipy.linalg",
"numpy.invalid_sumodule",
],
[
"--import",
"numpy",
"invalid_package",
"--import",
"scipy.linalg",
"numpy.invalid_sumodule",
],
[
"-i",
"numpy",
"invalid_package",
"--import",
"scipy.linalg",
"numpy.invalid_sumodule",
],
],
)
def test_command_line_import_flag(import_args):
result = subprocess.run(
[
sys.executable,
"-m",
"threadpoolctl",
*import_args,
],
capture_output=True,
check=True,
encoding="utf-8",
Expand Down
3 changes: 2 additions & 1 deletion threadpoolctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,8 @@ def _main():
"--import",
dest="modules",
nargs="*",
default=(),
action="extend",
default=[],
help="Python modules to import before introspecting thread-pools.",
)
parser.add_argument(
Expand Down
Loading