Beispiel #1
0
 def test_iterable_coder(self):
     iterable_coder = coders.IterableCoder(coders.VarIntCoder())
     # Verify cloud object representation
     self.assertEqual(
         {
             '@type': 'kind:stream',
             'is_stream_like': True,
             'component_encodings':
             [coders.VarIntCoder().as_cloud_object()]
         }, iterable_coder.as_cloud_object())
     # Test unnested
     self.check_coder(iterable_coder, [1], [-1, 0, 100])
     # Test nested
     self.check_coder(
         coders.TupleCoder((coders.VarIntCoder(),
                            coders.IterableCoder(coders.VarIntCoder()))),
         (1, [1, 2, 3]))
Beispiel #2
0
    def _test_iterable_coder_of_unknown_length(self, count):
        def iter_generator(count):
            for i in range(count):
                yield i

        iterable_coder = coders.IterableCoder(coders.VarIntCoder())
        self.assertItemsEqual(
            list(iter_generator(count)),
            iterable_coder.decode(iterable_coder.encode(
                iter_generator(count))))