コード例 #1
0
    def helper_test_evaluate_raises(self,
                                    expr,
                                    expected_exc_type=None,
                                    **kwargs):
        """Helper for testing the improper use of the ``evaluate`` function.


        :param expr: The expression to attempt to evaluate.
        :type expr: :class:`str <python:str>`

        :param expected_exc_type: The exception type expected to be raised.
        :type expected_exc_type: Exception

        :param kwargs: The values to pass to the ``evaluate`` function.

        """
        did_catch = False

        try:
            b = BooleanExpression(expr)
            b.evaluate(**kwargs)
        except expected_exc_type:
            did_catch = True
        except Exception as e:
            traceback.print_exc()
            self.fail('Received exception of type ' + type(e).__name__ +
                      ' but was expecting type ' + expected_exc_type.__name__ +
                      '.')
            did_catch = True

        if not did_catch:
            self.fail('No exception thrown.')
コード例 #2
0
    def helper_test_evaluate(self, expr, expected_result=None, **kwargs):
        """Helper for testing the evaluation of expressions.

        :param expr: The expression to attempt to evaluate.
        :type expr: :class:`str <python:str>`

        :param expected_result: The truthy value expected to be the result of
            evaluation the expression.
        :type expected_result: :class:`bool <python:bool>` or
            :class:`int <python:int>`

        :param kwargs: The values to pass to the ``evaluate`` function.

        """
        b = BooleanExpression(expr)
        result = b.evaluate(**kwargs)
        self.assertEqual(result, expected_result)