How to use the pynq.From 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_pynq_factory.py View on Github external
def test_where_power_returns_proper_results(self):
        col = [self.TwoValues(1, 2), self.TwoValues(2, 3), self.TwoValues(3, 4), self.TwoValues(4, 5), self.TwoValues(5, 6)]
        
        items = From(col).where("item.value ** item.value2 > 90").select_many()
        
        assert len(items) == 2, "Only items 4 and 5 should be in the resulting collection, but it has length of %d" % len(items)
        assert items[0].value == 4, "Item 4 should be in the resulting collection but it was %s." % items[0].value
        assert items[1].value == 5, "Item 5 should be in the resulting collection but it was %s." % items[1].value
github heynemann / pynq / tests / unit / test_order_by.py View on Github external
def test_mixed_expression_order(self):
        result = From(self.col).order_by("item.second + item.third", "item.first + item.second").select_many()

        assert result[0].first == 7
        assert result[1].first == 1
        assert result[2].first == 4
github heynemann / pynq / tests / unit / test_pynq_factory.py View on Github external
def test_where_binary_equals_returns_tree(self):
        col = []
        tree = From(col).where("some.other.property == 'Bernardo'")
        
        assert tree is not None, "The From method needs to return something"
        assert isinstance(tree, Query), "The lambda should have resolved to a LambdaExpression"
github heynemann / pynq / tests / unit / test_select_fields.py View on Github external
def test_select_returns_class_without_third_attribute(self):
        filtered = From(self.col).select("first","second")
        for i in range(3):
            assert not hasattr(filtered[i], "third")
github heynemann / pynq / tests / unit / test_collection_provider_sum_avg.py View on Github external
def test_sum_raises_for_an_invalid_property(self):
        error_message = "The attribute '%s' was not found in the specified collection's items. If you meant to use the raw value of each item in the collection just use the word 'item' as a parameter to .sum or use .sum()"
        
        class OneValue(object):
            def __init__(self, value):
                self.value = value
        fr = From([OneValue(1), OneValue(2), OneValue(3)])
        self.assertRaisesEx(ValueError, fr.sum, "value", exc_pattern=re.compile(error_message % "value"))
        self.assertRaisesEx(ValueError, fr.sum, "item.dumb", exc_pattern=re.compile(error_message % "item.dumb"))
        self.assertRaisesEx(ValueError, fr.sum, "", exc_pattern=re.compile(error_message % ""))
        self.assertRaisesEx(ValueError, fr.sum, None, exc_pattern=re.compile(error_message % "None"))
github heynemann / pynq / tests / unit / test_pynq_factory.py View on Github external
def test_passing_tuple_returns_collection_provider(self):
        query = From(tuple([]))
        assert isinstance(query.provider, CollectionProvider)
github heynemann / pynq / tests / unit / test_pynq_factory.py View on Github external
def test_where_binary_equals_returns_the_right_value_on_the_rhs(self):
        col = []
        tree = From(col).where("some.other.property == 'Bernardo'")

        assert tree.expressions[0].rhs.value == "'Bernardo'"
github heynemann / pynq / tests / unit / benchmark.py View on Github external
def run_many_small_collections():
    start_time = time.time()
    
    fixed_col = [OneValue(1), OneValue(2), OneValue(3)]
    
    for i in range(ITERATIONS):
        total = From(fixed_col).avg("item.value.value")

    print "AVG FIXED COL OPERATION - %d iterations took %.2f" % (ITERATIONS, (time.time() - start_time))
github heynemann / pynq / tests / unit / test_collection_provider_sum_avg.py View on Github external
def test_sum_returns_right_amount_for_a_given_sub_property(self):
        class OtherValue(object):
            def __init__(self, value):
                self.value = value
                
        class OneValue(object):
            def __init__(self, value):
                self.value = OtherValue(value)
                
        total = From([OneValue(1), OneValue(2), OneValue(3)]).sum("item.value.value")
        assert total == 6, "total should be 6 but was %s" % total
github heynemann / pynq / tests / unit / test_collection_provider_max_min.py View on Github external
def test_min_returns_right_amount_for_a_given_sub_property(self):
        class OtherValue(object):
            def __init__(self, value):
                self.value = value
                
        class OneValue(object):
            def __init__(self, value):
                self.value = OtherValue(value)
                
        value = From([OneValue(1), OneValue(2), OneValue(3)]).min("item.value.value")
        assert value == 1, "value should be 1 but was %s" % value