當前位置: 首頁>>代碼示例>>Python>>正文


Python streams.Stream類代碼示例

本文整理匯總了Python中streams.Stream的典型用法代碼示例。如果您正苦於以下問題:Python Stream類的具體用法?Python Stream怎麽用?Python Stream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Stream類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_it_should_limit_the_size_of_the_stream

    def test_it_should_limit_the_size_of_the_stream(self):
        stream = Stream(xrange(10000000000))
        limited = stream.limit(10)
        self.assertListEqual(list(limited), list(xrange(10)))

        stream = Stream(xrange(100))
        stream = stream.limit(1000)
        self.assertListEqual(list(stream), list(xrange(100)))
開發者ID:9seconds,項目名稱:streams,代碼行數:8,代碼來源:test_stream.py

示例2: test_it_should_map_a_function_to_the_stream

    def test_it_should_map_a_function_to_the_stream(self):
        stream = Stream(range(10))
        stream = stream.map(lambda item: -item)
        self.assertEqual(max(stream), 0)

        stream = Stream(dict((v, v) for v in xrange(100)))
        stream = stream.values().skip(10).limit(3)
        self.assertListEqual(list(stream), [10, 11, 12])
開發者ID:9seconds,項目名稱:streams,代碼行數:8,代碼來源:test_stream.py

示例3: test_divisibleby

    def test_divisibleby(self):
        stream = Stream(xrange(2000))
        stream = stream.ints().divisible_by(10)
        self.assertEqual(stream.count(), 200)

        stream = Stream(xrange(2000))
        stream = stream.divisible_by(1000)
        self.assertEquals(list(stream), [0, 1000])
開發者ID:AxelVoitier,項目名稱:streams,代碼行數:8,代碼來源:tests.py

示例4: test_it_should_concatenate_iterables

    def test_it_should_concatenate_iterables(self):
        stream = Stream.concat(Stream.range(10), Stream.range(10))
        self.assertListEqual(list(stream), list(xrange(10)) + list(xrange(10)))

        stream = Stream.concat(xrange(10), xrange(10), xrange(10))
        self.assertListEqual(list(stream.distinct()), list(xrange(10)))

        stream = Stream.concat(xrange(10), xrange(10), xrange(10))
        self.assertEqual(stream.count(), 30)
開發者ID:9seconds,項目名稱:streams,代碼行數:9,代碼來源:test_stream.py

示例5: test_it_should_filter_odds

    def test_it_should_filter_odds(self):
        stream = Stream(range(6))
        stream = stream.odds()
        self.assertListEqual(list(stream), [1, 3, 5])

        stream = Stream(xrange(200))
        stream = stream.odds()
        elements = list(stream)
        self.assertEqual(len(elements), 100)
        self.assertFalse(any(item % 2 == 0 for item in elements))
開發者ID:9seconds,項目名稱:streams,代碼行數:10,代碼來源:test_stream.py

示例6: test_it_should_filter_evens

    def test_it_should_filter_evens(self):
        stream = Stream(range(6))
        stream = stream.evens()
        self.assertListEqual(list(stream), [0, 2, 4])

        stream = Stream(xrange(200))
        stream = stream.ints().evens()
        elements = list(stream)
        self.assertEqual(len(elements), 100)
        self.assertTrue(all(item % 2 == 0 for item in elements))
開發者ID:9seconds,項目名稱:streams,代碼行數:10,代碼來源:test_stream.py

示例7: test_it_should_filter_by_regular_expression

    def test_it_should_filter_by_regular_expression(self):
        stream = Stream((text_type(x) for x in xrange(100)))
        ones = stream.regexp(r'^1')
        self.assertListEqual(
            list(ones),
            ['1', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19'])

        stream = Stream(str(item) for item in xrange(1000))
        stream = stream.regexp(r"^10*$")
        stream = stream.ints()
        self.assertListEqual(list(stream), [1, 10, 100])
開發者ID:9seconds,項目名稱:streams,代碼行數:11,代碼來源:test_stream.py

示例8: test_it_should_filter_instances_of_a_class

    def test_it_should_filter_instances_of_a_class(self):
        items = list(xrange(10)) + ['foo', 'bar', 'baz']
        stream = Stream(items)
        strings = stream.instances_of(string_types)
        self.assertListEqual(list(strings), ['foo', 'bar', 'baz'])

        elements = list(xrange(100))
        # noinspection PyTypeChecker
        elements = elements + [str(item) for item in elements] + [None, None]
        strings = list(Stream(elements).instances_of(str))
        ints = list(Stream(elements).instances_of(int))
        self.assertEqual(len(strings), 100)
        self.assertTrue(all(isinstance(item, str) for item in strings))
        self.assertEqual(len(ints), 100)
        self.assertTrue(all(isinstance(item, int) for item in ints))
開發者ID:9seconds,項目名稱:streams,代碼行數:15,代碼來源:test_stream.py

示例9: test_no_cache

 def test_no_cache(self):
     # Make a normal stream.
     stream = Stream.range(10)
     # Iterate once
     self.assertEqual(list(stream), list(range(10)))
     # Iterate twice
     self.assertEqual(list(stream), [])
開發者ID:9seconds,項目名稱:streams,代碼行數:7,代碼來源:test_stream.py

示例10: test_it_should_filter_items

    def test_it_should_filter_items(self):
        stream = Stream(range(10))
        stream = stream.filter(lambda item: item % 2)
        self.assertEqual(stream.sum(), 25)

        stream = Stream(dict((v, v) for v in xrange(100)))
        stream = stream.filter(lambda kv: kv[0] % 2)
        stream = stream.filter(lambda kv: kv[0] % 10, parallel=6)
        stream = stream.limit(5).keys()
        stream = list(stream)
        self.assertListEqual(list(stream), [1, 3, 5, 7, 9])
開發者ID:9seconds,項目名稱:streams,代碼行數:11,代碼來源:test_stream.py

示例11: test_limit

    def test_limit(self):
        stream = Stream(xrange(100))
        stream = stream.limit(50)
        self.assertEqual(stream.count(), 50)

        stream = Stream(xrange(100))
        stream = stream.limit(1000)
        self.assertEqual(stream.count(), 100)
開發者ID:AxelVoitier,項目名稱:streams,代碼行數:8,代碼來源:tests.py

示例12: test_it_should_count_the_number_of_occurrences_in_the_stream

    def test_it_should_count_the_number_of_occurrences_in_the_stream(self):
        stream = Stream(xrange(100))
        stream = stream.limit(50)
        self.assertEqual(stream.count(), 50)

        stream = Stream(xrange(100))
        stream = stream.limit(1000)
        self.assertEqual(stream.count(), 100)
開發者ID:9seconds,項目名稱:streams,代碼行數:8,代碼來源:test_stream.py

示例13: test_it_should_filter_by_divisibility

    def test_it_should_filter_by_divisibility(self):
        stream = Stream(range(6))
        stream = stream.divisible_by(2)
        self.assertListEqual(list(stream), [0, 2, 4])

        stream = Stream(xrange(2000))
        stream = stream.ints().divisible_by(10)
        self.assertEqual(stream.count(), 200)

        stream = Stream(xrange(2000))
        stream = stream.divisible_by(1000)
        self.assertEquals(list(stream), [0, 1000])
開發者ID:9seconds,項目名稱:streams,代碼行數:12,代碼來源:test_stream.py

示例14: test_cache

    def test_cache(self):
        # Make a cached stream.
        stream = Stream.range(10).cache()
        # Iterate once
        self.assertEqual(list(stream), list(range(10)))
        # Iterate twice, this time from the cache.
        self.assertEqual(list(stream), list(range(10)))

        # Now, we make a new, smaller, cached stream fromm our cached stream.
        stream = stream.cache(5)
        # Iterate once
        self.assertEqual(list(stream), list(range(10)))
        # Iterate twice, this time from the cache. We get the last 5 values.
        self.assertEqual(list(stream), list(range(5, 10)))
開發者ID:9seconds,項目名稱:streams,代碼行數:14,代碼來源:test_stream.py

示例15: test_it_should_iterate_over_an_iterable_multiple_times

 def test_it_should_iterate_over_an_iterable_multiple_times(self):
     stream = Stream.range(10)
     self.assertListEqual(list(stream), list(xrange(10)))
     self.assertListEqual(list(stream), [])
開發者ID:9seconds,項目名稱:streams,代碼行數:4,代碼來源:test_stream.py


注:本文中的streams.Stream類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。