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]
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
def test_returns_max_complex(self): p = Pinq(self.products) assert p.select(p.attr('price')).max() == 99.99
def test_returns_max(self): p = Pinq([5, 90, -22, 42, 42]) assert p.max() == 90
def test_returns_min_complex(self): p = Pinq(self.products) assert p.select(p.attr('price')).min() == 0.01
def test_returns_min(self): p = Pinq([5, 90, -22, 42, 42]) assert p.min() == -22
def test_returns_sum_complex(self): p = Pinq(self.products) assert p.select(p.attr('price')).sum() == 113
def test_returns_sum(self): p = Pinq(range(100)) assert p.sum() == 4950
def test_returns_set_of_items_complex(self): p = Pinq(self.products) assert p.select(p.attr('category')).to_set() == {2, 4}
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}
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]
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]
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
def test_values_returned_are_from_select_clause(self): p = Pinq(self.products) assert p.select(p.attr('id')).to_list() == [1, 2, 3]