Example #1
0
 def test_pick_first_unanswered(self):
     """
     pick_first_unanswered() accepts a number of prompts and when called 
     fires off the first prompt() it finds for which the session store does
     not have an entry yet.
     """
     
     pfu = pick_first_unanswered(
             prompt("What is your name?"),
             prompt("What is your age?"),
             prompt("What is your gender?"))
     
     session_store = {
         "What is your name?": "Simon",
         "What is your gender?": "Male"
     }
     
     pfu.next()
     [question_text, end_of_session] = pfu.send((MenuSystem(), session_store))
     
     self.assertEquals(question_text, "What is your age?")
     self.assertFalse(end_of_session)
     
     # advance coroutine
     pfu.next()
     validated_answer = pfu.send("29")
     self.assertEquals(session_store['What is your age?'], '29')
     
     # advance coroutine
     pfu.next()
     empty_response = pfu.send((MenuSystem(), session_store))
     # all prompts have been answered, it should yield False
     self.assertFalse(empty_response)
Example #2
0

ms = MenuSystem(
    prompt('Thnx 4 taking the Quiz! Answer 3 questions and see how much you know. '
            'Pick your language:', options=(
        'English',
        'Zulu',
        'Afrikaans',
        'Sotho',
    ), validator=pick_one),
    prompt(_('You will be asked to answer 3 questions regarding HIV. '
        'Answer them correctly and stand a chance to win airtime! Press 1 to continue.'
    )),
    pick_first_unanswered(
        prompt(_('Can traditional medicine cure HIV/AIDS?'), **yes_or_no),
        prompt(_('Is an HIV test at any government clinic free of charge?'), **yes_or_no),
        prompt(_('Is it possible to test HIV-negative for up to 3-months after becoming HIV-infected?'), **yes_or_no),
    ),
    # do(print_storage),    
    case(
            (check_question, prompt('Correct! Press 1 to continue.'))
    ),
    pick_first_unanswered(
        prompt(_('Can HIV be transmitted by sweat?'), **yes_or_no),
        prompt(_('Is there a herbal medication that can cure HIV/AIDS?'), **yes_or_no),
        prompt(_('Does a CD4-count reflect the strength of a person\'s immune system?'), **yes_or_no),
    ),
    pick_first_unanswered(
        prompt(_('Can HIV be transmitted through a mother\'s breast milk?'), **yes_or_no),
        prompt(_('Is it possible for an HIV positive woman to deliver an HIV negative baby?'), **yes_or_no)
    ),