Skip to content

Commit

Permalink
Remove deprecated distutils.util.strtobool
Browse files Browse the repository at this point in the history
Fix #273
  • Loading branch information
drgarcia1986 committed Dec 29, 2021
1 parent 4e032fb commit b9ec1cc
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion simple_settings/special_settings.py
Expand Up @@ -2,9 +2,9 @@
import logging.config
import os
from collections import OrderedDict
from distutils.util import strtobool

from .constants import SPECIAL_SETTINGS_KEY
from .strtobool import strtobool


def required_settings(settings_dict):
Expand Down
21 changes: 21 additions & 0 deletions simple_settings/strtobool.py
@@ -0,0 +1,21 @@
_MAP = {
'y': True,
'yes': True,
't': True,
'true': True,
'on': True,
'1': True,
'n': False,
'no': False,
'f': False,
'false': False,
'off': False,
'0': False
}


def strtobool(value):
try:
return _MAP[str(value).lower()]
except KeyError:
raise ValueError('"{}" is not a valid bool value'.format(value))
22 changes: 22 additions & 0 deletions tests/test_strtobool.py
@@ -0,0 +1,22 @@
import pytest

from simple_settings.strtobool import strtobool


class TestStrToBool:

@pytest.mark.parametrize('value', (
'y', 'Y', 'yes', 't', 'True', 'ON', 1,
))
def test_should_return_true(self, value):
assert strtobool(value) is True

@pytest.mark.parametrize('value', (
'n', 'N', 'no', 'f', 'False', 'OFF', 0,
))
def test_should_return_false(self, value):
assert strtobool(value) is False

def test_should_raise_value_error(self):
with pytest.raises(ValueError):
strtobool('VERDADEIRO')

0 comments on commit b9ec1cc

Please sign in to comment.