コード例 #1
0
def test_getattr_default_factory():
    b = DefaultFactoryMunch(lambda: None, bar='baz', lol={})
    assert b.foo is None
    assert b['foo'] is None

    assert b.bar == 'baz'
    assert getattr(b, 'bar') == 'baz'
    assert b['bar'] == 'baz'
    assert b.lol is b['lol']
    assert b.lol is getattr(b, 'lol')

    undefined = object()
    default = lambda: undefined
    b = DefaultFactoryMunch(default, bar='baz', lol={})
    assert b.foo is undefined
    assert b['foo'] is undefined

    default = lambda: object()
    b = DefaultFactoryMunch(default, bar='baz', lol={})
    assert b.foo is not b.baz
    assert b.foo is b['foo']
    assert b.foobar is b.foobar

    b = DefaultFactoryMunch(list)
    assert b.foo == []
    b.foo.append('bar')
    assert b.foo == ['bar']
    assert b.default_factory is list
コード例 #2
0
def test_repr_default_factory():
    b = DefaultFactoryMunch(list,
                            foo=DefaultFactoryMunch(list, lol=True),
                            ponies='are pretty!')
    assert repr(b).startswith("DefaultFactoryMunch(list, {'")
    assert "'ponies': 'are pretty!'" in repr(b)

    assert eval(repr(b)) == b
コード例 #3
0
ファイル: test_munch.py プロジェクト: Infinidat/munch
def test_setattr_default_factory():
    b = DefaultFactoryMunch(lambda: None, foo='bar', this_is='useful when subclassing')
    assert hasattr(b.values, '__call__')

    b.values = 'uh oh'
    assert b.values == 'uh oh'
    assert b['values'] is None

    assert b.default_factory() is None
    assert 'default_factory' not in b
コード例 #4
0
def test_setattr_default_factory():
    b = DefaultFactoryMunch(lambda: None, foo='bar', this_is='useful when subclassing')
    assert hasattr(b.values, '__call__')

    b.values = 'uh oh'
    assert b.values == 'uh oh'
    assert b['values'] is None

    assert b.default_factory() is None
    assert 'default_factory' not in b
コード例 #5
0
def test_munchify_default_factory():
    undefined = lambda: object()
    b = munchify(
        {'urmom': {'sez': {'what': 'what'}}},
        lambda d: DefaultFactoryMunch(undefined, d))
    assert b.urmom.sez.what == 'what'
    assert b.urdad is not undefined()
    assert b.urmom.sez.ni is not b.urdad
コード例 #6
0
ファイル: test_munch.py プロジェクト: Infinidat/munch
def test_copy_default_factory():
    undefined = lambda: object()
    m = DefaultFactoryMunch.fromDict({'urmom': {'sez': {'what': 'what'}}}, undefined)
    c = m.copy()
    assert c is not m
    assert c.urmom is not m.urmom
    assert c.urmom.sez is not m.urmom.sez
    assert c.urmom.sez.what == 'what'
    assert c == m
コード例 #7
0
def test_copy_default_factory():
    undefined = lambda: object()
    m = DefaultFactoryMunch.fromDict({'urmom': {'sez': {'what': 'what'}}}, undefined)
    c = m.copy()
    assert c is not m
    assert c.urmom is not m.urmom
    assert c.urmom.sez is not m.urmom.sez
    assert c.urmom.sez.what == 'what'
    assert c == m
コード例 #8
0
ファイル: core.py プロジェクト: AdrienPensart/click-skeleton
def skeleton(
    name: str,
    version: str,
    auto_envvar_prefix: Optional[str] = None,
    cls: Any = None,
    commands: Optional[Dict[str, Any]] = None,
    **kwargs: Any,
) -> Any:
    '''Generates an skeleton group with version options included'''
    auto_envvar_prefix = auto_envvar_prefix if auto_envvar_prefix is not None else name.upper()
    if cls is None:
        cls = AdvancedGroup

    sensible_context_settings = DEFAULT_CONTEXT_SETTINGS
    sensible_context_settings['auto_envvar_prefix'] = auto_envvar_prefix

    obj = DefaultFactoryMunch(Munch)
    obj.prog_name = name
    obj.version = version
    obj.context_settings = sensible_context_settings

    context_settings = sensible_context_settings
    context_settings['auto_envvar_prefix'] = auto_envvar_prefix
    context_settings['obj'] = obj

    commands = commands if commands is not None else {}
    commands['completion'] = completion_cli
    commands['version'] = version_cmd
    return add_options(
        version_option(
            version=version,
            prog_name=name,
            version_color='green',
            prog_name_color='yellow',
        ),
        click.group(
            name=name,
            context_settings=context_settings,
            commands=commands,
            cls=cls,
            **kwargs,
        ),
    )
コード例 #9
0
def test_fromDict_default_factory():
    obj = object()
    undefined = lambda: obj
    b = DefaultFactoryMunch.fromDict({'urmom': {
        'sez': {
            'what': 'what'
        }
    }}, undefined)
    assert b.urmom.sez.what == 'what'
    assert b.urmom.sez.foo is undefined()
コード例 #10
0
ファイル: test_munch.py プロジェクト: Infinidat/munch
def test_fromDict_default_factory():
    obj = object()
    undefined = lambda: obj
    b = DefaultFactoryMunch.fromDict({'urmom': {'sez': {'what': 'what'}}}, undefined)
    assert b.urmom.sez.what == 'what'
    assert b.urmom.sez.foo is undefined()
コード例 #11
0
def test_delattr_default_factory():
    b = DefaultFactoryMunch(lambda: None, lol=42)
    del b.lol

    assert b.lol is None
    assert b['lol'] is None