code: def test_rename(tmpdir):
      tmpdir.chdir()
  
      # Test very simple rename
      _ = open("file.txt", "w").close()
      rn = utility.Rename(
          in_file="file.txt", format_string="test_file1.txt"
      )
      res = rn.run()
      outfile = tmpdir.join("test_file1.txt").strpath
      assert res.outputs.out_file == outfile
      assert os.path.exists(outfile)
  
      # Now a string-formatting version
      rn = utility.Rename(
          in_file="file.txt",
          format_string="%(field1)s_file%(field2)d",
          keep_ext=True,
      )
      # Test .input field creation
      assert hasattr(rn.inputs, "field1")
      assert hasattr(rn.inputs, "field2")
  
      # Set the inputs
      rn.inputs.field1 = "test"
      rn.inputs.field2 = 2
      res = rn.run()
      outfile = tmpdir.join("test_file2.txt").strpath
      assert res.outputs.out_file == outfile
      assert os.path.exists(outfile)
  
file_path: nipype/nipype/interfaces/utility/tests/test_base.py
imports: import os
  import pytest
  from nipype.interfaces import utility
  from nipype.interfaces.base import isdefined
  import nipype.pipeline.engine
label_desc: Use image node_id 1 for calling a global function with example usage: test_rename(tmpdir) without return types