mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-03-25 22:20:45 +01:00
test-client: accept yes/true/no/false for boolean arguments
This commit is contained in:
parent
5da7301ec9
commit
b08f7a9c19
1 changed files with 16 additions and 3 deletions
|
|
@ -228,6 +228,19 @@ class Util:
|
|||
t = basestring
|
||||
return isinstance(s, t)
|
||||
|
||||
@staticmethod
|
||||
def is_bool(s, defval=False):
|
||||
if s is None:
|
||||
return defval
|
||||
if isinstance(s, int):
|
||||
return s != 0
|
||||
if isinstance(s, str):
|
||||
if s.lower() in ["1", "y", "yes", "true", "on"]:
|
||||
return True
|
||||
if s.lower() in ["0", "n", "no", "false", "off"]:
|
||||
return False
|
||||
raise ValueError('Argument "%s" is not a boolean' % (s,))
|
||||
|
||||
@staticmethod
|
||||
def as_bytes(s):
|
||||
if Util.is_string(s):
|
||||
|
|
@ -499,14 +512,14 @@ class Configuration:
|
|||
#
|
||||
# Only by setting NM_TEST_CLIENT_CHECK_L10N=1, these tests are included
|
||||
# as well.
|
||||
v = os.environ.get(ENV_NM_TEST_CLIENT_CHECK_L10N, "0") == "1"
|
||||
v = Util.is_bool(os.environ.get(ENV_NM_TEST_CLIENT_CHECK_L10N, None))
|
||||
elif name == ENV_NM_TEST_REGENERATE:
|
||||
# in the "regenerate" mode, the tests will rewrite the files on disk against
|
||||
# which we assert. That is useful, if there are intentional changes and
|
||||
# we want to regenerate the expected output.
|
||||
v = os.environ.get(ENV_NM_TEST_REGENERATE, "0") == "1"
|
||||
v = Util.is_bool(os.environ.get(ENV_NM_TEST_REGENERATE, None))
|
||||
elif name == ENV_NM_TEST_WITH_LINENO:
|
||||
v = os.environ.get(ENV_NM_TEST_WITH_LINENO, "0") == "1"
|
||||
v = Util.is_bool(os.environ.get(ENV_NM_TEST_WITH_LINENO, None))
|
||||
elif name in [
|
||||
ENV_NM_TEST_ASAN_OPTIONS,
|
||||
ENV_NM_TEST_LSAN_OPTIONS,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue