How to use the humanfriendly.coerce_boolean function in humanfriendly

To help you get started, we’ve selected a few humanfriendly examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xolox / python-humanfriendly / humanfriendly / tests.py View on Github external
def test_assert_raises(self):
        """Test :func:`~humanfriendly.testing.TestCase.assertRaises()`."""
        e = self.assertRaises(ValueError, humanfriendly.coerce_boolean, 'not a boolean')
        assert isinstance(e, ValueError)
github paylogic / pip-accel / pip_accel / tests.py View on Github external
installed. Because of this very non conventional behavior
                     the test is skipped unless the environment variable
                     ``PIP_ACCEL_TEST_AUTO_INSTALL=yes`` is set (opt-in).
        """
        if WINDOWS:
            return self.skipTest("""
                Skipping system package dependency installation
                test (not supported on Windows).
            """)
        elif platform.python_implementation() == 'PyPy':
            return self.skipTest("""
                Skipping system package dependency installation test (cffi on
                PyPy doesn't depend on libffi-dev being installed so this won't
                work at all).
            """)
        elif not coerce_boolean(os.environ.get('PIP_ACCEL_TEST_AUTO_INSTALL')):
            return self.skipTest("""
                Skipping system package dependency installation test because
                you need to set $PIP_ACCEL_TEST_AUTO_INSTALL=true to allow the
                test suite to use `sudo'.
            """)
        # Never allow concurrent execution of this code path, because the last
        # thing I want is to ruin my system by spawning concurrent dpkg and
        # apt-get processes. By actually preventing this I get to use detox for
        # parallel testing :-).
        with AptLock():
            # Force the removal of a system package required by `cffi' without
            # removing any (reverse) dependencies (we don't actually want to
            # break the system, thank you very much :-). Disclaimer: you opt in
            # to this with $PIP_ACCEL_TEST_AUTO_INSTALL...
            cffi_dependency = 'libffi-dev'
            subprocess.call([
github xolox / python-humanfriendly / humanfriendly / tests.py View on Github external
def test_boolean_coercion(self):
        """Test :func:`humanfriendly.coerce_boolean()`."""
        for value in [True, 'TRUE', 'True', 'true', 'on', 'yes', '1']:
            self.assertEqual(True, humanfriendly.coerce_boolean(value))
        for value in [False, 'FALSE', 'False', 'false', 'off', 'no', '0']:
            self.assertEqual(False, humanfriendly.coerce_boolean(value))
        self.assertRaises(ValueError, humanfriendly.coerce_boolean, 'not a boolean')
github xolox / python-rotate-backups / rotate_backups / __init__.py View on Github external
- ``~/.rotate-backups.ini`` and ``~/.rotate-backups.d/*.ini``
    - ``~/.config/rotate-backups.ini`` and ``~/.config/rotate-backups.d/*.ini``

    All of the available configuration files are loaded in the order given
    above, so that sections in user-specific configuration files override
    sections by the same name in system-wide configuration files.
    """
    expand_notice_given = False
    if configuration_file:
        loader = ConfigLoader(available_files=[configuration_file], strict=True)
    else:
        loader = ConfigLoader(program_name='rotate-backups', strict=False)
    for section in loader.section_names:
        items = dict(loader.get_options(section))
        context_options = {}
        if coerce_boolean(items.get('use-sudo')):
            context_options['sudo'] = True
        if items.get('ssh-user'):
            context_options['ssh_user'] = items['ssh-user']
        location = coerce_location(section, **context_options)
        rotation_scheme = dict((name, coerce_retention_period(items[name]))
                               for name in SUPPORTED_FREQUENCIES
                               if name in items)
        options = dict(include_list=split(items.get('include-list', '')),
                       exclude_list=split(items.get('exclude-list', '')),
                       io_scheduling_class=items.get('ionice'),
                       strict=coerce_boolean(items.get('strict', 'yes')),
                       prefer_recent=coerce_boolean(items.get('prefer-recent', 'no')))
        # Don't override the value of the 'removal_command' property unless the
        # 'removal-command' configuration file option has a value set.
        if items.get('removal-command'):
            options['removal_command'] = shlex.split(items['removal-command'])
github paylogic / pip-accel / pip_accel / config.py View on Github external
def trust_mod_times(self):
        """
        Whether to trust file modification times for cache invalidation.

        - Environment variable: ``$PIP_ACCEL_TRUST_MOD_TIMES``
        - Configuration option: ``trust-mod-times``
        - Default: :data:`True` unless the AppVeyor_ continuous integration
                   environment is detected (see `issue 62`_).

        .. _AppVeyor: http://www.appveyor.com
        .. _issue 62: https://github.com/paylogic/pip-accel/issues/62
        """
        on_appveyor = coerce_boolean(os.environ.get('APPVEYOR', 'False'))
        return coerce_boolean(self.get(property_name='trust_mod_times',
                                       environment_variable='PIP_ACCEL_TRUST_MOD_TIMES',
                                       configuration_option='trust-mod-times',
                                       default=(not on_appveyor)))
github paylogic / pip-accel / pip_accel / config.py View on Github external
:data:`True` if automatic installation of missing system packages is
        enabled, :data:`False` if it is disabled, :data:`None` otherwise (in this case
        the user will be prompted at the appropriate time).

        - Environment variable: ``$PIP_ACCEL_AUTO_INSTALL`` (refer to
          :func:`~humanfriendly.coerce_boolean()` for details on how the
          value of the environment variable is interpreted)
        - Configuration option: ``auto-install`` (also parsed using
          :func:`~humanfriendly.coerce_boolean()`)
        - Default: :data:`None`
        """
        value = self.get(property_name='auto_install',
                         environment_variable='PIP_ACCEL_AUTO_INSTALL',
                         configuration_option='auto-install')
        if value is not None:
            return coerce_boolean(value)
github paylogic / py2deb / py2deb / converter.py View on Github external
def lintian_enabled(self, value):
        """Automatically coerce :attr:`lintian_enabled` to a boolean value."""
        set_property(self, 'lintian_enabled', coerce_boolean(value))
github paylogic / py2deb / py2deb / converter.py View on Github external
def set_auto_install(self, enabled):
        """
        Enable or disable automatic installation of build time dependencies.

        :param enabled: Any value, evaluated using
                        :func:`~humanfriendly.coerce_boolean()`.
        """
        self.pip_accel.config.auto_install = coerce_boolean(enabled)