def append_identifier(self, spaced_attribute_name, allow_spaces=False, default_value=None):
        r"""Appends Python identifier.

        String beginning with a letter or underscore and containing only 
        letters, digits and underscores.

        Returns prompt.
        """
        help_template = "value must be valid Python identifier."
        helper = lambda x: predicates.is_identifier(x, allow_spaces=allow_spaces)
        self._make_prompt(
            spaced_attribute_name, validation_function=helper, help_template=help_template, default_value=default_value
        )
Exemple #2
0
def test_predicates_02():

    assert predicates.is_identifier('foo_bar')
    assert predicates.is_identifier('FooBar')
    assert predicates.is_identifier('_foo_bar')
    assert predicates.is_identifier('__foo_bar')
    assert predicates.is_identifier('_')
    assert predicates.is_identifier('f')

    assert not predicates.is_boolean(None)
    assert not predicates.is_boolean('')
    assert not predicates.is_boolean('1')
    assert not predicates.is_boolean('foo_!')
    assert not predicates.is_boolean('foo_#')
    assert not predicates.is_boolean('foo_@')
Exemple #3
0
    def append_identifier(
        self,
        spaced_attribute_name,
        allow_spaces=False,
        default_value=None,
    ):
        r'''Appends Python identifier.

        String beginning with a letter or underscore and containing only 
        letters, digits and underscores.

        Returns prompt.
        '''
        help_template = 'value must be valid Python identifier.'
        helper = lambda x: predicates.is_identifier(x,
                                                    allow_spaces=allow_spaces)
        self._make_prompt(
            spaced_attribute_name,
            validation_function=helper,
            help_template=help_template,
            default_value=default_value,
        )