kristynsmith commented on code in PR #35656:
URL: https://github.com/apache/beam/pull/35656#discussion_r2254731896


##########
sdks/python/apache_beam/internal/pickle_code_path_test.py:
##########
@@ -0,0 +1,420 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""Tests for generating stable identifiers to use for Pickle serialization."""
+
+import unittest
+
+from apache_beam.internal import code_object_pickler
+from apache_beam.internal.test_cases import after_module_add_function
+from apache_beam.internal.test_cases import after_module_add_lambda_variable
+from apache_beam.internal.test_cases import after_module_add_variable
+from apache_beam.internal.test_cases import after_module_remove_lambda_variable
+from apache_beam.internal.test_cases import after_module_remove_variable
+from apache_beam.internal.test_cases import after_module_with_classes
+from apache_beam.internal.test_cases import after_module_with_global_variable
+from apache_beam.internal.test_cases import after_module_with_nested_function
+from apache_beam.internal.test_cases import after_module_with_nested_function_2
+from apache_beam.internal.test_cases import after_module_with_single_class
+from apache_beam.internal.test_cases import before_module_with_classes
+from apache_beam.internal.test_cases import before_module_with_functions
+from apache_beam.internal.test_cases import before_module_with_lambdas
+from apache_beam.internal.test_cases import module_with_default_argument
+
+
+class CodePathTest(unittest.TestCase):
+  def test_get_code_from_stable_reference_empty_path(self):
+    with self.assertRaisesRegex(ValueError, "Path must not be empty"):
+      code_object_pickler._get_code_from_stable_reference("")
+
+  def test_get_code_from_stable_reference_invalid_default_index(self):
+    with self.assertRaisesRegex(ValueError, "out of bounds"):
+      code_object_pickler._get_code_from_stable_reference(
+          "apache_beam.internal.test_cases.module_with_default_argument."
+          "function_with_lambda_default_argument.__defaults__[1]")
+
+  def test_get_code_from_stable_reference_invalid_single_name_path(self):
+    with self.assertRaisesRegex(AttributeError,
+                                "Could not find code object with path"):
+      code_object_pickler._get_code_from_stable_reference(
+          "apache_beam.internal.test_cases.before_module_with_lambdas."
+          "my_function.__code__.co_consts[something]")
+
+  def test_get_code_from_stable_reference_invalid_lambda_with_args_path(self):
+    with self.assertRaisesRegex(AttributeError,
+                                "Could not find code object with path"):
+      code_object_pickler._get_code_from_stable_reference(
+          "apache_beam.internal.test_cases.before_module_with_lambdas."
+          "my_function.__code__.co_consts[<lambda>, ('x',)]")
+
+  def test_get_code_from_stable_reference_invalid_lambda_with_hash_path(self):
+    with self.assertRaisesRegex(AttributeError,
+                                "Could not find code object with path"):
+      code_object_pickler._get_code_from_stable_reference(
+          "apache_beam.internal.test_cases.before_module_with_lambdas."
+          "my_function.__code__.co_consts[<lambda>, ('',), 1234567890]")
+
+  def test_get_code_add_local_variable_in_class(self):

Review Comment:
   done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@beam.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to