• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python streams.Stream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中streams.Stream的典型用法代码示例。如果您正苦于以下问题:Python Stream类的具体用法?Python Stream怎么用?Python Stream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Stream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: test_it_should_apply_a_side_effect_to_the_stream

 def test_it_should_apply_a_side_effect_to_the_stream(self):
     side_list = []
     stream = Stream.range(10)
     self.assertEqual(side_list, list(stream.peek(side_list.append)))
开发者ID:9seconds,项目名称:streams,代码行数:4,代码来源:test_stream.py


示例17: test_it_should_iterate_on_a_seed_value

 def test_it_should_iterate_on_a_seed_value(self):
     i = iter(Stream.iterate(lambda x: x * 10, 1))
     self.assertEqual(next(i), 1)
     self.assertEqual(next(i), 10)
     self.assertEqual(next(i), 100)
     self.assertEqual(next(i), 1000)
开发者ID:9seconds,项目名称:streams,代码行数:6,代码来源:test_stream.py


示例18: test_it_should_include_only_values

 def test_it_should_include_only_values(self):
     stream = Stream(list(zip(range(10), range(100, 110),
                              range(20, 30))) + ['foo'])
     values = stream.values()
     self.assertListEqual(list(values), list(range(20, 30)) + ['foo'])
开发者ID:9seconds,项目名称:streams,代码行数:5,代码来源:test_stream.py


示例19: test_it_should_produce_a_range

 def test_it_should_produce_a_range(self):
     stream = Stream.range(10)
     self.assertIsInstance(stream, Stream)
     self.assertEqual(list(stream), list(range(10)))
开发者ID:9seconds,项目名称:streams,代码行数:4,代码来源:test_stream.py


示例20: test_it_should_expand_a_stream_to_tuples

    def test_it_should_expand_a_stream_to_tuples(self):
        tuples = Stream.range(10).tuplify()
        self.assertListEqual(list(tuples), [(i, i) for i in range(10)])

        tuples = Stream.range(10).tuplify(clones=4)
        self.assertListEqual(list(tuples), [(i, i, i, i) for i in range(10)])
开发者ID:9seconds,项目名称:streams,代码行数:6,代码来源:test_stream.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tester.Tester类代码示例发布时间:2022-05-27
下一篇:
Python streams.serial函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap