-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace deprecated strtobool function (#3760)
The `distutils` module has been deprecated in Python 3.10 and removed in Python 3.12, [see docs distutils](https://docs.python.org/3/library/distutils.html). The [migration advice](https://peps.python.org/pep-0632/#migration-advice): > For these functions, and any others not mentioned here, you will need to reimplement the functionality yourself. > `distutils.util.strtobool` Copied the strtobool function from 3.11 and adjusted it to return booleans, like our function did.
- Loading branch information
Showing
2 changed files
with
53 additions
and
4 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
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,39 @@ | ||
import pytest | ||
|
||
from grandchallenge.core.utils import strtobool | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"val, result", | ||
[ | ||
("y", True), | ||
("Y", True), | ||
("yes", True), | ||
("Yes", True), | ||
("true", True), | ||
("True", True), | ||
("t", True), | ||
("T", True), | ||
("on", True), | ||
("On", True), | ||
("1", True), | ||
("n", False), | ||
("N", False), | ||
("no", False), | ||
("No", False), | ||
("false", False), | ||
("False", False), | ||
("f", False), | ||
("F", False), | ||
("off", False), | ||
("Off", False), | ||
("0", False), | ||
], | ||
) | ||
def test_strtobool(val, result): | ||
assert strtobool(val) is result | ||
|
||
|
||
def test_strtobool_exception(): | ||
with pytest.raises(ValueError): | ||
strtobool("foobar") |