def test_problem_questions(): resetphysical() message = "my breathing problem ..." msg = Message(USERID, message) reply = bot.reply(msg) print "User message:'{}'".format(message) print "Bot reply:'{}'".format(reply) # perform: messages = ["It affects ...", "There's also ...", "Ok", "this test message should fail the test"] for message in messages[:3]: msg = Message(USERID, message) reply = bot.reply(msg) print "User message:'{}'".format(message) print "Bot reply:'{}'".format(reply) print "counter variable value:{}".format(bot._interpreter._rivescriptInterpreter.get_uservar(USERID, "counter")) # test: assert "severe" in reply or "often" in reply or "affecting" in reply msg = Message(USERID, messages[3]) reply = bot.reply(msg) print "User message:'{}'".format(message) print "Bot reply:'{}'".format(reply) assert "I believe we have covered all the concerns" in reply
def test_responsibility_no(): resetpractical() # enter responsibilities discussion: msg = "discuss responsibility" bot.reply(Message(USERID, msg)) # enter responsibilities discussion: msg = "look after" bot.reply(Message(USERID, msg)) msg = "no" reply = bot.reply(Message(USERID, msg)) assert "Ok ..." in reply
def test_responsibility_yes(): resetpractical() # enter responsibilities discussion: msg = "discuss responsibility" bot.reply(Message(USERID, msg)) # enter responsibilities discussion: msg = "look after" bot.reply(Message(USERID, msg)) msg = "something something yes" reply = bot.reply(Message(USERID, msg)) assert "Adding topic or checking if already exists ..." in reply
def test_expressing(): resetToEmotional() # perform: messages = [ "I find difficulties voicing my state", "I never want to show how I feel", "conveying my emotions has always been difficult" ] for msg in messages[:]: reply = bot.reply(Message(USERID, msg)) # test: found = False good_replies = [ "Do you feel you have problems expressing yourself in general or in particular situatons/with particular people?" ] for good_reply in good_replies: if good_reply in reply: found = True break assert found, reply
def test_regret(): resetspiritual() # perform: messages = [ "I have lived a life of immorality", "I have have been evil and regret it", "I worry for my conscience", "I wish I could go back and ...", "I wish to make formal apologies", "I believe I have been immoral" ] for msg in messages[:]: reply = bot.reply(Message(USERID, msg)) # test: found = False good_replies = [ "Do you believe there is any way for you to make up for your mistakes?" ] for good_reply in good_replies: if good_reply in reply: found = True break assert found, reply
def test_issue_identified(): resetfamily() # perform: messages = [ "discuss friend", "I think my mate ...", "aunt", "I like my aunt but I don't like my uncle", "my nephew hates me but my dad doesn't", "my wife does not talk to me anymore" ] replies = [] for msg in messages[:]: nextreply = bot.reply(Message(USERID, msg)) replies.append(nextreply) # reset to family topic senddummymessage() resetfamily() # test: assert "them" in replies[0] assert "them" in replies[1] assert "them" in replies[2] # Wrong answer: sets uservar "aunt" when it should be "uncle" assert "them" in replies[3] # Wrong answer: sets uservar "dad" when it should be nephew assert "them" in replies[4] assert "partner" in replies[5]
def test_reply_nopreprocess(): message = Message("localuser", "set global") expectedsubstring = "ERR" actual = bot.reply(message) assert expectedsubstring in actual
def test_setglobal(): # enter global topic: msg = Message(USERID, "set global") actual = bot.reply(msg) expected = "Topic set to global" assert expected == actual
def test_responsibility(): resetpractical() # perform: messages = ["I need to look after my children", "I care for my mother", "I have an obligation towards my partner's finances", "bla"] for msg in messages: # enter responsibilities discussion: reply = bot.reply(Message(USERID, "discuss responsibility")) assert "Tell me more about your responsibilities." == reply reply = bot.reply(Message(USERID, msg)) # test: assert "Do you believe this is relevant to your relationship with family or friends?" in reply
def test_depression(): resetToEmotional() # perform: messages = [ "I never felt down for this long before", "it's like I'm permanently unhappy", "I believe I am depressed", "Absolutely hopeless", "No hope to continue living", "I have always been brave but I never faced a situation so discouraging", "unachievable" ] for msg in messages[:]: reply = bot.reply(Message(USERID, msg)) # test: found = False good_replies = [ "Do you feel there is something other than your condition causing you to feel this way?" ] for good_reply in good_replies: if good_reply in reply: found = True break assert found, reply
def movedIntoPhysical(): # mentioning expected issue (or any physical issue) message = "something breathing something" msg = Message(USERID, message) reply = bot.reply(msg) return "Does the problem present itself in particular conditions?" == reply
def test_description(): # perform: messages = [ "she doesn't like me anymore", "he has been very mean", "we used to be best friends but now ..." ] for msg in messages[:]: senddummymessage() resetfamily() # problem with cousin m = "cousin" bot.reply(Message(USERID, m)) reply = bot.reply(Message(USERID, msg)) # test: assert "you would like to tell me" in reply
def test_reply(): bot = BotRivescript() bot._interpreter = mock_interpreter.getMock() expected = "Hello" actual = bot.reply(Message("id", "message")) assert expected == actual
def test_enter_emotional(): setglobal() messages = ["discuss emotional"] for msg in messages: reply = bot.reply(Message(USERID, msg)) # test: assert "talk about emotional" in reply
def test_yes(): # perform: messages = ["yes", "yea", "yeah"] for msg in messages[:]: senddummymessage() resetfamily() # problem with cousin m = "cousin" reply = bot.reply(Message(USERID, m)) m = "they are mean" reply = bot.reply(Message(USERID, m)) # "would you like to tell me anything else about this?" reply = bot.reply(Message(USERID, msg)) # test: assert "what is it" in reply.lower()
def test_reply_withpreprocess(): message = Message("localuser", "set global") bot = BotRivescript(preprocessor=preprocess.preprocessor_builder.build(), interpreter=RiveScriptProxy()) expected = "Topic set to global" actual = bot.reply(message) assert expected == actual
def test_enter_practical(): setglobal() # perform: messages = ["discuss practical"] for msg in messages: reply = bot.reply(Message(USERID, msg)) # test: assert "talk about practical" in reply
def test_intro_reply(): resetphysical() message = "my breathing problem ..." msg = Message(USERID, message) reply = bot.reply(msg) print "User message:'{}'".format(message) print "Bot reply:'{}'".format(reply) assert "Does the problem present itself in particular conditions?" == reply
def test_make_query_no(): setglobal() initializeConcerns() bot.createUserSession(USERID) skipTopicDiscussion() # perform: message = "anything" msg = Message(USERID, message) reply = bot.reply(msg) assert mostDistressful == getCurrentMicroTopic() assert "Before we move on" in reply message = "no" msg = Message(USERID, message) reply = bot.reply(msg) assert "next topic" in reply
def test_enter_family_topic(): setglobal() # perform: messages = [ "discuss family", "discuss my family" "I wish to change the topic please and talk about family", "desire to discuss the family", "I want to talk about family issues" ] for msg in messages: reply = bot.reply(Message(USERID, msg)) # test: assert "talk about family" in reply
def test_yes_and(): # perform: messages = [ "the problem is also that ...", "yes there is something else", "yea there is this: ...", ] for msg in messages[:]: senddummymessage() resetfamily() # problem with cousin m = "cousin" reply = bot.reply(Message(USERID, m)) print reply # problem with cousin m = "they are mean" reply = bot.reply(Message(USERID, m)) print reply # "would you like to tell me anything else about this?" reply = bot.reply(Message(USERID, msg)) # test: assert "I believe we have covered all the concerns" in reply
def test_change_topic(): setglobal() # perform: messages = [ "desire discuss other", "desire to change topic", "I want to change the topic", "I wish to change the topic please", "I want to talk about something else" ] for msg in messages[:]: reply = bot.reply(Message(USERID, msg)) # test: assert "would you like to" in reply, msg
def test_not_change_topic(): setglobal() # perform: messages = [ "do not desire to change topic", "I no want to change the topic", "I will nay wish to change the topic please" ] for msg in messages: reply = bot.reply(Message(USERID, msg)) # test: assert "the topic then" in reply, msg
def test_moveToNextTopic(): resetphysical() initializeConcerns() skipTopicDiscussion() # perform: message = "bla bla bla" msg = Message(USERID, message) reply = bot.reply(msg) #test assert mostDistressful in reply assert macrotopicForMostDistressful in reply assert movedIntoPhysical()
def test_change_topic_and(): setglobal() # perform: messages = [ "do desire to change topic and discuss physical", "I want to change the topic and talk emotional problems", "I really want change the topic please and speak about family" ] for msg in messages: reply = bot.reply(Message(USERID, msg)) # test: assert "'s talk about" in reply, msg setglobal()
def test_discuss(): setglobal() # perform: messages = [ "discuss physical", "want talk emotional", "wish discuss spiritual", "I wish to discuss my spiritual", "I wish to discuss my spiritual concerns please" ] for msg in messages: reply = bot.reply(Message(USERID, msg)) # test: assert "talk about" in reply, msg setglobal() #set back to global for next message
def test_enter_relativefriend(): resetfamily() # perform: messages = [ "discuss friend", "I think my mate ...", "aunt", "I like my aunt but I don't like my uncle", "my nephew hates me but my dad doesn't" "discuss relativefriend", ] for msg in messages[:]: reply = bot.reply(Message(USERID, msg)) # test: assert "What is it" in reply senddummymessage() resetfamily()
def test_travel(): resetpractical() # perform: messages = ["I want to travel abroad but I am worried about insurance", "I need to travel to visit my family"] for msg in messages[:]: reply = bot.reply(Message(USERID, msg)) # test: found = False good_replies = ["Is travelling important for you at this time?"] for good_reply in good_replies: if good_reply == reply: found = True break assert found, reply
def test_transport(): resetpractical() # perform: messages = ["commuting is becoming impossible", "I cannot cycle anymore"] for msg in messages[:]: reply = bot.reply(Message(USERID, msg)) # test: found = False good_replies = ["Is the transportation issue affecting other areas of your life, such as your work or other duties?"] for good_reply in good_replies: if good_reply == reply: found = True break assert found, reply
def test_communication(): resetpractical() # perform: messages = ["I find it difficult to talk on the phone to set up an appointment", ] for msg in messages[:]: reply = bot.reply(Message(USERID, msg)) # test: found = False good_replies = ["How would you prefer to communicate with the NHS?"] for good_reply in good_replies: if good_reply == reply: found = True break assert found, reply