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


Python collections.UserDict方法代码示例

本文整理汇总了Python中collections.UserDict方法的典型用法代码示例。如果您正苦于以下问题:Python collections.UserDict方法的具体用法?Python collections.UserDict怎么用?Python collections.UserDict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在collections的用法示例。


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

示例1: test_extract_auth_params

# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserDict [as 别名]
def test_extract_auth_params():
    request = UserDict()

    request.headers = {}
    assert _extract_auth_params(request) is None

    request.headers = {'Authorization': 'no-space'}
    with pytest.raises(InvalidAuthParameters):
        _extract_auth_params(request)

    request.headers = {'Authorization': ('BadAuthType signMethod=HMAC-SHA256,'
                                         'credential=fake-ak:fake-sig')}
    with pytest.raises(InvalidAuthParameters):
        _extract_auth_params(request)

    request.headers = {'Authorization': ('BackendAI signMethod=HMAC-SHA256,'
                                         'credential=fake-ak:fake-sig')}
    ret = _extract_auth_params(request)
    assert ret[0] == 'HMAC-SHA256'
    assert ret[1] == 'fake-ak'
    assert ret[2] == 'fake-sig' 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:23,代码来源:test_auth.py

示例2: test_custom_asserts

# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserDict [as 别名]
def test_custom_asserts(self):
        # This would always trigger the KeyError from trying to put
        # an array of equal-length UserDicts inside an ndarray.
        data = JSONArray([collections.UserDict({'a': 1}),
                          collections.UserDict({'b': 2}),
                          collections.UserDict({'c': 3})])
        a = pd.Series(data)
        self.assert_series_equal(a, a)
        self.assert_frame_equal(a.to_frame(), a.to_frame())

        b = pd.Series(data.take([0, 0, 1]))
        with pytest.raises(AssertionError):
            self.assert_series_equal(a, b)

        with pytest.raises(AssertionError):
            self.assert_frame_equal(a.to_frame(), b.to_frame()) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_json.py

示例3: test_MutableMapping_subclass

# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserDict [as 别名]
def test_MutableMapping_subclass(self):
        # Test issue 9214
        mymap = UserDict()
        mymap['red'] = 5
        self.assertIsInstance(mymap.keys(), Set)
        self.assertIsInstance(mymap.keys(), KeysView)
        self.assertIsInstance(mymap.items(), Set)
        self.assertIsInstance(mymap.items(), ItemsView)

        mymap = UserDict()
        mymap['red'] = 5
        z = mymap.keys() | {'orange'}
        self.assertIsInstance(z, set)
        list(z)
        mymap['blue'] = 7               # Shouldn't affect 'z'
        self.assertEqual(sorted(z), ['orange', 'red'])

        mymap = UserDict()
        mymap['red'] = 5
        z = mymap.items() | {('orange', 3)}
        self.assertIsInstance(z, set)
        list(z)
        mymap['blue'] = 7               # Shouldn't affect 'z'
        self.assertEqual(sorted(z), [('orange', 3), ('red', 5)]) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:26,代码来源:test_collections.py

示例4: test_compat_pickle

# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserDict [as 别名]
def test_compat_pickle(self):
        tests = [
            (range(1, 7), '__builtin__', 'xrange'),
            (map(int, '123'), 'itertools', 'imap'),
            (functools.reduce, '__builtin__', 'reduce'),
            (dbm.whichdb, 'whichdb', 'whichdb'),
            (Exception(), 'exceptions', 'Exception'),
            (collections.UserDict(), 'UserDict', 'IterableUserDict'),
            (collections.UserList(), 'UserList', 'UserList'),
            (collections.defaultdict(), 'collections', 'defaultdict'),
        ]
        for val, mod, name in tests:
            for proto in range(3):
                with self.subTest(type=type(val), proto=proto):
                    pickled = self.dumps(val, proto)
                    self.assertIn(('c%s\n%s' % (mod, name)).encode(), pickled)
                    self.assertIs(type(self.loads(pickled)), type(val)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:pickletester.py

示例5: test_plain

# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserDict [as 别名]
def test_plain(self):
        f = self.makeCallable('a, b=1')
        self.assertEqualCallArgs(f, '2')
        self.assertEqualCallArgs(f, '2, 3')
        self.assertEqualCallArgs(f, 'a=2')
        self.assertEqualCallArgs(f, 'b=3, a=2')
        self.assertEqualCallArgs(f, '2, b=3')
        # expand *iterable / **mapping
        self.assertEqualCallArgs(f, '*(2,)')
        self.assertEqualCallArgs(f, '*[2]')
        self.assertEqualCallArgs(f, '*(2, 3)')
        self.assertEqualCallArgs(f, '*[2, 3]')
        self.assertEqualCallArgs(f, '**{"a":2}')
        self.assertEqualCallArgs(f, 'b=3, **{"a":2}')
        self.assertEqualCallArgs(f, '2, **{"b":3}')
        self.assertEqualCallArgs(f, '**{"b":3, "a":2}')
        # expand UserList / UserDict
        self.assertEqualCallArgs(f, '*collections.UserList([2])')
        self.assertEqualCallArgs(f, '*collections.UserList([2, 3])')
        self.assertEqualCallArgs(f, '**collections.UserDict(a=2)')
        self.assertEqualCallArgs(f, '2, **collections.UserDict(b=3)')
        self.assertEqualCallArgs(f, 'b=2, **collections.UserDict(a=3)') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,代码来源:test_inspect.py

示例6: test_multiple_features

# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserDict [as 别名]
def test_multiple_features(self):
        f = self.makeCallable('a, b=2, *f, **g')
        self.assertEqualCallArgs(f, '2, 3, 7')
        self.assertEqualCallArgs(f, '2, 3, x=8')
        self.assertEqualCallArgs(f, '2, 3, x=8, *[(4,[5,6]), 7]')
        self.assertEqualCallArgs(f, '2, x=8, *[3, (4,[5,6]), 7], y=9')
        self.assertEqualCallArgs(f, 'x=8, *[2, 3, (4,[5,6])], y=9')
        self.assertEqualCallArgs(f, 'x=8, *collections.UserList('
                                 '[2, 3, (4,[5,6])]), **{"y":9, "z":10}')
        self.assertEqualCallArgs(f, '2, x=8, *collections.UserList([3, '
                                 '(4,[5,6])]), **collections.UserDict('
                                 'y=9, z=10)')

        f = self.makeCallable('a, b=2, *f, x, y=99, **g')
        self.assertEqualCallArgs(f, '2, 3, x=8')
        self.assertEqualCallArgs(f, '2, 3, x=8, *[(4,[5,6]), 7]')
        self.assertEqualCallArgs(f, '2, x=8, *[3, (4,[5,6]), 7], y=9, z=10')
        self.assertEqualCallArgs(f, 'x=8, *[2, 3, (4,[5,6])], y=9, z=10')
        self.assertEqualCallArgs(f, 'x=8, *collections.UserList('
                                 '[2, 3, (4,[5,6])]), q=0, **{"y":9, "z":10}')
        self.assertEqualCallArgs(f, '2, x=8, *collections.UserList([3, '
                                 '(4,[5,6])]), q=0, **collections.UserDict('
                                 'y=9, z=10)') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:25,代码来源:test_inspect.py

示例7: test_avoid_infinite_retries

# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserDict [as 别名]
def test_avoid_infinite_retries(capsys):
    now = datetime.now(timezone.utc)

    with patch('main.datetime', wraps=datetime) as datetime_mock:
        datetime_mock.now = Mock(return_value=now)

        old_context = UserDict()
        old_context.timestamp = (now - timedelta(seconds=15)).isoformat()
        old_context.event_id = 'old_event_id'

        young_context = UserDict()
        young_context.timestamp = (now - timedelta(seconds=5)).isoformat()
        young_context.event_id = 'young_event_id'

        main.avoid_infinite_retries(None, old_context)
        out, _ = capsys.readouterr()
        assert f"Dropped {old_context.event_id} (age 15000.0ms)" in out

        main.avoid_infinite_retries(None, young_context)
        out, _ = capsys.readouterr()
        assert f"Processed {young_context.event_id} (age 5000.0ms)" in out 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:23,代码来源:main_test.py

示例8: test_process_offensive_image

# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserDict [as 别名]
def test_process_offensive_image(
  storage_client,
  vision_client,
  __blur_image,
  capsys):
    result = UserDict()
    result.safe_search_annotation = UserDict()
    result.safe_search_annotation.adult = 5
    result.safe_search_annotation.violence = 5
    vision_client.safe_search_detection = MagicMock(return_value=result)

    filename = str(uuid.uuid4())
    data = {
      'bucket': 'my-bucket',
      'name': filename
    }

    main.blur_offensive_images(data, None)

    out, _ = capsys.readouterr()
    assert 'Analyzing %s.' % filename in out
    assert 'The image %s was detected as inappropriate.' % filename in out
    assert main.__blur_image.called 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:25,代码来源:main_test.py

示例9: test_process_safe_image

# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserDict [as 别名]
def test_process_safe_image(
  storage_client,
  vision_client,
  __blur_image,
  capsys):
    result = UserDict()
    result.safe_search_annotation = UserDict()
    result.safe_search_annotation.adult = 1
    result.safe_search_annotation.violence = 1
    vision_client.safe_search_detection = MagicMock(return_value=result)

    filename = str(uuid.uuid4())
    data = {
      'bucket': 'my-bucket',
      'name': filename
    }

    main.blur_offensive_images(data, None)

    out, _ = capsys.readouterr()

    assert 'Analyzing %s.' % filename in out
    assert 'The image %s was detected as OK.' % filename in out
    assert __blur_image.called is False 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:26,代码来源:main_test.py

示例10: test_process_safe_image

# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserDict [as 别名]
def test_process_safe_image(
  storage_client,
  vision_client,
  __blur_image,
  capsys):
    result = UserDict()
    result.safe_search_annotation = UserDict()
    result.safe_search_annotation.adult = 1
    result.safe_search_annotation.violence = 1
    vision_client.safe_search_detection = MagicMock(return_value=result)

    filename = str(uuid.uuid4())
    data = {
      'bucket': 'my-bucket',
      'name': filename
    }

    image.blur_offensive_images(data)

    out, _ = capsys.readouterr()

    assert 'Analyzing %s.' % filename in out
    assert 'The image %s was detected as OK.' % filename in out
    assert __blur_image.called is False 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:26,代码来源:image_test.py

示例11: __init__

# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserDict [as 别名]
def __init__(*args, **kwargs):
            if not args:
                raise TypeError("descriptor '__init__' of 'UserDict' object "
                                "needs an argument")
            self, args = args[0], args[1:]
            if len(args) > 1:
                raise TypeError('expected at most 1 arguments, got %d' % len(args))
            if args:
                dict = args[0]
            elif 'dict' in kwargs:
                dict = kwargs.pop('dict')
                import warnings
                warnings.warn("Passing 'dict' as keyword argument is deprecated",
                              DeprecationWarning, stacklevel=2)
            else:
                dict = None
            self.data = {}
            if dict is not None:
                self.update(dict)
            if len(kwargs):
                self.update(kwargs) 
开发者ID:mozilla,项目名称:jx-sqlite,代码行数:23,代码来源:__init__.py

示例12: test_redirects_to_https_with_port_number

# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserDict [as 别名]
def test_redirects_to_https_with_port_number(self):
        # same thing, but with :443 on the URL, see issue #180
        self.reqs['responses']['http'].url = 'https://http-observatory.security.mozilla.org:443/'

        history1 = UserDict()
        history1.request = UserDict()
        history1.request.url = 'http://http-observatory.security.mozilla.org/'

        self.reqs['responses']['http'].history.append(history1)

        result = redirection(self.reqs)

        self.assertEquals('redirection-to-https', result['result'])
        self.assertEquals(['http://http-observatory.security.mozilla.org/',
                           'https://http-observatory.security.mozilla.org:443/'], result['route'])
        self.assertTrue(result['pass']) 
开发者ID:mozilla,项目名称:http-observatory,代码行数:18,代码来源:test_misc.py

示例13: test_first_redirection_still_http

# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserDict [as 别名]
def test_first_redirection_still_http(self):
        self.reqs['responses']['http'].url = 'https://http-observatory.security.mozilla.org/foo'

        history1 = UserDict()
        history1.request = UserDict()
        history1.request.url = 'http://http-observatory.security.mozilla.org/'

        history2 = UserDict()
        history2.request = UserDict()
        history2.request.url = 'http://http-observatory.security.mozilla.org/foo'

        self.reqs['responses']['http'].history.append(history1)
        self.reqs['responses']['http'].history.append(history2)

        result = redirection(self.reqs)

        self.assertEquals('redirection-not-to-https-on-initial-redirection', result['result'])
        self.assertFalse(result['pass']) 
开发者ID:mozilla,项目名称:http-observatory,代码行数:20,代码来源:test_misc.py

示例14: test_all_redirections_preloaded

# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserDict [as 别名]
def test_all_redirections_preloaded(self):
        self.reqs['responses']['http'].url = 'https://www.pokeinthe.io/foo/bar'

        for url in ('http://pokeinthe.io/',
                    'https://pokeinthe.io/',
                    'https://www.pokeinthe.io/',
                    'https://baz.pokeinthe.io/foo'):
            history = UserDict()
            history.request = UserDict()
            history.request.url = url

            self.reqs['responses']['http'].history.append(history)

        result = redirection(self.reqs)

        self.assertEquals('redirection-all-redirects-preloaded', result['result'])
        self.assertTrue(result['pass']) 
开发者ID:mozilla,项目名称:http-observatory,代码行数:19,代码来源:test_misc.py

示例15: _from_factorized

# 需要导入模块: import collections [as 别名]
# 或者: from collections import UserDict [as 别名]
def _from_factorized(cls, values, original):
        return cls([collections.UserDict(x) for x in values if x != ()]) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:4,代码来源:array.py


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