def test_answer(self):
        result = gift.GiftParser.multi_choice_answer.parseString('= c }')[0]
        answer = gift.to_dict(result)
        self.assertEqual('c', answer['text'])

        result = gift.GiftParser.multi_choice_answer.parseString('~w ~')[0]
        answer = gift.to_dict(result)
        self.assertEqual('w', answer['text'])

        # test missing trailing separator
        with self.assertRaises(ParseException):
            gift.GiftParser.multi_choice_answer.parseString('=c')
    def test_answer(self):
        result = gift.GiftParser.multi_choice_answer.parseString('= c }')[0]
        answer = gift.to_dict(result)
        self.assertEqual('c', answer['text'])

        result = gift.GiftParser.multi_choice_answer.parseString('~w ~')[0]
        answer = gift.to_dict(result)
        self.assertEqual('w', answer['text'])

        # test missing trailing separator
        with self.assertRaises(ParseException):
            gift.GiftParser.multi_choice_answer.parseString('=c')
    def test_answer(self):
        result = gift.GiftParser.multi_choice_answer.parseString('~%50% a}')[0]
        answer = gift.to_dict(result)
        self.assertEqual(50, answer['score'])
        self.assertEqual('a', answer['text'])

        result = gift.GiftParser.multi_choice_answer.parseString(
            '~%-100% a ~%')[0]
        answer = gift.to_dict(result)
        self.assertEqual(-100, answer['score'])
        self.assertEqual('a', answer['text'])

        # missing end of answer separator
        with self.assertRaises(ParseException):
            gift.GiftParser.multi_choice_answer.parseString('~%100%a')
    def test_answer(self):
        result = gift.GiftParser.multi_choice_answer.parseString('~%50% a}')[0]
        answer = gift.to_dict(result)
        self.assertEqual(50, answer['score'])
        self.assertEqual('a', answer['text'])

        result = gift.GiftParser.multi_choice_answer.parseString(
            '~%-100% a ~%')[0]
        answer = gift.to_dict(result)
        self.assertEqual(-100, answer['score'])
        self.assertEqual('a', answer['text'])

        # missing end of answer separator
        with self.assertRaises(ParseException):
            gift.GiftParser.multi_choice_answer.parseString('~%100%a')
 def test_question(self):
     s = 'Two plus two equals { =four =4}'
     result = gift.GiftParser.short_answer_question.parseString(s)[0]
     question = gift.to_dict(result[1])
     self.assertEqual('Two plus two equals', question['task'])
     self.assertEqual('four', question['choices'][0]['text'])
     self.assertEqual('4', question['choices'][1]['text'])
 def test_sample_questions(self):
     questions = self._get_sample_questions()
     self.assertEqual(28, len(questions))
     for question in questions:
         result = gift.GiftParser.parse(question)[0]
         question = gift.to_dict(result)
         assert 'question' in question
 def test_question(self):
     s = 'Two plus two equals { =four =4}'
     result = gift.GiftParser.short_answer_question.parseString(s)[0]
     question = gift.to_dict(result[1])
     self.assertEqual('Two plus two equals', question['task'])
     self.assertEqual('four', question['choices'][0]['text'])
     self.assertEqual('4', question['choices'][1]['text'])
 def test_sample_questions(self):
     questions = self._get_sample_questions()
     self.assertEqual(28, len(questions))
     for question in questions:
         result = gift.GiftParser.parse(question)[0]
         question = gift.to_dict(result)
         assert 'question' in question
 def test_answers(self):
     result = gift.GiftParser.match_answers.parseString(
         '{=a->1 = b->2 =c->3}')
     answers = gift.to_dict(result[0])
     self.assertEqual(['a', 'b', 'c'],
                      [x['lhs'] for x in answers['choices']])
     self.assertEqual(['1', '2', '3'],
                      [x['rhs'] for x in answers['choices']])
Пример #10
0
 def test_answers_spaces_and_separators(self):
     tests = [
         '~%25%a1~%75%a2~%-100%a3}',
         '~%25% a1~%75% a2 ~%-100% a3 }',
         '~%25% a1~%75% a2 ~%-100% a3 }']
     for s in tests:
         result = gift.GiftParser.multi_choice_answers.parseString(s)[0]
         choices = gift.to_dict(result[1])
         self.assertEqual(3, len(choices))
    def test_scores_spaces_and_separators(self):
        result = gift.GiftParser.multi_choice_answers.parseString(
            '~w1 =c ~w2}')[0]
        answers = gift.to_dict(result)
        self.assertEqual([0, 100, 0], [x['score'] for x in answers['choices']])

        result = gift.GiftParser.multi_choice_answers.parseString(
            '=c ~w1 ab~w2}')[0]
        answers = gift.to_dict(result)
        self.assertEqual([100, 0, 0], [x['score'] for x in answers['choices']])
        self.assertEqual('w1 ab', answers['choices'][1]['text'])

        s = (' =yellow # right; good! ~red # wrong, '
             'it\'s yellow ~blue # wrong, it\'s yellow }')
        result = gift.GiftParser.multi_choice_answers.parseString(s)[0]
        answers = gift.to_dict(result)
        self.assertEqual('yellow', answers['choices'][0]['text'])
        self.assertEqual('right; good!', answers['choices'][0]['feedback'])
 def test_question_short_form(self):
     s = ('Question{= A correct answer ~Wrong answer1 ~Wrong answer2 '
          '~Wrong answer3 ~Wrong answer4 }')
     result = gift.GiftParser.multi_choice_question.parseString(s)[0]
     question = gift.to_dict(result)['question']
     self.assertEqual('Question', question['task'])
     self.assertEqual(5, len(question['choices']))
     self.assertEqual([100, 0, 0, 0, 0],
                      [x['score'] for x in question['choices']])
 def test_answers_spaces_and_separators(self):
     tests = [
         '~%25%a1~%75%a2~%-100%a3}', '~%25% a1~%75% a2 ~%-100% a3 }',
         '~%25% a1~%75% a2 ~%-100% a3 }'
     ]
     for s in tests:
         result = gift.GiftParser.multi_choice_answers.parseString(s)[0]
         choices = gift.to_dict(result[1])
         self.assertEqual(3, len(choices))
Пример #14
0
    def test_scores_spaces_and_separators(self):
        result = gift.GiftParser.multi_choice_answers.parseString(
            '~w1 =c ~w2}')[0]
        answers = gift.to_dict(result)
        self.assertEqual([0, 100, 0], [x['score'] for x in answers['choices']])

        result = gift.GiftParser.multi_choice_answers.parseString(
            '=c ~w1 ab~w2}')[0]
        answers = gift.to_dict(result)
        self.assertEqual([100, 0, 0], [x['score'] for x in answers['choices']])
        self.assertEqual('w1 ab', answers['choices'][1]['text'])

        s = (' =yellow # right; good! ~red # wrong, '
             'it\'s yellow ~blue # wrong, it\'s yellow }')
        result = gift.GiftParser.multi_choice_answers.parseString(s)[0]
        answers = gift.to_dict(result)
        self.assertEqual('yellow', answers['choices'][0]['text'])
        self.assertEqual(
            'right; good!', answers['choices'][0]['feedback'])
Пример #15
0
 def test_answers(self):
     result = gift.GiftParser.match_answers.parseString(
         '{=a->1 = b->2 =c->3}')
     answers = gift.to_dict(result[0])
     self.assertEqual(
         ['a', 'b', 'c'],
         [x['lhs'] for x in answers['choices']])
     self.assertEqual(
         ['1', '2', '3'],
         [x['rhs'] for x in answers['choices']])
Пример #16
0
 def test_question_short_form(self):
     s = ('Question{= A correct answer ~Wrong answer1 ~Wrong answer2 '
          '~Wrong answer3 ~Wrong answer4 }')
     result = gift.GiftParser.multi_choice_question.parseString(s)[0]
     question = gift.to_dict(result)['question']
     self.assertEqual('Question', question['task'])
     self.assertEqual(5, len(question['choices']))
     self.assertEqual(
         [100, 0, 0, 0, 0],
         [x['score'] for x in question['choices']])
    def test_numeric_range_answer(self):
        # test for question w.o. error margin
        result = gift.GiftParser.numeric_answer.parseString('{#2}')
        self.assertEqual(2, result.answer)

        # test range question
        s = 'What is the value of pi (to 3 decimal places)? {#3.141..3.142}.'
        result = gift.GiftParser.numeric_question.parseString(s)[0]
        question = gift.to_dict(result[1])
        self.assertEqual(3.141, question['choices'][0]['min'])
        self.assertEqual(3.142, question['choices'][0]['max'])
Пример #18
0
    def test_numeric_range_answer(self):
        # test for question w.o. error margin
        result = gift.GiftParser.numeric_answer.parseString('{#2}')
        self.assertEqual(2, result.answer)

        # test range question
        s = 'What is the value of pi (to 3 decimal places)? {#3.141..3.142}.'
        result = gift.GiftParser.numeric_question.parseString(s)[0]
        question = gift.to_dict(result[1])
        self.assertEqual(3.141, question['choices'][0]['min'])
        self.assertEqual(3.142, question['choices'][0]['max'])
 def test_question(self):
     s = """
         // question: 0 name: TrueStatement using {T} style
         ::TrueStatement about Grant::
         Grant was buried in a tomb in New York City.{T}
     """
     result = gift.GiftParser.true_false_question.parseString(s)[0]
     question = gift.to_dict(result[1])
     self.assertEqual('TrueStatement about Grant', question['title'])
     task = 'Grant was buried in a tomb in New York City.'
     self.assertEqual(task, question['task'])
     self.assertEqual(True, question['choices'][0]['text'])
Пример #20
0
 def test_question(self):
     s = """
         // question: 0 name: TrueStatement using {T} style
         ::TrueStatement about Grant::
         Grant was buried in a tomb in New York City.{T}
     """
     result = gift.GiftParser.true_false_question.parseString(s)[0]
     question = gift.to_dict(result[1])
     self.assertEqual('TrueStatement about Grant', question['title'])
     task = 'Grant was buried in a tomb in New York City.'
     self.assertEqual(task, question['task'])
     self.assertEqual(True, question['choices'][0]['text'])
 def test_questions(self):
     task = 'What two people are entombed in Grant\'s tomb?'
     question = """
         %s {
            ~%-100%No one
            ~%50%Grant
            ~%50%Grant's wife
            ~%-100%Grant's father
         }""" % task
     result = gift.GiftParser.multi_choice_question.parseString(question)[0]
     question = gift.to_dict(result)['question']
     self.assertEqual(task, question['task'])
     self.assertEqual(4, len(question['choices']))
 def test_questions(self):
     s = '''
         // comment
         ::Q2:: What's between orange and green in the spectrum?
         { =yellow # right; good! ~red # wrong, it's yellow ~blue
         # wrong, it's yellow }
         '''
     result = gift.GiftParser.multi_choice_question.parseString(s)[0]
     question = gift.to_dict(result)['question']
     self.assertEqual('Q2', question['title'])
     self.assertEqual("What's between orange and green in the spectrum?",
                      question['task'])
     self.assertEqual(3, len(question['choices']))
Пример #23
0
 def test_questions(self):
     task = 'What two people are entombed in Grant\'s tomb?'
     question = """
         %s {
            ~%-100%No one
            ~%50%Grant
            ~%50%Grant's wife
            ~%-100%Grant's father
         }""" % task
     result = gift.GiftParser.multi_choice_question.parseString(question)[0]
     question = gift.to_dict(result)['question']
     self.assertEqual(task, question['task'])
     self.assertEqual(4, len(question['choices']))
Пример #24
0
 def test_questions(self):
     s = '''
         // comment
         ::Q2:: What's between orange and green in the spectrum?
         { =yellow # right; good! ~red # wrong, it's yellow ~blue
         # wrong, it's yellow }
         '''
     result = gift.GiftParser.multi_choice_question.parseString(s)[0]
     question = gift.to_dict(result)['question']
     self.assertEqual('Q2', question['title'])
     self.assertEqual(
         "What's between orange and green in the spectrum?",
         question['task'])
     self.assertEqual(3, len(question['choices']))
 def test_question(self):
     task = ('Match the following countries with their '
             'corresponding capitals.')
     text = """
         %s {
         =Canada -> Ottawa
         =Italy  -> Rome
         =Japan  -> Tokyo
         =India  -> New Delhi
         }""" % task
     result = gift.GiftParser.match_question.parseString(text)[0]
     question = gift.to_dict(result[1])
     self.assertEqual(task, question['task'])
     # assert there are four matching clauses
     self.assertEqual(4, len(question['choices']))
Пример #26
0
 def test_question(self):
     task = ('Match the following countries with their '
             'corresponding capitals.')
     text = """
         %s {
         =Canada -> Ottawa
         =Italy  -> Rome
         =Japan  -> Tokyo
         =India  -> New Delhi
         }""" % task
     result = gift.GiftParser.match_question.parseString(text)[0]
     question = gift.to_dict(result[1])
     self.assertEqual(task, question['task'])
     # assert there are four matching clauses
     self.assertEqual(4, len(question['choices']))
 def test_question_long_form(self):
     s = '''
         //Comment line
         ::Question title
         :: Question {
         =A correct answer
         ~Wrong answer1
         #A response to wrong answer1
         ~Wrong answer2
         #A response to wrong answer2
         ~Wrong answer3
         #A response to wrong answer3
         ~Wrong answer4
         #A response to wrong answer4
         }'''
     result = gift.GiftParser.multi_choice_question.parseString(s)[0]
     question = gift.to_dict(result)['question']
     self.assertEqual('Question title', question['title'])
     self.assertEqual('Question', question['task'])
     self.assertEqual(5, len(question['choices']))
     self.assertEqual([100, 0, 0, 0, 0],
                      [x['score'] for x in question['choices']])
Пример #28
0
 def test_question_long_form(self):
     s = '''
         //Comment line
         ::Question title
         :: Question {
         =A correct answer
         ~Wrong answer1
         #A response to wrong answer1
         ~Wrong answer2
         #A response to wrong answer2
         ~Wrong answer3
         #A response to wrong answer3
         ~Wrong answer4
         #A response to wrong answer4
         }'''
     result = gift.GiftParser.multi_choice_question.parseString(s)[0]
     question = gift.to_dict(result)['question']
     self.assertEqual('Question title', question['title'])
     self.assertEqual('Question', question['task'])
     self.assertEqual(5, len(question['choices']))
     self.assertEqual(
         [100, 0, 0, 0, 0],
         [x['score'] for x in question['choices']])
 def test_answers(self):
     s = '=c ~w1 ~w2}'
     result = gift.GiftParser.missing_word_answers.parseString(s)
     answers = gift.to_dict(result[0][1])
     self.assertEqual('c', answers[0]['text'])
     self.assertEqual(100, answers[0]['score'])
Пример #30
0
 def test_question(self):
     s = 'CourseBuilder costs {~lots of money =nothing ~little} to download.'
     result = gift.GiftParser.missing_word_question.parseString(s)
     question = gift.to_dict(result[0][1])
     self.assertEqual('CourseBuilder costs ', question['prefix'])
     self.assertEqual(3, len(question['choices']))
Пример #31
0
 def test_answer(self):
     result = gift.GiftParser.short_answer.parseString('=a=')[0]
     self.assertEqual('a', gift.to_dict(result)['text'])
     result = gift.GiftParser.short_answer.parseString('=a }')[0]
     self.assertEqual('a', gift.to_dict(result)['text'])
 def test_essay_question(self):
     task = 'Write a short biography of Dag Hammarskjold.'
     text = '%s {}' % task
     result = gift.GiftParser.essay_question.parseString(text)[0]
     question = gift.to_dict(result[1])
     self.assertEqual(task, question['task'])
Пример #33
0
 def test_answers(self):
     s = '=foo =bar}'
     result = gift.GiftParser.short_answers.parseString(s)
     choices = gift.to_dict(result[0])
     self.assertEqual('foo', choices['choices'][0]['text'])
     self.assertEqual('bar', choices['choices'][1]['text'])
Пример #34
0
 def test_essay_question(self):
     task = 'Write a short biography of Dag Hammarskjold.'
     text = '%s {}' % task
     result = gift.GiftParser.essay_question.parseString(text)[0]
     question = gift.to_dict(result[1])
     self.assertEqual(task, question['task'])
Пример #35
0
 def test_answers(self):
     s = '=c ~w1 ~w2}'
     result = gift.GiftParser.missing_word_answers.parseString(s)
     answers = gift.to_dict(result[0][1])
     self.assertEqual('c', answers[0]['text'])
     self.assertEqual(100, answers[0]['score'])
 def test_question(self):
     s = 'CourseBuilder costs {~lots of money =nothing ~little} to download.'
     result = gift.GiftParser.missing_word_question.parseString(s)
     question = gift.to_dict(result[0][1])
     self.assertEqual('CourseBuilder costs ', question['prefix'])
     self.assertEqual(3, len(question['choices']))
 def test_answer(self):
     result = gift.GiftParser.short_answer.parseString('=a=')[0]
     self.assertEqual('a', gift.to_dict(result)['text'])
     result = gift.GiftParser.short_answer.parseString('=a }')[0]
     self.assertEqual('a', gift.to_dict(result)['text'])
 def test_answers(self):
     s = '=foo =bar}'
     result = gift.GiftParser.short_answers.parseString(s)
     choices = gift.to_dict(result[0])
     self.assertEqual('foo', choices['choices'][0]['text'])
     self.assertEqual('bar', choices['choices'][1]['text'])