Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_expression_length_of_constant(self):
a = ConstantExpression(["a","b"])
node_type = UnaryExpression.CollectionLength
expr = UnaryExpression(node_type, a)
self.assertEquals(expr.node_type, node_type)
self.assertEquals(expr.rhs, a)
def test_nested_negate_expression(self):
a = ConstantExpression(10)
node_type = UnaryExpression.Negate
expr = UnaryExpression(node_type, UnaryExpression(node_type, a))
self.assertEquals(expr.node_type, node_type)
self.failUnless(isinstance(expr.rhs, UnaryExpression), "The right-hand side of the unary expression should be an unary expression as well, but is %s" % expr.rhs.__class__)
self.assertEquals(expr.rhs.node_type, node_type)
self.assertEquals(expr.rhs.rhs, a)
def test_expression_equal_of_two_constants_representation(self):
a = ConstantExpression(["a","b"])
node_type = UnaryExpression.CollectionLength
expr = UnaryExpression(node_type, a)
self.assertEquals("len(['a', 'b'])", str(expr))
def test_nested_not_expression_representation(self):
a = ConstantExpression(True)
node_type = UnaryExpression.Not
expr = UnaryExpression(node_type, UnaryExpression(node_type, a))
self.assertEquals("(not (not True))", str(expr))
def test_nested_negate_expression_representation(self):
a = ConstantExpression(10)
node_type = UnaryExpression.Negate
expr = UnaryExpression(node_type, UnaryExpression(node_type, a))
self.assertEquals("negate(negate(10))", str(expr))
def nud(self):
return UnaryExpression(UnaryExpression.Negate, self.expression(self.lbp+20))
def led(self, left):
def compare_items(self, a, b):
expression = None
for order_expression in self.order_expressions:
is_negate_expression = isinstance(order_expression, UnaryExpression) and \
order_expression.node_type == UnaryExpression.Negate
modifier = 1
curr_expr = order_expression
if is_negate_expression:
modifier = -1
curr_expr = order_expression.rhs
if isinstance(curr_expr, NameExpression):
field_name = curr_expr.name
result = cmp(modifier * getattr(a, field_name), modifier * getattr(b, field_name))
else:
item = a
val1 = eval(str(curr_expr))
item = b
val2 = eval(str(curr_expr))
result = cmp(modifier * val1, modifier * val2)