code: def testNameCollision(self):
      # Make sure we have a clean directory to work in.
      with self.tempDir() as tempdir:
          # Jump to that directory until this test is done.
          with self.tempWorkingDir(tempdir):
              # Save training snapshots to a relative path.
              traindir = "train"
              os.mkdir(traindir)
              # Collides with the default name of the checkpoint state file.
              filepath = os.path.join(traindir, "checkpoint")
  
              with self.cached_session() as sess:
                  unused_a = variables.Variable(
                      0.0
                  )  # So that Saver saves something.
                  self.evaluate(
                      variables.global_variables_initializer()
                  )
  
                  # Should fail.
                  saver = saver_module.Saver(sharded=False)
                  with self.assertRaisesRegex(
                      ValueError, "collides with"
                  ):
                      saver.save(sess, filepath)
  
                  # Succeeds: the file will be named "checkpoint-<step>".
                  saver.save(sess, filepath, global_step=1)
                  self.assertIsNotNone(
                      checkpoint_management.latest_checkpoint(traindir)
                  )
  
                  # Succeeds: the file will be named "checkpoint-<i>-of-<n>".
                  saver = saver_module.Saver(sharded=True)
                  saver.save(sess, filepath)
                  self.assertIsNotNone(
                      checkpoint_management.latest_checkpoint(traindir)
                  )
  
                  # Succeeds: the file will be named "checkpoint-<step>-<i>-of-<n>".
                  saver = saver_module.Saver(sharded=True)
                  saver.save(sess, filepath, global_step=1)
                  self.assertIsNotNone(
                      checkpoint_management.latest_checkpoint(traindir)
                  )
  
imports: import contextlib
  import os
  import pathlib
  import shutil
  import tempfile
  from google.protobuf import text_format
  from tensorflow.core.protobuf import saver_pb2
  from tensorflow.python.checkpoint import checkpoint
  from tensorflow.python.checkpoint import checkpoint_management
  from tensorflow.python.eager import context
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.lib.io import file_io
  from tensorflow.python.ops import variables
  from tensorflow.python.platform import gfile
  from tensorflow.python.platform import test
  from tensorflow.python.platform import tf_logging
  from tensorflow.python.training import saver
  from tensorflow.python.training.checkpoint_state_pb2 import CheckpointState
label_desc: Use image node_id 3 for calling the LatestCheckpointWithRelativePaths obj's underlying member method code with example usage: obj.testNameCollision() without return types