code: def testPrepareContexts(self):
      node_contexts = pipeline_pb2.NodeContexts()
      self.load_proto_from_text(
          os.path.join(self._testdata_dir, "node_context_spec.pbtxt"),
          node_contexts,
      )
      with metadata.Metadata(
          connection_config=self._connection_config
      ) as m:
          context_lib.prepare_contexts(
              metadata_handle=m, node_contexts=node_contexts
          )
          # Duplicated call should succeed.
          contexts = context_lib.prepare_contexts(
              metadata_handle=m, node_contexts=node_contexts
          )
  
          got_context_type_one = m.store.get_context_type(
              "my_context_type_one"
          )
          got_context_type_one.ClearField("id")
          self.assertProtoEquals(
              """
            name: 'my_context_type_one'
            """,
              got_context_type_one,
          )
          got_context_type_two = m.store.get_context_type(
              "my_context_type_two"
          )
          got_context_type_two.ClearField("id")
  
          self.assertProtoEquals(
              """
            name: 'my_context_type_two'
            """,
              got_context_type_two,
          )
          self.assertEqual(
              contexts[0],
              m.store.get_context_by_type_and_name(
                  "my_context_type_one", "my_context_one"
              ),
          )
          self.assertEqual(
              contexts[1],
              m.store.get_context_by_type_and_name(
                  "my_context_type_one", "my_context_two"
              ),
          )
          self.assertEqual(
              contexts[2],
              m.store.get_context_by_type_and_name(
                  "my_context_type_two", "my_context_three"
              ),
          )
          self.assertEqual(
              contexts[0].custom_properties["property_a"].int_value, 1
          )
          self.assertEqual(
              contexts[1].custom_properties["property_a"].int_value, 2
          )
          self.assertEqual(
              contexts[2].custom_properties["property_a"].int_value, 3
          )
          self.assertEqual(
              contexts[2].custom_properties["property_b"].string_value,
              "4",
          )
  
file_path: tfx/tfx/orchestration/portable/mlmd/context_lib_test.py
imports: import os
  import tensorflow
  from tfx.orchestration import metadata
  from tfx.orchestration.portable.mlmd import context_lib
  from tfx.proto.orchestration import pipeline_pb2
  from tfx.utils import test_case_utils
  from ml_metadata.proto import metadata_store_pb2
label_desc: Use image node_id 2 for calling the ContextLibTest obj's underlying member method code with example usage: obj.testPrepareContexts() without return types