Esempio n. 1
0
 def test_tuple_coder(self):
     kv_coder = coders.TupleCoder(
         (coders.VarIntCoder(), coders.BytesCoder()))
     # Verify cloud object representation
     self.assertEqual(
         {
             '@type':
             'kind:pair',
             'is_pair_like':
             True,
             'component_encodings': [
                 coders.VarIntCoder().as_cloud_object(),
                 coders.BytesCoder().as_cloud_object()
             ],
         }, kv_coder.as_cloud_object())
     # Test binary representation
     self.assertEqual(b'\x04abc', kv_coder.encode((4, b'abc')))
     # Test unnested
     self.check_coder(kv_coder, (1, b'a'), (-2, b'a' * 100),
                      (300, b'abc\0' * 5))
     # Test nested
     self.check_coder(
         coders.TupleCoder((coders.TupleCoder(
             (coders.PickleCoder(), coders.VarIntCoder())),
                            coders.StrUtf8Coder(), coders.BooleanCoder())),
         ((1, 2), 'a', True), ((-2, 5), u'a\u0101' * 100, False),
         ((300, 1), 'abc\0' * 5, True))
 def test_standard_bool_coder(self):
   real_coder = typecoders.registry.get_coder(bool)
   expected_coder = coders.BooleanCoder()
   self.assertEqual(real_coder.encode(True), expected_coder.encode(True))
   self.assertEqual(True, real_coder.decode(real_coder.encode(True)))
   self.assertEqual(real_coder.encode(False), expected_coder.encode(False))
   self.assertEqual(False, real_coder.decode(real_coder.encode(False)))
Esempio n. 3
0
 def test_bool_coder(self):
     self.check_coder(coders.BooleanCoder(), True, False)