def test__eq__3(self): """ Variable different. """ que_1 = Question("TestQuestion1", Variable(str, "TestVar1")) que_2 = Question("TestQuestion1", Variable(str, "TestVar2")) self.assertNotEqual(que_1, que_2)
def test_putting_questions_in_pipe_mult_questions(self): """ Run one timestep, multiple questions given, multiple questions in pipe expected. Case with multiple questions in *one single* occurrence. """ communicator_end, testsuite_end = multiprocessing.Pipe(True) question_1 = Question("How are you?", self.var_foo) question_2 = Question("Walk to Hell!", self.var_foo) schedule = MockQuestionSchedule( (QuestionOccurrence({question_1, question_2}, 123), )) communicator = QuestionCommunicator(communicator_end, self.db, schedule) communicator.mainloop(0, 1) self.assertTrue(testsuite_end.poll()) testsuite_end.recv() # First output already tested in test above. self.assertFalse(testsuite_end.poll()) result = testsuite_end.recv() self.assertIsInstance(result, QuestionMessage) self.assertEqual(result.id, 666) self.assertEqual(result.text, "Walk to Hell!") self.assertEqual(result.variable, self.var_foo) self.assertFalse(testsuite_end.poll())
def test__eq__1(self): """ Both inputs should be equal. """ que_1 = Question("TestQuestion1", Variable(str, "TestVar1")) que_2 = Question("TestQuestion1", Variable(str, "TestVar1")) self.assertEqual(que_1, que_2)
def test_putting_question_in_pipe(self): """ Run the mainloop of QuestionCommunicator for one timestep. The given QuestionSchedule generates one set of QuestionOccurrences, with one question. The QuestionCommunicator should put a corresponding QuestionMessage in the Queue. """ communicator_end, testsuite_end = multiprocessing.Pipe(True) question = Question("How are you?", self.var_foo) schedule = MockQuestionSchedule((QuestionOccurrence({question}, 123), )) communicator = QuestionCommunicator(communicator_end, self.db, schedule) communicator.mainloop(0, 1) self.assertTrue(testsuite_end.poll()) result = testsuite_end.recv() self.assertIsInstance(result, QuestionMessage) self.assertEqual(result.id, 123) self.assertEqual(result.text, "How are you?") self.assertEqual(result.variable, self.var_foo) self.assertFalse(testsuite_end.poll())
def test_repr_2(self): """ Base-case: str-typed Question """ question = Question("TestQuestion1", Variable(str, "TestVar1")) expected = "Question(Variable(str,'TestVar1')):TestQuestion1" result = str(question) self.assertEqual(result, expected)
def test_repr_1(self): """ Base case: str-typed Question """ question = Question("TestQuestion", Variable(str, "TestVar")) expected = "Question('TestQuestion',Variable(str,'TestVar'))" result = repr(question) self.assertEqual(result, expected)
def setUp(self) -> None: """ Scheduled time: Tuesday 7:30 Start time: Monday 15:22, 22 March """ start_time = 1616422958 self.recurring_question = RecurringQuestionSet( {WeekDay(1)}, 7, 30, {Question("test", Variable(str, "my_var"))}, start_time)
def test_putting_questions_in_pipe_mult_questions(self): """ One question occurs per timestep. So after 2 timesteps, there should be 2 questions in the pipe. """ communicator_end, testsuite_end = multiprocessing.Pipe(True) question_1 = Question("How are you?", self.var_foo) schedule = MockQuestionSchedule((QuestionOccurrence({question_1}, 123), )) communicator = QuestionCommunicator(communicator_end, self.db, schedule) communicator.mainloop(0, 2) self.assertTrue(testsuite_end.poll()) testsuite_end.recv() # Question from first timestep self.assertTrue(testsuite_end.poll()) testsuite_end.recv() # Question from second timestep self.assertFalse(testsuite_end.poll())
def test_repr(self): occurrence = QuestionOccurrence( Question("TestQuestion", Variable(str, "TestVar")), 0) expected = "0: 'TestQuestion'" result = str(occurrence) self.assertEqual(result, expected)