Пример #1
0
    def test_to_list_and_to_dict(self):
        with TestPipeline() as pipeline:
            the_list = [6, 3, 1, 1, 9, 1, 5, 2, 0, 6]
            timestamp = 0
            pcoll = pipeline | 'start' >> Create(the_list)
            result = pcoll | 'to list' >> combine.ToList()

            # Now for global combines without default
            timestamped = pcoll | Map(lambda x: TimestampedValue(x, timestamp))
            windowed = timestamped | 'window' >> WindowInto(FixedWindows(60))
            result_windowed = (
                windowed
                | 'to list wo defaults' >> combine.ToList().without_defaults())

            def matcher(expected):
                def match(actual):
                    equal_to(expected[0])(actual[0])

                return match

            assert_that(result, matcher([the_list]))
            assert_that(result_windowed,
                        matcher([the_list]),
                        label='to-list-wo-defaults')

        with TestPipeline() as pipeline:
            pairs = [(1, 2), (3, 4), (5, 6)]
            timestamp = 0
            pcoll = pipeline | 'start-pairs' >> Create(pairs)
            result = pcoll | 'to dict' >> combine.ToDict()

            # Now for global combines without default
            timestamped = pcoll | Map(lambda x: TimestampedValue(x, timestamp))
            windowed = timestamped | 'window' >> WindowInto(FixedWindows(60))
            result_windowed = (
                windowed
                | 'to dict wo defaults' >> combine.ToDict().without_defaults())

            def matcher():
                def match(actual):
                    equal_to([1])([len(actual)])
                    equal_to(pairs)(actual[0].items())

                return match

            assert_that(result, matcher())
            assert_that(result_windowed,
                        matcher(),
                        label='to-dict-wo-defaults')
Пример #2
0
    def test_to_list_and_to_dict(self):
        pipeline = TestPipeline()
        the_list = [6, 3, 1, 1, 9, 1, 5, 2, 0, 6]
        pcoll = pipeline | 'start' >> Create(the_list)
        result = pcoll | 'to list' >> combine.ToList()

        def matcher(expected):
            def match(actual):
                equal_to(expected[0])(actual[0])

            return match

        assert_that(result, matcher([the_list]))
        pipeline.run()

        pipeline = TestPipeline()
        pairs = [(1, 2), (3, 4), (5, 6)]
        pcoll = pipeline | 'start-pairs' >> Create(pairs)
        result = pcoll | 'to dict' >> combine.ToDict()

        def matcher():
            def match(actual):
                equal_to([1])([len(actual)])
                equal_to(pairs)(actual[0].iteritems())

            return match

        assert_that(result, matcher())
        pipeline.run()