def testCompile(self): """Tests the Compile function.""" expression = expressions.BinaryExpression(operator='and') expression.Compile() expression = expressions.BinaryExpression() with self.assertRaises(errors.ParseError): expression.Compile()
def testAddOperands(self): """Tests the AddOperands function.""" expression = expressions.BinaryExpression(operator='and') left_hand_expression = expressions.Expression() right_hand_expression = expressions.Expression() expression.AddOperands(left_hand_expression, right_hand_expression) with self.assertRaises(errors.ParseError): expression.AddOperands(None, right_hand_expression) with self.assertRaises(errors.ParseError): expression.AddOperands(left_hand_expression, None)
def _AddBinaryOperator(self, string=None, **unused_kwargs): """Adds a binary operator to the stack. Note that this function is used as a callback by _GetNextToken. Args: string (str): operator, such as "and", "or", "&&" or "||". Returns: str: next state, which is None. """ expression = expressions.BinaryExpression(operator=string) self._stack.append(expression) return None