-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: replace strtobool for local function
- Loading branch information
1 parent
8585c7b
commit 90b0bb8
Showing
3 changed files
with
31 additions
and
1 deletion.
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,21 @@ | ||
import pytest | ||
from util import strtobool | ||
|
||
|
||
def test_true_values(): | ||
true_list = ["y", "yes", "t", "true", "on", "1"] | ||
for item in true_list: | ||
assert strtobool(item) == 1 | ||
|
||
|
||
def test_false_values(): | ||
false_list = ["n", "no", "f", "false", "off", "0"] | ||
for item in false_list: | ||
assert strtobool(item) == 0 | ||
|
||
|
||
def test_invalid_value_text(): | ||
invalid_list = ["Invalid_Value_1", "1nv4l1d_V4lu3_2", "Invalid_Value_3"] | ||
for value in invalid_list: | ||
with pytest.raises(ValueError, match="invalid truth value '%s'".format(value)): | ||
strtobool(value) |
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,9 @@ | ||
def strtobool(value): | ||
value = value.lower() | ||
if value in ["y", "yes", "t", "true", "on", "1"]: | ||
result = True | ||
elif value in ["n", "no", "f", "false", "off", "0"]: | ||
result = False | ||
else: | ||
raise ValueError("invalid truth value '%s'".format(value)) | ||
return result |