Python collections.ItemsView() Examples
The following are 8
code examples of collections.ItemsView().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
collections
, or try the search function
.
Example #1
Source File: test_dictviews.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_abc_registry(self): d = dict(a=1) self.assertIsInstance(d.viewkeys(), collections.KeysView) self.assertIsInstance(d.viewkeys(), collections.MappingView) self.assertIsInstance(d.viewkeys(), collections.Set) self.assertIsInstance(d.viewkeys(), collections.Sized) self.assertIsInstance(d.viewkeys(), collections.Iterable) self.assertIsInstance(d.viewkeys(), collections.Container) self.assertIsInstance(d.viewvalues(), collections.ValuesView) self.assertIsInstance(d.viewvalues(), collections.MappingView) self.assertIsInstance(d.viewvalues(), collections.Sized) self.assertIsInstance(d.viewitems(), collections.ItemsView) self.assertIsInstance(d.viewitems(), collections.MappingView) self.assertIsInstance(d.viewitems(), collections.Set) self.assertIsInstance(d.viewitems(), collections.Sized) self.assertIsInstance(d.viewitems(), collections.Iterable) self.assertIsInstance(d.viewitems(), collections.Container)
Example #2
Source File: 6_16_dictsorted.py From Python-Journey-from-Novice-to-Expert with MIT License | 5 votes |
def items(self): return ItemsView(self)
Example #3
Source File: ordereddict.py From pyRevit with GNU General Public License v3.0 | 5 votes |
def viewitems(self): "Return set-like object with view of mapping items." return ItemsView(self)
Example #4
Source File: boltons_utils.py From hyperparameter_hunter with MIT License | 5 votes |
def default_enter(path, key, value): # print('enter(%r, %r)' % (key, value)) if isinstance(value, basestring): return value, False elif isinstance(value, Mapping): return value.__class__(), ItemsView(value) elif isinstance(value, Sequence): return value.__class__(), enumerate(value) elif isinstance(value, Set): return value.__class__(), enumerate(value) else: # files, strings, other iterables, and scalars are not # traversed return value, False
Example #5
Source File: 6_16_dictsorted.py From Python_Master-the-Art-of-Design-Patterns with MIT License | 5 votes |
def items(self): return ItemsView(self)
Example #6
Source File: request_environment.py From python-compat-runtime with Apache License 2.0 | 5 votes |
def viewitems(self): return collections.ItemsView(self)
Example #7
Source File: _mutablemapping.py From compas with MIT License | 5 votes |
def items(self): """D.items() => a set-like object providing a view on D's items""" return stdlib_collections.ItemsView(self)
Example #8
Source File: test_data_spec.py From n6 with GNU Affero General Public License v3.0 | 4 votes |
def for_various_result_types_of__filter_by_which(test_meth): # Taking into consideration that the data specification's # overridable method `filter_by_which()` is required to return a # container that is either a *dict items view* or a *set-like* # object, we want to ensure that the methods which call # `filter_by_which()` handle the call results properly for various # types of these results (i.e., regardless of whether the result is # a *dict items view* or a *set-like* object; regardless of whether # the object is an instance of a builtin type or of a custom one; # and regardless of whether the object is mutable or immutable...). # # By wrapping with this decorator a test of a data specification's # method which uses `filter_by_which()` call results *and* by # decorating the test case class that contains such a test with # `@unittest_expander.expand` -- we ensure that the method will be # tested for various kinds of types of `filter_by_which()` call # results. @foreach([ None, lambda iterable: dict(iterable).viewitems(), lambda iterable: collections.ItemsView(dict(iterable)), frozenset, set, CustomImmutableSet, CustomMutableSet, ]) @functools.wraps(test_meth) def decorated_test_meth(self, result_type_adjuster): if result_type_adjuster is None: test_meth(self) return called = [] wrapped = _make_wrapped__filter_by_which( result_type_adjuster, called, orig=self.base_data_spec_class.filter_by_which) with patch.object(self.base_data_spec_class, 'filter_by_which', wrapped): assert not called, 'bug in the test' test_meth(self) assert called, 'bug in the test' def _make_wrapped__filter_by_which(result_type_adjuster, called, orig): @staticmethod def wrapped(*args, **kwargs): called.append(None) orig_result = orig(*args, **kwargs) return result_type_adjuster(orig_result) return wrapped return decorated_test_meth # # Mix-ins for test case classes #