예제 #1
0
    def test_with_dictonary(self):
        products = [
            {
                'id': 1,
                'price': 13,
                'category': 2
            },
            {
                'id': 2,
                'price': 99.99,
                'category': 2
            },
            {
                'id': 3,
                'price': 0.01,
                'category': 4
            },
        ]

        p = Pinq(products)
        assert p.select(p.item('price')).max() == 99.99
        assert p.select(p.item('id')).to_list() == [1, 2, 3]
예제 #2
0
    def test_can_iterate(self):
        p = Pinq(self.products)

        for product in p:
            # this is arbitrary, we're really checking we can iterate over p
            assert product.id > 0
예제 #3
0
 def test_returns_max_complex(self):
     p = Pinq(self.products)
     assert p.select(p.attr('price')).max() == 99.99
예제 #4
0
 def test_returns_max(self):
     p = Pinq([5, 90, -22, 42, 42])
     assert p.max() == 90
예제 #5
0
 def test_returns_min_complex(self):
     p = Pinq(self.products)
     assert p.select(p.attr('price')).min() == 0.01
예제 #6
0
 def test_returns_min(self):
     p = Pinq([5, 90, -22, 42, 42])
     assert p.min() == -22
예제 #7
0
 def test_returns_sum_complex(self):
     p = Pinq(self.products)
     assert p.select(p.attr('price')).sum() == 113
예제 #8
0
 def test_returns_sum(self):
     p = Pinq(range(100))
     assert p.sum() == 4950
예제 #9
0
 def test_returns_set_of_items_complex(self):
     p = Pinq(self.products)
     assert p.select(p.attr('category')).to_set() == {2, 4}
예제 #10
0
 def test_returns_set_of_items(self):
     p = Pinq([1, 1, 2, 3, 5, 8, 13, 21, 34, 55])
     assert p.to_set() == {1, 2, 3, 5, 8, 13, 21, 34, 55}
예제 #11
0
 def test_multi_filter(self):
     assert (Pinq(self.products).where(lambda p: p.category == 2).where(
         lambda p: p.price > 50).select(lambda p: p.id).to_list()) == [2]
예제 #12
0
 def test_filter_is_applied(self):
     assert (Pinq(self.products).where(lambda p: p.category == 2).select(
         lambda p: p.id).to_list()) == [1, 2]
예제 #13
0
    def test_multi_select(self):
        p = Pinq(self.products)
        expected = ["13.0", "99.99", "0.01"]

        assert p.select(p.attr('price')).select(str).to_list() == expected
예제 #14
0
 def test_values_returned_are_from_select_clause(self):
     p = Pinq(self.products)
     assert p.select(p.attr('id')).to_list() == [1, 2, 3]