github.com/apache/beam/sdks/v2@v2.48.2/python/apache_beam/internal/util_test.py (about)

     1  #
     2  # Licensed to the Apache Software Foundation (ASF) under one or more
     3  # contributor license agreements.  See the NOTICE file distributed with
     4  # this work for additional information regarding copyright ownership.
     5  # The ASF licenses this file to You under the Apache License, Version 2.0
     6  # (the "License"); you may not use this file except in compliance with
     7  # the License.  You may obtain a copy of the License at
     8  #
     9  #    http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  #
    17  
    18  """Unit tests for the util module."""
    19  # pytype: skip-file
    20  
    21  import unittest
    22  
    23  from apache_beam.internal.util import ArgumentPlaceholder
    24  from apache_beam.internal.util import insert_values_in_args
    25  from apache_beam.internal.util import remove_objects_from_args
    26  
    27  
    28  class UtilTest(unittest.TestCase):
    29    def test_remove_objects_from_args(self):
    30      args, kwargs, objs = remove_objects_from_args(
    31          [1, 'a'], {'x': 1, 'y': 3.14}, (str, float))
    32      self.assertEqual([1, ArgumentPlaceholder()], args)
    33      self.assertEqual({'x': 1, 'y': ArgumentPlaceholder()}, kwargs)
    34      self.assertEqual(['a', 3.14], objs)
    35  
    36    def test_remove_objects_from_args_nothing_to_remove(self):
    37      args, kwargs, objs = remove_objects_from_args(
    38          [1, 2], {'x': 1, 'y': 2}, (str, float))
    39      self.assertEqual([1, 2], args)
    40      self.assertEqual({'x': 1, 'y': 2}, kwargs)
    41      self.assertEqual([], objs)
    42  
    43    def test_insert_values_in_args(self):
    44      values = ['a', 'b']
    45      args = [1, ArgumentPlaceholder()]
    46      kwargs = {'x': 1, 'y': ArgumentPlaceholder()}
    47      args, kwargs = insert_values_in_args(args, kwargs, values)
    48      self.assertEqual([1, 'a'], args)
    49      self.assertEqual({'x': 1, 'y': 'b'}, kwargs)
    50  
    51    def test_insert_values_in_args_nothing_to_insert(self):
    52      values = []
    53      args = [1, 'a']
    54      kwargs = {'x': 1, 'y': 'b'}
    55      args, kwargs = insert_values_in_args(args, kwargs, values)
    56      self.assertEqual([1, 'a'], args)
    57      self.assertEqual({'x': 1, 'y': 'b'}, kwargs)
    58  
    59  
    60  if __name__ == '__main__':
    61    unittest.main()