mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Tests: clean up env var handling
* Replace deprecated strtobool * Strip whitespace from env values
This commit is contained in:
16
runtests.py
16
runtests.py
@@ -5,7 +5,6 @@
|
|||||||
# runtests.py [tests.test_x tests.test_y.SomeTestCase ...]
|
# runtests.py [tests.test_x tests.test_y.SomeTestCase ...]
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from distutils.util import strtobool
|
|
||||||
|
|
||||||
import django
|
import django
|
||||||
import os
|
import os
|
||||||
@@ -51,14 +50,19 @@ def runtests(test_labels=None):
|
|||||||
def envbool(var, default=False):
|
def envbool(var, default=False):
|
||||||
"""Returns value of environment variable var as a bool, or default if not set/empty.
|
"""Returns value of environment variable var as a bool, or default if not set/empty.
|
||||||
|
|
||||||
Converts `'true'` to `True`, and `'false'` to `False`.
|
Converts `'true'` and similar string representations to `True`,
|
||||||
See :func:`~distutils.util.strtobool` for full list of allowable values.
|
and `'false'` and similar string representations to `False`.
|
||||||
"""
|
"""
|
||||||
val = os.getenv(var, '')
|
# Adapted from the old :func:`~distutils.util.strtobool`
|
||||||
|
val = os.getenv(var, '').strip().lower()
|
||||||
if val == '':
|
if val == '':
|
||||||
return default
|
return default
|
||||||
|
elif val in ('y', 'yes', 't', 'true', 'on', '1'):
|
||||||
|
return True
|
||||||
|
elif val in ('n', 'no', 'f', 'false', 'off', '0'):
|
||||||
|
return False
|
||||||
else:
|
else:
|
||||||
return strtobool(val)
|
raise ValueError("invalid boolean value env[%r]=%r" % (var, val))
|
||||||
|
|
||||||
|
|
||||||
def envlist(var):
|
def envlist(var):
|
||||||
@@ -66,7 +70,7 @@ def envlist(var):
|
|||||||
|
|
||||||
Returns an empty list if variable is empty or not set.
|
Returns an empty list if variable is empty or not set.
|
||||||
"""
|
"""
|
||||||
val = os.getenv(var, "").split(',')
|
val = [item.strip() for item in os.getenv(var, '').split(',')]
|
||||||
if val == ['']:
|
if val == ['']:
|
||||||
# "Splitting an empty string with a specified separator returns ['']"
|
# "Splitting an empty string with a specified separator returns ['']"
|
||||||
val = []
|
val = []
|
||||||
|
|||||||
Reference in New Issue
Block a user