def test_ask_not_string(self):
     """
     Test ask function not string
     :return: assertion: exception: not string
     """
     inquiry = Interface()
     self.assertRaises(Exception, lambda: inquiry.ask(12))
示例#2
0
 def test_provide_answer_corrected_fptr(self):
     obj = Interface()
     obj.ask('What shape is 2 5 2 5?')
     obj.teach(get_triangle_type)
     obj.correct(get_quadrilateral_type)
     result = obj.ask('What shape is 2 5 2 5?')
     self.assertEqual(result, 'rectangle')
 def test_story_color_list(self):
     obj = Interface()
     result = obj.ask("What are color conversions?")
     self.assertEqual(
         result,
         'yellow, red, and blue are the primary colors available for mixing'
     )
示例#4
0
 def test_provide_answer_corrected(self):
     obj = Interface()
     obj.ask('What color is the sky?')
     obj.teach('The sky is blue')
     obj.correct('The sky is a multitude of colors typically ranging from turquoise to indigo')
     result = obj.ask('What color is the sky?')
     self.assertEqual(result, 'The sky is a multitude of colors typically ranging from turquoise to indigo')
示例#5
0
 def test_provide_answer_corrected_strings(self):
     obj = Interface()
     obj.ask('Why did ancient egyptians build the pyramids?')
     obj.teach('To honor their royalty in tombs')
     obj.correct('Aliens')
     result = obj.ask('Why did ancient egyptians build the pyramids?')
     self.assertEqual(result, 'Aliens')
 def test_story_joke(self):
     obj = Interface()
     result = obj.ask("Tell me a joke!")
     self.assertEqual(
         result,
         "To whoever took my Microsoft Office: I will find you. You have my Word."
     )
 def test_request_notastring(self):
     """
     Check that Exception is raised when request is not a string
     :return:
     """
     qaobject = Interface()
     self.assertRaises(Exception, qaobject.request, 2555)
示例#8
0
    def test_ask_who_let_dogs_out(self):
        obj = Interface()
        question = 'Who let the dogs out?'
        result = obj.ask(question)
        output_to_file(question, result)

        self.assertEqual(result, getpass.getuser() + ' let the dogs out')
示例#9
0
 def test_git_utils_path_untracked(self, mock_subproc_popen):
     """
     Checks if ability to detected files which have not been checked in, is operational
     :param mock_subproc_popen: Function who's return is mocked
     :return:
     """
     p_mock1 = mock.Mock()
     attrs = {'communicate.return_value': ('', '')}
     p_mock1.configure_mock(**attrs)
     attrs = {'communicate.return_value': ('', '')}
     p_mock2 = mock.Mock()
     p_mock2.configure_mock(**attrs)
     attrs = {'communicate.return_value': ('didntcommit.txt', '')}
     p_mock3 = mock.Mock()
     p_mock3.configure_mock(**attrs)
     attrs = {'communicate.return_value': (PARENT_DIRECTORY, '')}
     p_mock4 = mock.Mock()
     p_mock4.configure_mock(**attrs)
     mock_subproc_popen.side_effect = [p_mock1, p_mock2, p_mock3, p_mock4]
     qaobject = Interface()
     result = qaobject.ask("What is the status of <didntcommit.txt>?")
     self.assertEqual(result,
                      'didntcommit.txt has been not been checked in')
     self.assertRaises(Exception, git_utils.get_git_file_info,
                       'X/:somethingnottrue')
示例#10
0
 def test_ask_open_door(self):
     obj = Interface()
     question = 'Open the door hal'
     result = obj.demand(question)
     output_to_file(question, result)
     self.assertEqual(result,
                      'I\'m afraid I can\'t do that ' + getpass.getuser())
示例#11
0
 def test_provide_answer_corrected_square2(self):
     obj = Interface()
     obj.ask('What type of flamingo is this 1 1 1 1?')
     obj.teach(get_triangle_type)
     obj.correct(get_quad_type)
     result = obj.ask('What type of flamingo is this 1 1 1 1?')
     self.assertEqual(result, 'Square')
示例#12
0
 def test_file_dirty(self, mock_dirty, mock_untracked, mock_diff):
     obj = Interface()
     mock_diff.return_value = []
     mock_dirty = True
     mock_untracked.return_value = []
     result = obj.ask('What is the status of <requirements.txt>?')
     self.assertEqual(result, 'requirements.txt is a dirty repo')
示例#13
0
 def test_provide_answer_already_asked2(self):
     obj = Interface()
     obj.ask('Why did Abe Lincoln start killing vampires?')
     obj.teach('Because Abe hates glitter')
     result = obj.teach('Because Abe hates glitter')
     self.assertEqual(result,
                      "I don\'t know about that. I was taught differently")
 def test_ask_notastring(self):
     """
     Check that Exception is raised when ask is not a string
     :return:
     """
     qaobject = Interface()
     self.assertRaises(Exception, qaobject.ask, 45566)
 def test_ask_toomanyparamters(self):
     """
     Check that Exception is raised with too many parameters.
     :return:
     """
     qaobject = Interface()
     self.assertRaises(Exception, qaobject.ask, "What type of triangle is: 3 4 5 6?")
 def test_question_update_noprevious(self):
     """
     Check that correct responds correctly when no previous question exists.
     :return:
     """
     qaobject = Interface()
     result = qaobject.correct("42")
     self.assertEqual(result, 'Please ask a question first')
 def test_question_answer_noprevious(self):
     """
     Check returns proper output when no question mark.
     :return:
     """
     qaobject = Interface()
     result = qaobject.teach("How now brown cow.")
     self.assertEqual(result, 'Please ask a question first')
示例#18
0
 def test_story_clear_mem_teach(self):
     obj = Interface()
     obj.ask('Why did Abe Lincoln start killing vampires?')
     obj.teach('Because Abe hates glitter')
     obj.ask('Why did Abe Lincoln start killing vampires?')
     obj.ask("Please clear memory?")
     result = obj.ask('Why did Abe Lincoln start killing vampires?')
     self.assertEqual(result, 'I don\'t know, please provide the answer')
 def test_ask_no_values(self):
     """
     Test ask function no values
     :return: assertion: invalid
     """
     inquiry = Interface()
     result = inquiry.ask('What type of triangle is this?')
     self.assertEqual(result, "invalid")
 def test_question_string_answer(self):
     """
     Check triangle return correct
     :return:
     """
     qaobject = Interface()
     result = qaobject.ask('What type of triangle is: 3 4 5?')
     self.assertEqual(result, 'scalene')
示例#21
0
 def test_file_not_in_repo(self, mock_subproc_popen):
     obj = Interface()
     process_mock = Mock()
     attrs = {'communicate.return_value': ('test.txt', '')}
     process_mock.configure_mock(**attrs)
     mock_subproc_popen.return_value = process_mock
     result = obj.ask('Is the <test.txt> in the repo?')
     self.assertEqual(result, 'No')
示例#22
0
 def test_provide_answer_corrected_sentence(self):
     obj = Interface()
     obj.ask('Why did Abe Lincoln start killing vampires?')
     obj.teach('Because Abe hates glitter')
     obj.correct('Because Abe wants to add to his glitter collection')
     result = obj.ask('Why did Abe Lincoln start killing vampires?')
     self.assertEqual(result,
                      'Because Abe wants to add to his glitter collection')
 def test_question_string_noqmark(self):
     """
     Check returns proper output for now question mark.
     :return:
     """
     qaobject = Interface()
     result = qaobject.ask("What type of triangle is: 3 3 3")
     self.assertEqual(result, 'Was that a question?')
 def test_question_90percentmatch(self):
     """
     Check returns proper output for question 90% similar to stored question.
     :return:
     """
     qaobject = Interface()
     result = qaobject.ask("What type of quadrilteral is: 2 2 2 2 90 90 90 90?")
     self.assertEqual(result, 'square')
 def test_question_string_nokeyword(self):
     """
     Check returns proper output for unknown question.
     :return:
     """
     qaobject = Interface()
     result = qaobject.ask("Is that a dog?")
     self.assertEqual(result, 'I don\'t know, please provide the answer')
 def test_ask_no_correct(self):
     """
     Test correct function, no question
     :return: assertion: ask question first
     """
     inquiry = Interface()
     result = inquiry.correct('polygon')
     self.assertEqual(result, 'Please ask a question first')
 def test_question_string(self):
     """
     Check returns proper output for improper question
     :return:
     """
     qaobject = Interface()
     result = qaobject.ask("What_type_of_triangle_is: 3 3 3?")
     self.assertEqual(result, 'Was that a question?')
示例#28
0
 def test_story_ten_unit_conversions(self):
     obj = Interface()
     result = obj.ask("What are numeric conversions?")
     self.assertEqual(
         result,
         'tera = 6, giga = 5, mega = 4, kilo = 3, deca = 1, no_unit = 0, deci = -1, centi = -2, '
         '\n milli = -3, micro = -4, nano = -5, pico = -6; '
         '\n Format = "Convert <value> <unit> to <unit to convert to>"')
 def test_question_number_placement(self):
     """
     Check returns correct answer when numbers are placed incorrectly.
     :return:
     """
     qaobject = Interface()
     result = qaobject.ask("What type 2 of trangle is: 2 2?")
     self.assertEqual(result, 'equilateral')
 def test_ask_bad_question(self):
     """
     Test ask function bad question
     :return: assertion: provide answer
     """
     inquiry = Interface()
     result = inquiry.ask('What kind of shape has sides 1 1 3?')
     self.assertEqual(result, "I don't know, please provide the answer")