当前位置: 首页>>代码示例>>Python>>正文


Python dictset.dictset函数代码示例

本文整理汇总了Python中nefertari.utils.dictset.dictset函数的典型用法代码示例。如果您正苦于以下问题:Python dictset函数的具体用法?Python dictset怎么用?Python dictset使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了dictset函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_process_bools

 def test_process_bools(self):
     test_dict = dictset(
         complete__bool='false',
         other_arg=5,
     )
     result_dict = docs.process_bools(test_dict)
     assert result_dict == dictset(complete=False, other_arg=5)
开发者ID:numb3r3,项目名称:nefertari-sqla,代码行数:7,代码来源:test_documents.py

示例2: test_filter_fields

 def test_filter_fields(self, mock_fields):
     mock_fields.return_value = ('description', 'id', 'complete')
     params = docs.BaseMixin.filter_fields(dictset(
         description='nice',
         name='regular name',
         id__in__here=[1, 2, 3],
     ))
     assert params == dictset(
         description='nice',
         id__in__here=[1, 2, 3],
     )
开发者ID:numb3r3,项目名称:nefertari-sqla,代码行数:11,代码来源:test_documents.py

示例3: test_filter_fields

 def test_filter_fields(self):
     class MyModel(docs.BaseDocument):
         name = fields.StringField()
     params = MyModel.filter_fields(dictset(
         description='nice',
         name='regular name',
         id__in__here=[1, 2, 3],
     ))
     assert params == dictset(
         name='regular name',
         id__in__here=[1, 2, 3],
     )
开发者ID:oleduc,项目名称:nefertari-mongodb,代码行数:12,代码来源:test_documents.py

示例4: test_process_lists

 def test_process_lists(self):
     test_dict = dictset(
         id__in='1,   2, 3',
         name__all='foo',
         other__arg='4',
         yet_other_arg=5,
     )
     result_dict = docs.process_lists(test_dict)
     expected = dictset(
         id__in=['1', '2', '3'],
         name__all=['foo'],
         other__arg='4',
         yet_other_arg=5,
     )
     assert result_dict == expected
开发者ID:numb3r3,项目名称:nefertari-sqla,代码行数:15,代码来源:test_documents.py

示例5: test_pop_by_values

 def test_pop_by_values(self):
     dset = dictset({'boo': '1', 'foo': '2'})
     dset.pop_by_values('3')
     assert dict(dset) == {'boo': '1', 'foo': '2'}
     dset.pop_by_values('1')
     assert dict(dset) == {'foo': '2'}
     dset.pop_by_values('2')
     assert dict(dset) == {}
开发者ID:karthikmm,项目名称:nefertari,代码行数:8,代码来源:test_dictset.py

示例6: test_process_bool_param

 def test_process_bool_param(self):
     dset = dictset({'boo': 'true', 'foo': 'false'})
     assert dset.process_bool_param('boo')
     assert not dset.process_bool_param('foo')
     assert dset.boo
     assert not dset.foo
     assert isinstance(dset.boo, bool)
     assert isinstance(dset.foo, bool)
开发者ID:karthikmm,项目名称:nefertari,代码行数:8,代码来源:test_dictset.py

示例7: test_asbool

 def test_asbool(self):
     dset1 = dictset({
         'foo': 'true', 'fruit': 'false',
         'baz': True, 'zoo': False})
     assert dset1.asbool('foo')
     assert dset1.asbool('baz')
     assert isinstance(dset1.asbool('foo'), bool)
     assert isinstance(dset1.asbool('baz'), bool)
     assert not dset1.asbool('fruit')
     assert not dset1.asbool('zoo')
开发者ID:karthikmm,项目名称:nefertari,代码行数:10,代码来源:test_dictset.py

示例8: to_dict

    def to_dict(self, **kwargs):
        _dict = dictset()
        _keys = kwargs.pop('_keys', [])
        _depth = kwargs.pop('_depth', 1)

        data = dictset(self._data).subset(_keys) if _keys else self._data

        for attr, val in data.items():
            _dict[attr] = val
            if _depth:
                kw = kwargs.copy()
                kw['_depth'] = _depth - 1

                if hasattr(val, 'to_dict'):
                    _dict[attr] = val.to_dict(**kw)
                elif isinstance(val, list):
                    _dict[attr] = to_dicts(val, **kw)

        _dict['_type'] = self.__class__.__name__
        return _dict
开发者ID:mbijon,项目名称:nefertari,代码行数:20,代码来源:data.py

示例9: test_reserved_params_dropped

 def test_reserved_params_dropped(
         self, mock_check, mock_drop, simple_model, memory_db):
     from nefertari.utils import dictset
     memory_db()
     mock_drop.side_effect = lambda x: dictset({'name': 'a'})
     try:
         simple_model.get_collection(_limit=1, __strict=True)
     except JHTTPBadRequest:
         raise Exception('Unexpected JHTTPBadRequest exception')
     mock_drop.assert_called_once_with({})
     mock_check.assert_called_once_with(['name'])
开发者ID:numb3r3,项目名称:nefertari-sqla,代码行数:11,代码来源:test_documents.py

示例10: test_process_datetime_param

 def test_process_datetime_param(self):
     dset = dictset({'boo': '2014-01-02T03:04:05Z'})
     dtime = dset.process_datetime_param('boo')
     assert dtime is dset.boo
     assert dtime == dset.boo
     assert isinstance(dtime, datetime)
     assert dtime.year == 2014
     assert dtime.month == 1
     assert dtime.day == 2
     assert dtime.hour == 3
     assert dtime.minute == 4
     assert dtime.second == 5
开发者ID:karthikmm,项目名称:nefertari,代码行数:12,代码来源:test_dictset.py

示例11: obj2dict

def obj2dict(obj, classkey=None):
    if isinstance(obj, dict):
        for k in obj.keys():
            obj[k] = obj2dict(obj[k], classkey)
        return obj
    elif issequence(obj):
        return [obj2dict(v, classkey) for v in obj]
    elif hasattr(obj, "__dict__"):
        data = dictset([
            (key, obj2dict(value, classkey))
            for key, value in obj.__dict__.items()
            if not six.callable(value) and not key.startswith('_')
        ])
        if classkey is not None and hasattr(obj, "__class__"):
            data[classkey] = obj.__class__.__name__
        return data
    else:
        return obj
开发者ID:mbijon,项目名称:nefertari,代码行数:18,代码来源:data.py

示例12: test_process_dict_param_type

 def test_process_dict_param_type(self):
     dset = dictset({'boo': 'a:1'})
     assert dset.process_dict_param('boo', _type=lambda x: int(x)) == {
         'a': 1}
     assert dset.boo == {'a': 1}
开发者ID:karthikmm,项目名称:nefertari,代码行数:5,代码来源:test_dictset.py

示例13: test_process_dict_param_pop

 def test_process_dict_param_pop(self):
     dset = dictset({'boo': 'a:1'})
     assert dset.process_dict_param('boo', pop=True) == {'a': '1'}
     assert 'boo' not in dset
开发者ID:karthikmm,项目名称:nefertari,代码行数:4,代码来源:test_dictset.py

示例14: test_asfloat

 def test_asfloat(self):
     assert dictset({'foo': '1.0'}).asfloat('foo') == 1.0
开发者ID:karthikmm,项目名称:nefertari,代码行数:2,代码来源:test_dictset.py

示例15: test_asint_default

 def test_asint_default(self):
     dset = dictset({'foo': '1'})
     assert dset.asint('foo1', default=2) == 2
     assert 'foo1' not in dset
开发者ID:karthikmm,项目名称:nefertari,代码行数:4,代码来源:test_dictset.py


注:本文中的nefertari.utils.dictset.dictset函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。