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


Python abc.Iterator方法代码示例

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


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

示例1: test_Iterator

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Iterator [as 别名]
def test_Iterator(self):
        non_samples = [None, 42, 3.14, 1j, b"", "", (), [], {}, set()]
        for x in non_samples:
            self.assertNotIsInstance(x, Iterator)
            self.assertFalse(issubclass(type(x), Iterator), repr(type(x)))
        samples = [iter(bytes()), iter(str()),
                   iter(tuple()), iter(list()), iter(dict()),
                   iter(set()), iter(frozenset()),
                   iter(dict().keys()), iter(dict().items()),
                   iter(dict().values()),
                   (lambda: (yield))(),
                   (x for x in []),
                   ]
        for x in samples:
            self.assertIsInstance(x, Iterator)
            self.assertTrue(issubclass(type(x), Iterator), repr(type(x)))
        self.validate_abstract_methods(Iterator, '__next__', '__iter__')

        # Issue 10565
        class NextOnly:
            def __next__(self):
                yield 1
                return
        self.assertNotIsInstance(NextOnly(), Iterator) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:26,代码来源:test_collections.py

示例2: test_construct

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Iterator [as 别名]
def test_construct(self):
        def _check_iterator(it):
            self.assertIsInstance(it, abc.Iterator)
            self.assertIsInstance(it, abc.Iterable)
        s = struct.Struct('>ibcp')
        it = s.iter_unpack(b"")
        _check_iterator(it)
        it = s.iter_unpack(b"1234567")
        _check_iterator(it)
        # Wrong bytes length
        with self.assertRaises(struct.error):
            s.iter_unpack(b"123456")
        with self.assertRaises(struct.error):
            s.iter_unpack(b"12345678")
        # Zero-length struct
        s = struct.Struct('>')
        with self.assertRaises(struct.error):
            s.iter_unpack(b"")
        with self.assertRaises(struct.error):
            s.iter_unpack(b"12") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:22,代码来源:test_struct.py

示例3: test_Iterator

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Iterator [as 别名]
def test_Iterator(self):
        non_samples = [None, 42, 3.14, 1j, b"", "", (), [], {}, set()]
        for x in non_samples:
            self.assertNotIsInstance(x, Iterator)
            self.assertFalse(issubclass(type(x), Iterator), repr(type(x)))
        samples = [iter(bytes()), iter(str()),
                   iter(tuple()), iter(list()), iter(dict()),
                   iter(set()), iter(frozenset()),
                   iter(dict().keys()), iter(dict().items()),
                   iter(dict().values()),
                   (lambda: (yield))(),
                   (x for x in []),
                   ]
        for x in samples:
            self.assertIsInstance(x, Iterator)
            self.assertTrue(issubclass(type(x), Iterator), repr(type(x)))
        self.validate_abstract_methods(Iterator, '__next__', '__iter__')

        # Issue 10565
        class NextOnly:
            def __next__(self):
                yield 1
                raise StopIteration
        self.assertNotIsInstance(NextOnly(), Iterator) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:26,代码来源:test_collections.py

示例4: test_get_sample_keys_method_local_only

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Iterator [as 别名]
def test_get_sample_keys_method_local_only(self, initialized_arrayset):
        from collections.abc import Iterator
        aset = initialized_arrayset

        # add subsamples which are not local to each subsample
        # perform the mock
        from hangar.backends import backend_decoder
        template = backend_decoder(b'50:daeaaeeaebv')
        aset['foo']._subsamples[50] = template

        assert isinstance(aset.keys(local=True), Iterator)
        res = list(aset.keys(local=True))
        assert len(res) == 1
        assert 2 in res

        del aset._samples['foo']._subsamples[50] 
开发者ID:tensorwerk,项目名称:hangar-py,代码行数:18,代码来源:test_column_nested.py

示例5: test_get_sample_items_method_local_only

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Iterator [as 别名]
def test_get_sample_items_method_local_only(self, initialized_arrayset):
        from hangar.columns.layout_nested import FlatSubsampleReader
        from collections.abc import Iterator
        aset = initialized_arrayset
        # add subsamples which are not local to each subsample
        # perform the mock
        from hangar.backends import backend_decoder
        template = backend_decoder(b'50:daeaaeeaebv')
        aset['foo']._subsamples[50] = template

        assert isinstance(aset.items(local=True), Iterator)
        res = list(aset.items(local=True))
        assert len(res) == 1
        sample_name, sample = res[0]
        assert sample_name == 2
        assert isinstance(sample, FlatSubsampleReader)
        assert sample.sample == sample_name

        del aset._samples['foo']._subsamples[50] 
开发者ID:tensorwerk,项目名称:hangar-py,代码行数:21,代码来源:test_column_nested.py

示例6: test_Iterator

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Iterator [as 别名]
def test_Iterator(self):
        non_samples = [None, 42, 3.14, 1j, b"", "", (), [], {}, set()]
        for x in non_samples:
            self.assertNotIsInstance(x, Iterator)
            self.assertFalse(issubclass(type(x), Iterator), repr(type(x)))
        samples = [iter(bytes()), iter(str()),
                   iter(tuple()), iter(list()), iter(dict()),
                   iter(set()), iter(frozenset()),
                   iter(dict().keys()), iter(dict().items()),
                   iter(dict().values()),
                   _test_gen(),
                   (x for x in []),
                   ]
        for x in samples:
            self.assertIsInstance(x, Iterator)
            self.assertTrue(issubclass(type(x), Iterator), repr(type(x)))
        self.validate_abstract_methods(Iterator, '__next__', '__iter__')

        # Issue 10565
        class NextOnly:
            def __next__(self):
                yield 1
                return
        self.assertNotIsInstance(NextOnly(), Iterator) 
开发者ID:bkerler,项目名称:android_universal,代码行数:26,代码来源:test_collections.py

示例7: _test_files

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Iterator [as 别名]
def _test_files(files_iter):
        assert isinstance(files_iter, Iterator), files_iter
        files = list(files_iter)
        root = files[0].root
        for file in files:
            assert file.root == root
            assert not file.hash or file.hash.value
            assert not file.hash or file.hash.mode == 'sha256'
            assert not file.size or file.size >= 0
            assert file.locate().exists()
            assert isinstance(file.read_binary(), bytes)
            if file.name.endswith('.py'):
                file.read_text() 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:15,代码来源:test_api.py

示例8: __iter__

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Iterator [as 别名]
def __iter__(self):
        # Inherited __init__ puts the Mapping into self._mapping
        return iter(self._mapping._data.flat)


# developer note: Iterator functionality is deprecated 
开发者ID:dwavesystems,项目名称:dimod,代码行数:8,代码来源:samples.py

示例9: test_iterator

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Iterator [as 别名]
def test_iterator(self):
        # deprecated feature
        bqm = dimod.BinaryQuadraticModel.from_ising({}, {'ab': -1})
        sampleset = dimod.SampleSet.from_samples_bqm([{'a': -1, 'b': 1}, {'a': 1, 'b': 1}], bqm)
        self.assertIsInstance(sampleset.samples(), abc.Iterator)
        self.assertIsInstance(sampleset.samples(n=2), abc.Iterator)
        spl = next(sampleset.samples())
        self.assertEqual(spl, {'a': 1, 'b': 1}) 
开发者ID:dwavesystems,项目名称:dimod,代码行数:10,代码来源:test_sampleset.py

示例10: test_direct_subclassing

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Iterator [as 别名]
def test_direct_subclassing(self):
        for B in Hashable, Iterable, Iterator, Sized, Container, Callable:
            class C(B):
                pass
            self.assertTrue(issubclass(C, B))
            self.assertFalse(issubclass(int, C)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_collections.py

示例11: test_registration

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Iterator [as 别名]
def test_registration(self):
        for B in Hashable, Iterable, Iterator, Sized, Container, Callable:
            class C:
                __hash__ = None  # Make sure it isn't hashable by default
            self.assertFalse(issubclass(C, B), B.__name__)
            B.register(C)
            self.assertTrue(issubclass(C, B)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:test_collections.py

示例12: __reversed__

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Iterator [as 别名]
def __reversed__(self) -> 'Iterator[T_co]':
        pass 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:4,代码来源:typing.py

示例13: devices

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Iterator [as 别名]
def devices(self, cursor: Union[str, None] = None) -> Iterator:
        """Get an iterable object which calls fetch or sync to retrieve all device records.

        Args:
              cursor (str): If supplied, the cursor returned will perform the sync operation. Otherwise you will
                receive a cursor that performs a fetch for each iteration, until the fetch cursor is exhausted.

        Returns:
              Union[DEPSyncCursor, DEPFetchCursor]: A cursor that is iterable
        """
        if cursor is not None:  # Could actually be an expired cursor here
            return DEPSyncCursor(self, cursor=cursor)
        else:
            return DEPFetchCursor(self) 
开发者ID:cmdmnt,项目名称:commandment,代码行数:16,代码来源:dep.py

示例14: test_get_sample_keys_method

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Iterator [as 别名]
def test_get_sample_keys_method(self, initialized_arrayset):
        from collections.abc import Iterator
        aset = initialized_arrayset

        assert isinstance(aset.keys(), Iterator)
        res = list(aset.keys())
        assert len(res) == 2
        assert 2 and 'foo' in res 
开发者ID:tensorwerk,项目名称:hangar-py,代码行数:10,代码来源:test_column_nested.py

示例15: test_get_sample_subsample_keys_method

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import Iterator [as 别名]
def test_get_sample_subsample_keys_method(self, initialized_arrayset, subsample_data_map):
        from collections.abc import Iterator

        aset = initialized_arrayset
        for sample_name, subsample_data in subsample_data_map.items():
            sample = aset.get(sample_name)
            assert isinstance(sample.keys(), Iterator)
            res = list(sample.keys())
            for k in res:
                assert k in subsample_data 
开发者ID:tensorwerk,项目名称:hangar-py,代码行数:12,代码来源:test_column_nested.py


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