Skip to content

Commit

Permalink
[BEAM-14411] Re-enable TypecodersTest, fix most issues (#17547)
Browse files Browse the repository at this point in the history
* Re-enable TypecodersTest, fix most issues

* yapf

* lint
  • Loading branch information
TheNeuralBit authored May 16, 2022
1 parent f174eba commit d51a601
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions sdks/python/apache_beam/coders/typecoders_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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))
Expand All @@ -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)
Expand Down Expand Up @@ -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())
Expand All @@ -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'))
Expand Down

0 comments on commit d51a601

Please sign in to comment.