code: def test_ssh_open_close(tmp_path=None, tfile1=None):
      manager = SSHManager()
  
      socket_path = None
      if _ssh_manager_is_multiplex:
          socket_path = opj(
              str(manager.socket_dir),
              get_connection_hash("datalad-test"),
          )
          # TODO: facilitate the test when it didn't exist
          existed_before = exists(socket_path)
  
      c1 = manager.get_connection("ssh://datalad-test")
      c1.open()
      if socket_path:
          # control master exists for sure now
          ok_(exists(socket_path))
  
      # use connection to execute remote command:
      # we list explicitly local HOME since we override it in module_setup
      #
      # Note: Use realpath() below because we know that the resolved temporary
      # test directory exists on the target (many tests rely on that), but it
      # doesn't necessarily have the unresolved variant.
      out, err = c1("ls -a {}".format(sh_quote(op.realpath(tmp_path))))
      remote_ls = [
          entry
          for entry in out.splitlines()
          if entry != "." and entry != ".."
      ]
      eq_(set(remote_ls), {"f0", "f1"})
      if socket_path:
          ok_(exists(socket_path))
  
      # now test for arguments containing spaces and other pleasant symbols
      out, err = c1("ls -l {}".format(sh_quote(tfile1)))
      assert_in(tfile1, out)
      # on a crippled FS it will actually say something like
      # Control socket connect(...6258b3a7): Connection refused\r\n'
      # but still work.
      # eq_(err, '')
  
      c1.close()
      if socket_path:
          # control master doesn't exist anymore:
          ok_(exists(socket_path) == existed_before)
  
file_path: datalad/datalad/support/tests/test_sshconnector.py
imports: import logging
  import os.path
  from os.path import exists, getmtime, isdir
  from os.path import join
  from datalad.tests.utils_pytest import SkipTest, assert_false, assert_in, assert_is_instance, assert_raises, eq_, get_most_obscure_supported_name, get_ssh_port, ok_, patch_config, skip_if_on_windows, skip_nomultiplex_ssh, skip_ssh, swallow_logs, with_tempfile, with_tree
  from datalad.utils import Path
  from ..sshconnector import MultiplexSSHConnection, MultiplexSSHManager, NoMultiplexSSHConnection, SSHConnection, SSHManager, get_connection_hash, sh_quote
label_desc: Use image node_id 2 for calling a global function with example usage: test_ssh_open_close(tmp_path, tfile1) without return types