Example #1
0
    def test_symbolic_expression_matcher_pymbolic_import_error(self):
        with mock.patch.dict(sys.modules, {'pymbolic': None}):
            expected_warning = ("some_where: unable to check symbolic "
                                "expression")
            mock_vctx = mock.MagicMock()
            SymbolicExpressionMatcher(mock_vctx, "some_where", "abcd")
            self.assertEqual(mock_vctx.add_warning.call_count, 1)
            self.assertIn(expected_warning,
                          mock_vctx.add_warning.call_args[0][1])

            # no validation context
            SymbolicExpressionMatcher(None, "", "abcd")
Example #2
0
 def test_symbolic_expression_matcher_validation_error(self):
     with mock.patch("pymbolic.parse") as mock_pymbolic_parse:
         expected_error_msg = "some error"
         mock_pymbolic_parse.side_effect = ValueError(expected_error_msg)
         with self.assertRaises(ValidationError) as cm:
             SymbolicExpressionMatcher(None, "", "abcd")
         self.assertIn(expected_error_msg, str(cm.exception))
Example #3
0
 def test_symbolic_expression_matcher_validate(self):
     pattern = "1/A"
     matcher = SymbolicExpressionMatcher(None, "", pattern)
     matcher.validate("A^(-1)")
     with self.assertRaises(forms.ValidationError) as cm:
         matcher.validate("A^^(-1)")
     self.assertIn(
         "ParseError: terminal expected, bitwisexor found "
         "instead at index 2: ...^(-1)...']", str(cm.exception))
     self.assertEqual(matcher.correct_answer_text(), pattern)
Example #4
0
 def test_symbolic_expression_matcher_validate(self):
     pattern = "1/A"
     matcher = SymbolicExpressionMatcher(None, "", pattern)
     matcher.validate("A^(-1)")
     with self.assertRaises(forms.ValidationError) as cm:
         matcher.validate("A^^(-1)")
     self.assertIn("ParseError: terminal expected, bitwisexor found "
                   "instead at index 2: ...^(-1)...']",
                   str(cm.exception))
     self.assertEqual(matcher.correct_answer_text(), pattern)
Example #5
0
    def test_symbolic_expression_matcher_grade(self):
        matcher = SymbolicExpressionMatcher(None, "", "1/A")
        self.assertEqual(matcher.grade("A**(-1)"), 1)
        # case sensitive
        self.assertEqual(matcher.grade("a**(-1)"), 0)

        self.assertEqual(matcher.grade("A**(-2)"), 0)

        # parse_sympy error
        self.assertEqual(matcher.grade("A^^(-2)"), 0)

        # simplify error
        with mock.patch("sympy.simplify") as mock_simplify:
            mock_simplify.side_effect = ValueError("my simplify error")
            self.assertEqual(matcher.grade("abcd"), 0)
Example #6
0
    def test_symbolic_expression_matcher_grade(self):
        matcher = SymbolicExpressionMatcher(None, "", "1/A")
        self.assertEqual(matcher.grade("A**(-1)"), 1)
        # case sensitive
        self.assertEqual(matcher.grade("a**(-1)"), 0)

        self.assertEqual(matcher.grade("A**(-2)"), 0)

        # parse_sympy error
        self.assertEqual(matcher.grade("A^^(-2)"), 0)

        # simplify error
        with mock.patch("sympy.simplify") as mock_simplify:
            mock_simplify.side_effect = ValueError("my simplify error")
            self.assertEqual(matcher.grade("abcd"), 0)