def test_prompt_validate(self, stdin): """ Prompt user until return value passes validation check """ invals = ['foo', 'bar'] stdin.side_effect = lambda x: invals.pop(0) ret = scripts.prompt('', validate=lambda x: x == 'bar') self.assertEqual(ret, 'bar')
def test_prompt_default(self, stdin): """ If user hits 'enter', return default value """ stdin.return_value = '' ret = scripts.prompt('', default='abc') self.assertEqual(ret, 'abc')
def test_prompt_no_default(self, stdin): """ If no default, require a value """ invals = ['', 'foo'] stdin.side_effect = lambda x: invals.pop(0) ret = scripts.prompt('') self.assertEqual(ret, 'foo')
def test_prompt_validate(self, stdin): """ Prompt user until return value passes validation check """ invals = ["foo", "bar"] stdin.side_effect = lambda x: invals.pop(0) ret = scripts.prompt("", validate=lambda x: x == "bar") self.assertEqual(ret, "bar")
def test_prompt_default(self, _): """ If user hits 'enter', return default value """ ret = scripts.prompt("", default="abc") self.assertEqual(ret, "abc")