diff options
author | Paweł Tomulik <ptomulik@meil.pw.edu.pl> | 2018-11-13 04:52:24 (GMT) |
---|---|---|
committer | Paweł Tomulik <ptomulik@meil.pw.edu.pl> | 2018-11-13 05:02:28 (GMT) |
commit | 6e4c93ae4f130a4566ee58e7a6e48695a51f1bf8 (patch) | |
tree | 12b1c346af86289f51b7af6ed8e4a3b1859fb781 | |
parent | 648cf42a89845ccad012e02609ca8958e62ce272 (diff) | |
download | SCons-6e4c93ae4f130a4566ee58e7a6e48695a51f1bf8.zip SCons-6e4c93ae4f130a4566ee58e7a6e48695a51f1bf8.tar.gz SCons-6e4c93ae4f130a4566ee58e7a6e48695a51f1bf8.tar.bz2 |
s/get_bool_envvar/get_os_env_bool/
-rw-r--r-- | src/engine/SCons/Platform/virtualenv.py | 4 | ||||
-rw-r--r-- | src/engine/SCons/Util.py | 13 | ||||
-rw-r--r-- | src/engine/SCons/UtilTests.py | 51 |
3 files changed, 55 insertions, 13 deletions
diff --git a/src/engine/SCons/Platform/virtualenv.py b/src/engine/SCons/Platform/virtualenv.py index 03fb486..4127d8c 100644 --- a/src/engine/SCons/Platform/virtualenv.py +++ b/src/engine/SCons/Platform/virtualenv.py @@ -37,11 +37,11 @@ virtualenv_enabled_by_default = False def _enable_virtualenv_default(): - return SCons.Util.get_bool_envvar('SCONS_ENABLE_VIRTUALENV', virtualenv_enabled_by_default) + return SCons.Util.get_os_env_bool('SCONS_ENABLE_VIRTUALENV', virtualenv_enabled_by_default) def _ignore_virtualenv_default(): - return SCons.Util.get_bool_envvar('SCONS_IGNORE_VIRTUALENV', False) + return SCons.Util.get_os_env_bool('SCONS_IGNORE_VIRTUALENV', False) enable_virtualenv = _enable_virtualenv_default() diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index 4588955..f20aae3 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -1597,9 +1597,9 @@ def cmp(a, b): return (a > b) - (a < b) -def get_bool_envvar(name, default=False): +def get_env_bool(env, name, default=False): """ - Get a value of OS environment variable converting it to boolean. + Get a value of an environment variable converting it to boolean. - FOO=1, FOO=123, FOO=true, FOO=yes, FOO=y, FOO=on are examples of ``True`` values. @@ -1607,10 +1607,10 @@ def get_bool_envvar(name, default=False): values. If a variable can't be converted to a boolean, default value is returned - (``False`` by default) + (``False`` by default). """ try: - var = os.environ[name] + var = env[name] except KeyError: return default try: @@ -1623,6 +1623,11 @@ def get_bool_envvar(name, default=False): else: return default + +def get_os_env_bool(name, default=False): + """Same as get_env_bool(os.environ, name, default).""" + return get_env_bool(os.environ, name, default) + # Local Variables: # tab-width:4 # indent-tabs-mode:nil diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py index 6067c98..99873ce 100644 --- a/src/engine/SCons/UtilTests.py +++ b/src/engine/SCons/UtilTests.py @@ -905,13 +905,50 @@ class OsEnviron(object): self.stop() -class get_bool_envvarTestCase(unittest.TestCase): +class get_env_boolTestCase(unittest.TestCase): + def test_missing(self): + env = dict() + var = get_env_bool(env, 'FOO') + assert var is False, "var should be False, not %s" % repr(var) + env = {'FOO': '1'} + var = get_env_bool(env, 'BAR') + assert var is False, "var should be False, not %s" % repr(var) + + def test_true(self): + for foo in [ 'TRUE', 'True', 'true', + 'YES', 'Yes', 'yes', + 'Y', 'y', + 'ON', 'On', 'on', + '1', '20', '-1']: + env = {'FOO': foo} + var = get_env_bool(env, 'FOO') + assert var is True, 'var should be True, not %s' % repr(var) + + def test_false(self): + for foo in [ 'FALSE', 'False', 'false', + 'NO', 'No', 'no', + 'N', 'n', + 'OFF', 'Off', 'off', + '0']: + env = {'FOO': foo} + var = get_env_bool(env, 'FOO', True) + assert var is False, 'var should be True, not %s' % repr(var) + + def test_default(self): + env = {'FOO': 'other'} + var = get_env_bool(env, 'FOO', True) + assert var is True, 'var should be True, not %s' % repr(var) + var = get_env_bool(env, 'FOO', False) + assert var is False, 'var should be False, not %s' % repr(var) + + +class get_os_env_boolTestCase(unittest.TestCase): def test_missing(self): with OsEnviron(dict()): - var = get_bool_envvar('FOO') + var = get_os_env_bool('FOO') assert var is False, "var should be False, not %s" % repr(var) with OsEnviron({'FOO': '1'}): - var = get_bool_envvar('BAR') + var = get_os_env_bool('BAR') assert var is False, "var should be False, not %s" % repr(var) def test_true(self): @@ -921,7 +958,7 @@ class get_bool_envvarTestCase(unittest.TestCase): 'ON', 'On', 'on', '1', '20', '-1']: with OsEnviron({'FOO': foo}): - var = get_bool_envvar('FOO') + var = get_os_env_bool('FOO') assert var is True, 'var should be True, not %s' % repr(var) def test_false(self): @@ -931,14 +968,14 @@ class get_bool_envvarTestCase(unittest.TestCase): 'OFF', 'Off', 'off', '0']: with OsEnviron({'FOO': foo}): - var = get_bool_envvar('FOO', True) + var = get_os_env_bool('FOO', True) assert var is False, 'var should be True, not %s' % repr(var) def test_default(self): with OsEnviron({'FOO': 'other'}): - var = get_bool_envvar('FOO', True) + var = get_os_env_bool('FOO', True) assert var is True, 'var should be True, not %s' % repr(var) - var = get_bool_envvar('FOO', False) + var = get_os_env_bool('FOO', False) assert var is False, 'var should be False, not %s' % repr(var) |