def test_chabot_print_prediction_from_user_input_ctrl_c(self): # arrange exp = EMERGENCY_MSG msg = u"\u0003" # ctrl c cb = ChatBotInit() actual = cb.get_conversation(msg) self.assertTrue(actual in exp)
def test_chabot_print_prediction_from_user_input_keystroke(self): # arrange exp = EMERGENCY_MSG msg = u"\u2191" # arrow down cb = ChatBotInit() actual = cb.get_conversation(msg) self.assertTrue(actual in exp)
def test_chabot_print_prediction_from_user_input_ctrl_c(self): # arrange msg = u"\u0003" # ctrl c cb = ChatBotInit() original_input = mock.builtins.input mock.builtins.input = lambda _: msg with mock.patch("sys.stdout", new=io.StringIO()) as fake_stdout: cb.init_chat_cmd(run_once=True) actual = fake_stdout.getvalue() self.assertTrue(actual) mock.builtins.input = original_input
def test_chabot_predict_from_user_input(self): # reference: https://forum.learncodethehardway.com/t/testing-input-and-print/1757/10 # arrange cb = ChatBotInit() msg = "exit" exp = None original_input = mock.builtins.input mock.builtins.input = lambda _: msg # act actual = cb.init_chat_cmd() # assert self.assertEqual(actual, exp) mock.builtins.input = original_input
def test_chabot_print_prediction_from_user_input(self): # reference: https://forum.learncodethehardway.com/t/testing-input-and-print/1757/10 # arrange cb = ChatBotInit() msg = "exit" exp = "Bye!" original_input = mock.builtins.input mock.builtins.input = lambda _: msg with mock.patch("sys.stdout", new=io.StringIO()) as fake_stdout: cb.init_chat_cmd() actual = fake_stdout.getvalue() self.assertIn(exp, actual) mock.builtins.input = original_input
#!flask/bin/python import os, sys from settings import ROOT_DIR, BOT_PREFIX sys.path.append(ROOT_DIR + '/backend/') sys.path.append(ROOT_DIR + '/frontend/') from flask import Flask, render_template, request, redirect, Response import random, json from backend.chatbot import ChatBotInit app = Flask(__name__) cb = ChatBotInit() @app.route('/') def output(): # serve index template return render_template('index.html') @app.route('/receiver', methods=['POST']) def worker(): message = request.json['message'] return BOT_PREFIX + cb.get_conversation(message) if __name__ == '__main__': # run! port = int(os.environ.get('PORT', 5000))
#!/usr/bin/python import os, sys from settings import ROOT_DIR sys.path.append(ROOT_DIR + '/backend/') sys.path.append(ROOT_DIR + '/frontend/') from backend.chatbot import ChatBotInit if __name__ == "__main__": cb = ChatBotInit() cb.init_chat_cmd()
def test_chatbot_can_be_instantiated(self): cb = ChatBotInit() self.assertTrue(cb)