How to use the pynq.expressions.NameExpression function in pynq

To help you get started, we’ve selected a few pynq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github heynemann / pynq / tests / unit / test_name_expression.py View on Github external
def test_name_expression_string_repr(self):
        expression = NameExpression("somename")
        assert str(expression) == "somename"
github heynemann / pynq / tests / unit / test_name_expression.py View on Github external
def test_name_expression(self):
        expression = NameExpression("somename")
        assert expression.name == "somename", "The name of the" \
                                               " variable in this expression should be" \
                                               " 'somename' but was %s" % expression.name
github heynemann / pynq / tests / unit / test_group_by.py View on Github external
def test_grouping_adds_right_expression_for_name_expression(self):
        query = From(self.col).group_by("second")
        assert isinstance(query.group_expression, NameExpression)
github heynemann / pynq / tests / unit / test_order_by.py View on Github external
def test_adding_order_creates_a_name_expression_in_query(self):
        query = From([]).order_by("some")
        assert isinstance(query.order_expressions[0], NameExpression)
github heynemann / pynq / tests / unit / test_pynq_factory.py View on Github external
def test_where_binary_equals_returns_tree_name_expressions_as_attributes_on_lhs(self):
        col = []
        tree = From(col).where("some.other.property == 'Bernardo'")
        error_message = "There should be three attributes "\
                        "('some','other','property') in the GetAttributeExpression, "\
                        "but there was %d"
        assert len(tree.expressions[0].lhs.attributes) == 3, \
                error_message % len(tree.expressions[0].lhs.attributes)
        for i in range(3):
            error = "The %d parameter should be a NameExpression but was %s"
            class_name = tree.expressions[0].lhs.attributes[i].__class__.__name__
            assert isinstance(tree.expressions[0].lhs.attributes[i], NameExpression), \
                                error % (i, class_name)
github heynemann / pynq / pynq / providers / __init__.py View on Github external
def transform_collection(self, col, cols):
        dynamic_item = type('DynamicItem', (object,), {})

        items = []
        app = items.append
        for item in col:
            field_count = 0
            new_item = dynamic_item()
            for field in cols:
                if isinstance(field, NameExpression):
                    field_name = field.name
                    setattr(new_item, field_name, getattr(item, field_name))
                else:
                    setattr(new_item, "dynamic_%d" % field_count, eval(str(field)))
                field_count += 1
            app(new_item)

        return items
github heynemann / pynq / pynq / providers / __init__.py View on Github external
def __group_collection(self, collection, group_expression):
        if isinstance(group_expression, NameExpression):
            expr_name = group_expression.name
            if "." in expr_name:
                rel = lambda item: reduce(getattr, expr_name, item)
            else:
                rel = lambda item: getattr(item, expr_name)
        else:
            rel = lambda item: eval(str(query.group_expression))

        return EquivalenceClassSetPartition.partition(collection, rel)
github heynemann / pynq / pynq / parser.py View on Github external
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)
github heynemann / pynq / pynq / parser.py View on Github external
def nud(self):
        return NameExpression(self.value)