當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。