Exemplo n.º 1
0
    def test_prompt_masked(self):
        self.explain('''
This test checks to see whether we can prompt for a password without displaying
what you type.
''')
        answer = prompt('Type an imaginary password:'******'Were your keystrokes masked out?'))
Exemplo n.º 2
0
def fancy_prompt(q,
                 regex,
                 answers,
                 dflt=None,
                 normfunc=None,
                 acceptfunc=None,
                 comment=None,
                 question=None):
    key = q.strip().lower()
    if not normfunc:
        normfunc = _strip_and_lower_case
    if (not acceptfunc) and regex:
        acceptfunc = lambda val: re.match(regex, val)
    if comment:
        writec(YELLOW + comment)
        print('')

    answer = prompt(q,
                    regex,
                    default=answers.get(key, dflt),
                    normfunc=normfunc,
                    acceptfunc=acceptfunc,
                    question=question)
    printc(NORMTXT)
    answers[key] = answer
    return answer
Exemplo n.º 3
0
    def test_prompt_enter_require_answer(self):
        self.explain('''
This test checks to see whether we can force the user to give an answer. THE
FIRST TIME you are prompted, PRESS ENTER. The second time, give a real answer.
''')
        self.stuff('\nFred\ny\n')
        answer = prompt('What is your name?', default=None)
        self.assertTrue(prompt_bool('Were you re-prompted?'))
        self.assertStdout(_text_repeats, 'your name')
Exemplo n.º 4
0
    def test_prompt(self):
        self.explain('''
Answer the following question with at least a few chars. If the prompt()
function is working, we should see a non-empty answer.
''')
        self.stuff('to seek the holy grail\n')
        answer = prompt('What is your quest?')
        self.assertTrue(answer)
        # Answer should never include trailing \n
        self.assertEquals(answer.rstrip(), answer)
Exemplo n.º 5
0
def fancy_prompt(q, regex,  answers, dflt=None, normfunc=None, acceptfunc=None, comment=None,question = None):
    key = q.strip().lower()
    if not normfunc:
        normfunc = _strip_and_lower_case
    if (not acceptfunc) and regex:
        acceptfunc = lambda val: re.match(regex, val)
    if comment:
        writec(YELLOW + comment)
        print('')
   
    answer = prompt(q, regex, default=answers.get(key, dflt),
                    normfunc=normfunc, acceptfunc=acceptfunc,question = question)
    printc(NORMTXT)
    answers[key] = answer
    return answer
Exemplo n.º 6
0
 def test_prompt_enter_again(self):
     self.stuff('\n')
     answer = prompt('\nPress Enter again:')
     self.assertEqual('', answer)
Exemplo n.º 7
0
 def test_prompt_enter(self):
     self.stuff('\n')
     answer = prompt('\nPress Enter:', default="blue")
     self.assertEqual('blue', answer)
     self.assertStdout(_text_has, '( =blue)')