def test_activity_ast(): """Test a mix of various activities using legacy and new parser.""" activity_text = ("""activity = [ '<p>This is just some <i>HTML</i> text!</p>', { questionType: 'multiple choice', questionHTML: '<p>What letter am I thinking about now?</p>', choices: [ ['A', false, '"A" is wrong, try again.'], ['B', true, '"B" is correct!'], ['C', false, '"C" is wrong, try again.'], ['D', false, '"D" is wrong, try again.'] ] }, { questionType: 'freetext', questionHTML: '<p>What color is the snow?</p>', correctAnswerRegex: regex("/white/i"), correctAnswerOutput: 'Correct!', incorrectAnswerOutput: 'Try again.', showAnswerOutput: 'Our search expert says: white!' }, { questionType: 'multiple choice group', questionGroupHTML: '<p>This section will test you on colors and numbers.</p>', allCorrectMinCount: 2, questionsList: [ {questionHTML: 'Pick all <i>odd</i> numbers:', choices: ['1', '2', '3', '4', '5'], correctIndex: [0, 2, 4]}, {questionHTML: 'Pick one <i>even</i> number:', choices: ['1', '2', '3', '4', '5'], correctIndex: [1, 3], multiSelect: false}, {questionHTML: 'What color is the sky?', choices: ['#00FF00', '#00FF00', '#0000FF'], correctIndex: 2} ], allCorrectOutput: 'Great job! You know the material well.', someIncorrectOutput: 'You must answer at least two questions correctly.' } ]; """) verify_activity(activity_text) scope = verify.Activity().scope current_ast = ActivityParser13.parse_string_in_scope( activity_text, scope, 'activity') expected_ast = verify.legacy_eval_python_expression_for_test( activity_text, scope, 'activity') same = (len(current_ast.get('activity')) == 4 and current_ast.get('activity') == expected_ast.get('activity') and current_ast == expected_ast) if not same: import pprint # # pylint: disable-msg=g-import-not-at-top pprint.pprint(current_ast.get('activity')) pprint.pprint(expected_ast.get('activity')) assert same
def test_assessment_ast(): """Test a mix of various activities using legacy and new parser.""" # pylint: disable-msg=anomalous-backslash-in-string assessment_text = ( """assessment = { preamble: '<p>This is text.</p>', questionsList: [ {'questionHTML': '<p>This is text.</p>', choices: ["A and B", "D and B", correct("A and C"), "C and D", "I don't know"] }, {"questionHTML": '<p>This is text.</p>', choices: [correct("True"), "False", "I don't know"], choiceScores: [0, 0.5, 1.0], weight: 3 }, {questionHTML: '<p>This is text.</p>', correctAnswerString: 'sunrise' }, {questionHTML: '<p>This is text.</p>', correctAnswerRegex: regex("/354\s*[+]\s*651/") } ], assessmentName: 'Pre', checkAnswers: false } """) # pylint: enable-msg=anomalous-backslash-in-string verify_assessment(assessment_text) scope = verify.Assessment().scope current_ast = AssessmentParser13.parse_string_in_scope( assessment_text, scope, 'assessment') expected_ast = verify.legacy_eval_python_expression_for_test( assessment_text, scope, 'assessment') same = ( len(current_ast.get('assessment')) == 4 and len(current_ast.get('assessment').get('questionsList')) == 4 and current_ast.get('assessment') == expected_ast.get('assessment') and current_ast == expected_ast) if not same: import pprint # # pylint: disable-msg=g-import-not-at-top pprint.pprint(current_ast.get('assessment')) pprint.pprint(expected_ast.get('assessment')) assert same
def test_assessment_ast(): """Test a mix of various activities using legacy and new parser.""" # pylint: disable=anomalous-backslash-in-string assessment_text = ( """assessment = { preamble: '<p>This is text.</p>', questionsList: [ {'questionHTML': '<p>This is text.</p>', choices: ["A and B", "D and B", correct("A and C"), "C and D", "I don't know"] }, {"questionHTML": '<p>This is text.</p>', choices: [correct("True"), "False", "I don't know"], choiceScores: [0, 0.5, 1.0], weight: 3 }, {questionHTML: '<p>This is text.</p>', correctAnswerString: 'sunrise' }, {questionHTML: '<p>This is text.</p>', correctAnswerRegex: regex("/354\s*[+]\s*651/") } ], assessmentName: 'Pre', checkAnswers: false } """) # pylint: enable=anomalous-backslash-in-string verify_assessment(assessment_text) scope = verify.Assessment().scope current_ast = AssessmentParser13.parse_string_in_scope( assessment_text, scope, 'assessment') expected_ast = verify.legacy_eval_python_expression_for_test( assessment_text, scope, 'assessment') same = ( len(current_ast.get('assessment')) == 4 and len(current_ast.get('assessment').get('questionsList')) == 4 and current_ast.get('assessment') == expected_ast.get('assessment') and current_ast == expected_ast) if not same: import pprint pprint.pprint(current_ast.get('assessment')) pprint.pprint(expected_ast.get('assessment')) assert same
def test_activity_ast(): """Test a mix of various activities using legacy and new parser.""" activity_text = ( """activity = [ '<p>This is just some <i>HTML</i> text!</p>', { questionType: 'multiple choice', questionHTML: '<p>What letter am I thinking about now?</p>', choices: [ ['A', false, '"A" is wrong, try again.'], ['B', true, '"B" is correct!'], ['C', false, '"C" is wrong, try again.'], ['D', false, '"D" is wrong, try again.'] ] }, { questionType: 'freetext', questionHTML: '<p>What color is the snow?</p>', correctAnswerRegex: regex("/white/i"), correctAnswerOutput: 'Correct!', incorrectAnswerOutput: 'Try again.', showAnswerOutput: 'Our search expert says: white!' }, { questionType: 'multiple choice group', questionGroupHTML: '<p>This section will test you on colors and numbers.</p>', allCorrectMinCount: 2, questionsList: [ {questionHTML: 'Pick all <i>odd</i> numbers:', choices: ['1', '2', '3', '4', '5'], correctIndex: [0, 2, 4]}, {questionHTML: 'Pick one <i>even</i> number:', choices: ['1', '2', '3', '4', '5'], correctIndex: [1, 3], multiSelect: false}, {questionHTML: 'What color is the sky?', choices: ['#00FF00', '#00FF00', '#0000FF'], correctIndex: 2} ], allCorrectOutput: 'Great job! You know the material well.', someIncorrectOutput: 'You must answer at least two questions correctly.' } ]; """) verify_activity(activity_text) scope = verify.Activity().scope current_ast = ActivityParser13.parse_string_in_scope( activity_text, scope, 'activity') expected_ast = verify.legacy_eval_python_expression_for_test( activity_text, scope, 'activity') same = ( len(current_ast.get('activity')) == 4 and current_ast.get('activity') == expected_ast.get('activity') and current_ast == expected_ast) if not same: import pprint # # pylint: disable-msg=g-import-not-at-top pprint.pprint(current_ast.get('activity')) pprint.pprint(expected_ast.get('activity')) assert same