code: def testCanonicalName(self):
      self.assertEqual(
          "/job:foo/replica:0",
          device.canonical_name("/job:foo/replica:0"),
      )
      self.assertEqual(
          "/job:foo/replica:0",
          device.canonical_name("/replica:0/job:foo"),
      )
  
      self.assertEqual(
          "/job:foo/replica:0/task:0",
          device.canonical_name("/job:foo/replica:0/task:0"),
      )
      self.assertEqual(
          "/job:foo/replica:0/task:0",
          device.canonical_name("/job:foo/task:0/replica:0"),
      )
  
      self.assertEqual(
          "/device:CPU:0", device.canonical_name("/device:CPU:0")
      )
      self.assertEqual(
          "/device:GPU:2", device.canonical_name("/device:GPU:2")
      )
  
      self.assertEqual(
          "/job:foo/replica:0/task:0/device:GPU:0",
          device.canonical_name(
              "/job:foo/replica:0/task:0/device:GPU:0"
          ),
      )
      self.assertEqual(
          "/job:foo/replica:0/task:0/device:GPU:0",
          device.canonical_name(
              "/device:GPU:0/task:0/replica:0/job:foo"
          ),
      )
  
file_path: tensorflow/tensorflow/python/framework/device_test.py
imports: from absl.testing import parameterized
  from tensorflow.python.eager import context
  from tensorflow.python.framework import device
  from tensorflow.python.framework import device_spec
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import variables
  from tensorflow.python.platform import googletest
label_desc: Use image node_id 2 for calling the DeviceTest obj's underlying member method code with example usage: obj.testCanonicalName() without return types