[Tutor] unit testing raw_input()

Andre Roberge andre.roberge at gmail.com
Wed Apr 19 00:34:48 CEST 2006


Hi all-

Suppose I had a function like the following:

def y_n(prompt="Answer yes or no"):
    while True:
        answer = raw_input(prompt)
        if answer in ['y', 'Y', 'yes']:
            print "You said yes!"
            break
        elif answer in ['n', 'N', 'no']:
            print "You said no!"
            break
        else:
            print "%s is an invalid answer."%answer

How could I go about to write an automated test for it?

André


More information about the Tutor mailing list