code: def test_unlock(origpath=None, clonepath=None):
      origds = Dataset(origpath).create()
      (origds.pathobj / "test-annex.dat").write_text("some text")
      origds.save()
  
      ds = clone(origpath, clonepath)
      repo = ds.repo
      testfile = ds.pathobj / "test-annex.dat"
  
      managed_branch = repo.is_managed_branch()
      if not managed_branch:
          # file is currently locked:
          # TODO: use get_annexed_files instead of hardcoded filename
          assert_raises(IOError, open, testfile, "w")
  
      # Note: In V6+ we can unlock even if the file's content isn't present, but
      # doing so when unlock() is called with no paths isn't consistent with the
      # current behavior when an explicit path is given (it doesn't unlock) or
      # with the behavior in V5, so we don't do it.
  
      # Unlocking the dataset without an explicit path does not fail if there
      # are files without content.
      eq_(ds.unlock(path=None, on_failure="ignore"), [])
      eq_(ds.unlock(path=[], on_failure="ignore"), [])
      # cannot unlock without content (annex get wasn't called)
      assert_in_results(
          ds.unlock(path="test-annex.dat", on_failure="ignore"),
          path=str(testfile),
          status="impossible",
      )
  
      repo.get("test-annex.dat")
      result = ds.unlock()
      if not managed_branch:
          # with managed repos `unlock` is not talking
          assert_result_count(result, 1)
          assert_in_results(result, path=str(testfile), status="ok")
  
      testfile.write_text("change content")
  
      ds.save(
          "test-annex.dat",
          message="edit 'test-annex.dat' via unlock and lock it again",
      )
  
      if not managed_branch:
          # after commit, file is locked again:
          assert_raises(IOError, open, testfile, "w")
  
      # content was changed:
      eq_("change content", testfile.read_text())
  
      # unlock again, this time more specific:
      result = ds.unlock(path="test-annex.dat")
      if not managed_branch:
          # with managed repos `unlock` is not talking
          assert_result_count(result, 1)
          assert_in_results(result, path=str(testfile), status="ok")
  
      testfile.write_text("change content again")
  
      ds.save(
          "test-annex.dat",
          message="edit 'test-annex.dat' via unlock and lock it again",
      )
  
      # TODO:
      # BOOOM: test-annex.dat writeable in V6!
      # Why the hell is this different than the first time we wrote to the file
      # and locked it again?
      # Also: After opening the file is empty.
  
      if not managed_branch:
          # after commit, file is locked again:
          assert_raises(IOError, open, testfile, "w")
  
      # content was changed:
      eq_("change content again", testfile.read_text())
  
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 2 for calling a global function with example usage: test_unlock(origpath, clonepath) without return types