code: def test_unlock_directory(path=None):
      ds = Dataset(path).create(force=True)
      ds.save()
      ds.unlock(path="dir")
      dirpath = Path("dir")
      dirpath_abs = Path(ds.pathobj / "dir")
  
      # On adjusted branches (for the purposes of this test, crippled
      # filesystems), the files were already unlocked and the committed state is
      # the unlocked pointer file.
      is_managed_branch = ds.repo.is_managed_branch()
      if is_managed_branch:
          assert_repo_status(ds.path)
      else:
          assert_repo_status(
              ds.path, modified=[dirpath / "a", dirpath / "b"]
          )
      ds.save()
      ds.drop(str(dirpath / "a"), reckless="kill")
      assert_false(ds.repo.file_has_content(str(dirpath / "a")))
  
      # Unlocking without an explicit non-directory path doesn't fail if one of
      # the directory's files doesn't have content.
      res = ds.unlock(path="dir")
      assert_not_in_results(
          res, action="unlock", path=str(dirpath_abs / "a")
      )
      if is_managed_branch:
          assert_not_in_results(
              res, action="unlock", path=str(dirpath_abs / "b")
          )
      else:
          assert_in_results(
              res,
              action="unlock",
              status="ok",
              path=str(dirpath_abs / "b"),
          )
          assert_repo_status(ds.path, modified=[dirpath / "b"])
  
      # If we explicitly provide a path that lacks content, we get a result
      # for it.
      assert_in_results(
          ds.unlock(path=dirpath / "a", on_failure="ignore"),
          action="unlock",
          status="impossible",
          path=str(dirpath_abs / "a"),
      )
  
file_path: datalad/datalad/local/tests/test_unlock.py
imports: from datalad.api import clone, create, unlock
  from datalad.distribution.dataset import Dataset
  from datalad.support.annexrepo import AnnexRepo
  from datalad.support.exceptions import InsufficientArgumentsError, NoDatasetFound
  from datalad.tests.utils_pytest import assert_cwd_unchanged, assert_false, assert_in_results, assert_not_in_results, assert_raises, assert_repo_status, assert_result_count, chpwd, eq_, getpwd, skip_if_root, slow, with_tempfile, with_tree
  from datalad.utils import Path
label_desc: Use image node_id 3 for calling a global function with example usage: test_unlock_directory(path) without return types