Skip to content

Commit

Permalink
fix: replace strtobool for local function
Browse files Browse the repository at this point in the history
  • Loading branch information
ZandorSabino committed Nov 29, 2021
1 parent 8585c7b commit 90b0bb8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion decouple.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from shlex import shlex
from io import open
from collections import OrderedDict
from distutils.util import strtobool
from util import strtobool

# Useful for very coarse version differentiation.
PYVERSION = sys.version_info
Expand Down
21 changes: 21 additions & 0 deletions tests/test_util.py
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)
9 changes: 9 additions & 0 deletions util.py
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

0 comments on commit 90b0bb8

Please sign in to comment.