code: def test_to_from_string(self, device_spec_type):
      d = device_spec_type.from_string("/job:foo/replica:0")
      self.assertEqual("/job:foo/replica:0", d.to_string())
      self.assertEqual(0, d.replica)
  
      d = device_spec_type.from_string("/replica:1/task:0/cpu:0")
      self.assertEqual("/replica:1/task:0/device:CPU:0", d.to_string())
      self.assertAllEqual(
          [1, 0, "CPU", 0],
          [d.replica, d.task, d.device_type, d.device_index],
      )
  
      d = device_spec_type.from_string("/replica:1/task:0/device:CPU:0")
      self.assertEqual("/replica:1/task:0/device:CPU:0", d.to_string())
      self.assertAllEqual(
          [1, 0, "CPU", 0],
          [d.replica, d.task, d.device_type, d.device_index],
      )
  
      d = device_spec_type.from_string("/job:muu/device:GPU:2")
      self.assertEqual("/job:muu/device:GPU:2", d.to_string())
      self.assertAllEqual(
          ["muu", "GPU", 2], [d.job, d.device_type, d.device_index]
      )
  
      with self.assertRaisesRegex(
          ValueError, "Multiple device types are not allowed"
      ):
          d.parse_from_string("/job:muu/device:GPU:2/cpu:0")
  
file_path: tensorflow-upstream/tensorflow/python/framework/device_spec_test.py
imports: from absl.testing import parameterized
  from tensorflow.python.framework import device_spec
  from tensorflow.python.framework import test_util
  from tensorflow.python.platform import googletest
label_desc: Use image node_id 7 for calling the DeviceSpecTest obj's underlying member method code with example usage: obj.test_to_from_string(device_spec_type) without return types