Esempio n. 1
0
"""Test for the custom coders example."""

# pytype: skip-file

from __future__ import absolute_import

import logging
import tempfile
import unittest

from apache_beam.examples.cookbook import group_with_coder
from apache_beam.testing.util import open_shards

# Patch group_with_coder.PlayerCoder.decode(). To test that the PlayerCoder was
# used, we do not strip the prepended 'x:' string when decoding a Player object.
group_with_coder.PlayerCoder.decode = lambda self, s: group_with_coder.Player(  # type: ignore[assignment]
    s.decode('utf-8'))


class GroupWithCoderTest(unittest.TestCase):

    SAMPLE_RECORDS = [
        'joe,10', 'fred,3', 'mary,7', 'joe,20', 'fred,6', 'ann,5', 'joe,30',
        'ann,10', 'mary,1'
    ]

    def create_temp_file(self, records):
        with tempfile.NamedTemporaryFile(delete=False) as f:
            for record in records:
                f.write(b'%s\n' % record.encode('utf-8'))
            return f.name
Esempio n. 2
0

"""Test for the custom coders example."""

import logging
import tempfile
import unittest

from apache_beam.examples.cookbook import group_with_coder


# Patch group_with_coder.PlayerCoder.decode(). To test that the PlayerCoder was
# used, we do not strip the prepended 'x:' string when decoding a Player object.
group_with_coder.PlayerCoder.decode = lambda self, s: group_with_coder.Player(s)


class GroupWithCoderTest(unittest.TestCase):

  SAMPLE_RECORDS = [
      'joe,10', 'fred,3', 'mary,7',
      'joe,20', 'fred,6', 'ann,5',
      'joe,30', 'ann,10', 'mary,1']

  def create_temp_file(self, records):
    with tempfile.NamedTemporaryFile(delete=False) as f:
      for record in records:
        f.write('%s\n' % record)
      return f.name

  def test_basics_with_type_check(self):
    # Run the workflow with pipeline_type_check option. This will make sure
Esempio n. 3
0
# limitations under the License.
#
"""Test for the custom coders example."""

from __future__ import absolute_import

import logging
import tempfile
import unittest

from apache_beam.examples.cookbook import group_with_coder
from apache_beam.testing.util import open_shards

# Patch group_with_coder.PlayerCoder.decode(). To test that the PlayerCoder was
# used, we do not strip the prepended 'x:' string when decoding a Player object.
group_with_coder.PlayerCoder.decode = lambda self, s: group_with_coder.Player(
    s.decode('utf-8'))


class GroupWithCoderTest(unittest.TestCase):

    SAMPLE_RECORDS = [
        'joe,10', 'fred,3', 'mary,7', 'joe,20', 'fred,6', 'ann,5', 'joe,30',
        'ann,10', 'mary,1'
    ]

    def create_temp_file(self, records):
        with tempfile.NamedTemporaryFile(delete=False) as f:
            for record in records:
                f.write(b'%s\n' % record.encode('utf-8'))
            return f.name