From d51a6012e22f34b9587a029fc8214915beea9fcb Mon Sep 17 00:00:00 2001 From: Brian Hulette Date: Mon, 16 May 2022 15:55:35 -0700 Subject: [PATCH] [BEAM-14411] Re-enable TypecodersTest, fix most issues (#17547) * Re-enable TypecodersTest, fix most issues * yapf * lint --- .../apache_beam/coders/typecoders_test.py | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/sdks/python/apache_beam/coders/typecoders_test.py b/sdks/python/apache_beam/coders/typecoders_test.py index f74483ad48dc..442aa24a8b0e 100644 --- a/sdks/python/apache_beam/coders/typecoders_test.py +++ b/sdks/python/apache_beam/coders/typecoders_test.py @@ -23,7 +23,6 @@ from apache_beam.coders import coders from apache_beam.coders import typecoders from apache_beam.internal import pickler -from apache_beam.tools import utils from apache_beam.typehints import typehints @@ -40,7 +39,7 @@ def __hash__(self): class CustomCoder(coders.Coder): def encode(self, value): - return str(value.number) + return str(value.number).encode('ASCII') def decode(self, encoded): return CustomClass(int(encoded)) @@ -53,21 +52,15 @@ def is_deterministic(self): class TypeCodersTest(unittest.TestCase): - def setUp(self): - try: - utils.check_compiled('apache_beam.coders') - except RuntimeError: - self.skipTest('Cython is not installed') - def test_register_non_type_coder(self): coder = CustomCoder() - with self.assertRaises(TypeError) as e: + with self.assertRaisesRegex( + TypeError, + ('Coder registration requires a coder class object. ' + 'Received %r instead.' % coder)): + # When registering a coder the coder class must be specified. typecoders.registry.register_coder(CustomClass, coder) - self.assertEqual( - e.exception.message, - 'Coder registration requires a coder class object. ' - 'Received %r instead.' % coder) def test_get_coder_with_custom_coder(self): typecoders.registry.register_coder(CustomClass, CustomCoder) @@ -128,6 +121,7 @@ def test_iterable_coder(self): self.assertEqual(expected_coder, real_coder) self.assertEqual(real_coder.encode(values), expected_coder.encode(values)) + @unittest.skip('BEAM-14411') def test_list_coder(self): real_coder = typecoders.registry.get_coder(typehints.List[bytes]) expected_coder = coders.IterableCoder(coders.BytesCoder()) @@ -142,7 +136,7 @@ def test_list_coder(self): def test_nullable_coder(self): expected_coder = coders.NullableCoder(coders.BytesCoder()) - real_coder = typecoders.registry.get_coder(typehints.Optional(bytes)) + real_coder = typecoders.registry.get_coder(typehints.Optional[bytes]) self.assertEqual(expected_coder, real_coder) self.assertEqual(expected_coder.encode(None), real_coder.encode(None)) self.assertEqual(expected_coder.encode(b'abc'), real_coder.encode(b'abc'))