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_get_attribute_returns_the_proper_representation(self):
expression = GetAttributeExpression(GetAttributeExpression("some","weird"), "expression")
assert str(expression) == "some.weird.expression"
def test_where_binary_equals_returns_get_attribute_expression_on_lhs(self):
col = []
tree = From(col).where("some.other.property == 'Bernardo'")
error = "Lhs should be GetAttributeExpression but was %s"
class_name = tree.expressions[0].__class__.__name__
assert isinstance(tree.expressions[0].lhs, GetAttributeExpression), \
error % class_name
def test_get_attribute_expression_validates_against_empty_attributes(self):
self.assertRaisesEx(ValueError, GetAttributeExpression, exc_pattern=re.compile("In order to create a new attribute expression you need to provide some attributes."))
def test_nested_get_attribute_expressions_work_together(self):
expression = GetAttributeExpression(GetAttributeExpression("some","weird"), "expression")
assert len(expression.attributes) == 3
assert expression.attributes[0] == "some"
assert expression.attributes[1] == "weird"
assert expression.attributes[2] == "expression"
def test_get_attribute_expression_keeps_track_of_attributes(self):
expression = GetAttributeExpression("some","expression")
assert len(expression.attributes) == 2, "Length of attributes property should be 2 but was %d" % len(expression.attributes)
assert expression.attributes[0] == "some"
assert expression.attributes[1] == "expression"
def add_attributes(self, attrs):
for attr in attrs:
if isinstance(attr, GetAttributeExpression):
self.add_attributes(attr.attributes)
else:
self.attributes.append(attr)
def led(self, left):
first = left
second = token
if not isinstance(second, NameToken):
error = u"Each part of a given get attribute expression (some.variable.value) needs to be a NameExpression."
raise ValueError(error)
second = NameExpression(second.value)
self.advance()
return GetAttributeExpression(first, second)