55 lines
No EOL
1.5 KiB
Python
55 lines
No EOL
1.5 KiB
Python
import main
|
|
import pytest
|
|
from os.path import exists
|
|
|
|
def test_likelyQuestion():
|
|
likelyQuestion = main.mostLikely("birthday")
|
|
assert likelyQuestion['question'] == 'What is your birthday?'
|
|
|
|
def test_likelyAnswer():
|
|
likelyAnswer = main.mostLikely("weather today")
|
|
assert likelyAnswer['answer'] == 'Same as yesterday.'
|
|
|
|
def test_detection_of_no_user_input():
|
|
userQuestion = ''
|
|
assert not main.continueQuestions(userQuestion)
|
|
|
|
def testDetectionOfUserInput():
|
|
userQuestion = 'weather'
|
|
assert main.continueQuestions(userQuestion)
|
|
|
|
def testFaqJsonFileExists():
|
|
fileName = exists('./faq.json')
|
|
assert fileName
|
|
|
|
# Check whether log file gets made after a successful run
|
|
|
|
def testLogfileExists():
|
|
logName = exists('./asked_questions_log.txt')
|
|
assert logName
|
|
|
|
def readFileLines(fileName):
|
|
file = open(fileName, "r")
|
|
# Create a count of non-empty lines
|
|
nonemptyLines = [line.strip("\n") for line in file if line != "\n"]
|
|
lineCount = len(nonemptyLines)
|
|
file.close()
|
|
return lineCount
|
|
|
|
def testLogfileLinecountIncreases():
|
|
oldLineCount = readFileLines("./asked_questions_log.txt")
|
|
|
|
userQuestion = 'weather'
|
|
main.continueQuestions(userQuestion)
|
|
|
|
newLineCount = readFileLines("./asked_questions_log.txt")
|
|
|
|
assert newLineCount == oldLineCount + 1
|
|
|
|
def testDetectionIfUserEntersSymbolsOnly():
|
|
userQuestion = '#$%^&*'
|
|
assert not main.continueQuestions(userQuestion)
|
|
|
|
def testDetectionIfUserEntersSpaceOnly():
|
|
userQuestion = ' '
|
|
assert not main.continueQuestions(userQuestion) |