code: def test_obtain(path=None):
      ds = create(path)
      cfg = ConfigManager(ds)
      dummy = "datalad.test.dummy"
      # we know nothing and we don't know how to ask
      assert_raises(RuntimeError, cfg.obtain, dummy)
      # can report known ones
      cfg.add(dummy, "5.3")
      assert_equal(cfg.obtain(dummy), "5.3")
      # better type
      assert_equal(cfg.obtain(dummy, valtype=float), 5.3)
      # don't hide type issues, float doesn't become an int magically
      assert_raises(ValueError, cfg.obtain, dummy, valtype=int)
      # inject some prior knowledge
      from datalad.interface.common_cfg import definitions as cfg_defs
  
      cfg_defs[dummy] = dict(type=float)
      # no we don't need to specify a type anymore
      assert_equal(cfg.obtain(dummy), 5.3)
      # but if we remove the value from the config, all magic is gone
      cfg.unset(dummy)
      # we know nothing and we don't know how to ask
      assert_raises(RuntimeError, cfg.obtain, dummy)
  
      #
      # test actual interaction
      #
      @with_testsui()
      def ask():
          # fail on unknown dialog type
          assert_raises(
              ValueError,
              cfg.obtain,
              dummy,
              dialog_type="Rorschach_test",
          )
  
      ask()
  
      # ask nicely, and get a value of proper type using the preconfiguration
      @with_testsui(responses="5.3")
      def ask():
          assert_equal(
              cfg.obtain(dummy, dialog_type="question", text="Tell me"),
              5.3,
          )
  
      ask()
  
      # preconfigure even more, to get the most compact call
      cfg_defs[dummy]["ui"] = (
          "question",
          dict(text="tell me", title="Gretchen Frage"),
      )
  
      @with_testsui(responses="5.3")
      def ask():
          assert_equal(cfg.obtain(dummy), 5.3)
  
      ask()
  
      @with_testsui(responses="murks")
      def ask():
          assert_raises(ValueError, cfg.obtain, dummy)
  
      ask()
  
      # fail to store when destination is not specified, will not even ask
      @with_testsui()
      def ask():
          assert_raises(ValueError, cfg.obtain, dummy, store=True)
  
      ask()
  
      # but we can preconfigure it
      cfg_defs[dummy]["destination"] = "broken"
  
      @with_testsui(responses="5.3")
      def ask():
          assert_raises(ValueError, cfg.obtain, dummy, store=True)
  
      ask()
  
      # fixup destination
      cfg_defs[dummy]["destination"] = "branch"
  
      @with_testsui(responses="5.3")
      def ask():
          assert_equal(cfg.obtain(dummy, store=True), 5.3)
  
      ask()
  
      # now it won't have to ask again
      @with_testsui()
      def ask():
          assert_equal(cfg.obtain(dummy), 5.3)
  
      ask()
  
      # wipe it out again
      cfg.unset(dummy)
      assert_not_in(dummy, cfg)
  
imports: import logging
  import os
  from os.path import exists
  from os.path import join
  from unittest.mock import patch
  import pytest
  from datalad import cfg
  from datalad.api import create
  from datalad.cmd import CommandError
  from datalad.config import ConfigManager, _where_to_scope, parse_gitconfig_dump, rewrite_url, write_config_section
  from datalad.distribution.dataset import Dataset
  from datalad.support.annexrepo import AnnexRepo
  from datalad.support.gitrepo import GitRepo
  from datalad.tests.utils_pytest import DEFAULT_BRANCH, DEFAULT_REMOTE, assert_equal, assert_false, assert_in, assert_not_equal, assert_not_in, assert_raises, assert_true, chpwd, ok_file_has_content, with_tempfile, with_testsui, with_tree
  from datalad.utils import Path, get_home_envvars, swallow_logs
label_desc: Use image node_id 5 for calling a global function with example usage: test_obtain(path) without return types