code: def test_question_choices():
      # TODO: come up with a reusable fixture for testing here
  
      choices = {
          "a": "[a], b, cc",
          "b": "a, [b], cc",
          "cc": "a, b, [cc]",
      }
  
      for hidden in (True, False):
          for default_value in ["a", "b"]:
              choices_str = choices[default_value]
              for entered_value, expected_value in [
                  (default_value, default_value),
                  ("", default_value),
                  ("cc", "cc"),
              ]:
                  with patch_getpass(
                      return_value=entered_value
                  ) as gpcm:
                      out = StringIO()
                      response = DialogUI(out=out).question(
                          "prompt",
                          choices=sorted(choices),
                          default=default_value,
                          hidden=hidden,
                      )
                      # .assert_called_once() is not available on older mock's
                      # e.g. on  1.3.0 on nd16.04
                      eq_(
                          gpcm.call_count, 1
                      )  # should have asked only once
                      eq_(response, expected_value)
                      # getpass doesn't use out -- goes straight to the terminal
                      eq_(out.getvalue(), "")
                      # TODO: may be test that the prompt was passed as a part of the getpass arg
                      # eq_(out.getvalue(), 'prompt (choices: %s): ' % choices_str)
  
      # check some expected exceptions to be thrown
      out = StringIO()
      ui = DialogUI(out=out)
      assert_raises(
          ValueError, ui.question, "prompt", choices=["a"], default="b"
      )
      eq_(out.getvalue(), "")
  
      with patch_getpass(return_value="incorrect"):
          assert_raises(
              RuntimeError, ui.question, "prompt", choices=["a", "b"]
          )
      assert_re_in(
          ".*ERROR: .incorrect. is not among choices.*", out.getvalue()
      )
  
file_path: datalad/datalad/ui/tests/test_dialog.py
imports: import builtins
  from io import StringIO
  from unittest.mock import call, patch
  import pytest
  from datalad.ui.progressbars import progressbars
  from datalad.utils import swallow_logs
  from ...tests.utils_pytest import assert_in, assert_not_in, assert_raises, assert_re_in, eq_, ok_endswith, ok_startswith
  from ..dialog import ConsoleLog, DialogUI, IPythonUI
label_desc: Use image node_id 4 for calling a global function with example usage: test_question_choices() without return types