Exemplo n.º 1
0
 def test_skip_is_deferred(self):
     a = TracingGenerator()
     self.assertEqual(a.trace, [])
     b = Queryable(a).skip(3)
     self.assertEqual(a.trace, [])
     c = b.take().to_list()
     self.assertEqual(a.trace, [0, 1, 2, 3])
 def test_select_with_corresponding_deferred(self):
     a = TracingGenerator()
     self.assertListEqual(a.trace, [])
     b = Queryable(a).select_with_correspondence(lambda x: x * 2)
     self.assertListEqual(a.trace, [])
     b.take(3).to_list()
     self.assertListEqual(a.trace, list(range(3)))
Exemplo n.º 3
0
 def test_group_join_is_deferred(self):
     a = TracingGenerator()
     self.assertEqual(a.trace, [])
     b = [2, 3, 4, 5, 6]
     c = Queryable(a).group_join(b)
     self.assertEqual(a.trace, [])
     d = c.take(3).to_list()
Exemplo n.º 4
0
 def test_select_with_index_deferred(self):
     a = TracingGenerator()
     self.assertEqual(a.trace, [])
     b = Queryable(a).select_with_index()
     self.assertEqual(a.trace, [])
     b.take(3).to_list()
     self.assertEqual(a.trace, [0, 1, 2])
 def test_select_many_with_index_closed(self):
     a = [{'name' : 'Alice', 'flowers' : ['Agapanthus', 'Allium', 'Alpina', 'Alstroemeria', 'Amaranthus', 'Amarylis' ] },
          {'name' : 'Bob',   'flowers' : ['Bouvardia' ]},
          {'name' : 'Chris', 'flowers' : ['Carnations', 'Cattleya', 'Celosia', 'Chincherinchee', 'Chrysanthemum']}]
     b = Queryable(a)
     b.close()
     self.assertRaises(ValueError, lambda: b.select_many_with_index(lambda i, x: [str(i) + flower for flower in x['flowers']]))
 def test_select_many_with_index_deferred(self):
     a = TracingGenerator()
     self.assertEqual(a.trace, [])
     b = Queryable(a).select_many_with_index(lambda index, source_element: [source_element] * index)
     self.assertEqual(a.trace, [])
     b.take(10).to_list()
     self.assertEqual(a.trace, [0, 1, 2, 3, 4])
Exemplo n.º 7
0
 def test_select_deferred(self):
     a = TracingGenerator()
     self.assertEqual(a.trace, [])
     b = Queryable(a).select(lambda x: x*2)
     self.assertEqual(a.trace, [])
     c = b.take(3).to_list()
     self.assertEqual(a.trace, [0, 1, 2])
Exemplo n.º 8
0
 def test_take_is_deferred(self):
     a = TracingGenerator()
     self.assertEqual(a.trace, [])
     b = Queryable(a).take()
     self.assertEqual(a.trace, [])
     c = b.to_list()
     self.assertEqual(a.trace, [0])
Exemplo n.º 9
0
 def test_where_deferred(self):
     a = TracingGenerator()
     self.assertEqual(a.trace, [])
     b = Queryable(a).where(lambda x: x % 3 == 0)
     self.assertEqual(a.trace, [])
     c = b.take(2).to_list()
     self.assertEqual(a.trace, [0, 1, 2, 3])
Exemplo n.º 10
0
 def test_default_if_empty_is_deferred_not_empty(self):
     a = TracingGenerator()
     self.assertEqual(a.trace, [])
     b = Queryable(a).default_if_empty(42)
     self.assertEqual(a.trace, [])
     c = b.take(3).to_list()
     self.assertEqual(a.trace, [0, 1, 2])
Exemplo n.º 11
0
 def test_select_many_deferred(self):
     a = TracingGenerator()
     self.assertEqual(a.trace, [])
     b = Queryable(a).select_many(lambda x: [x] * x)
     self.assertEqual(a.trace, [])
     b.take(10).to_list()
     self.assertEqual(a.trace, [0, 1, 2, 3, 4])
Exemplo n.º 12
0
 def test_join_is_deferred(self):
     a = TracingGenerator()
     self.assertEqual(a.trace, [])
     b = [2, 3, 4, 5, 6]
     c = Queryable(a).join(b)
     self.assertEqual(a.trace, [])
     d = c.take(3).to_list()
     e = [(2, 2), (3, 3), (4, 4)]
     self.assertEqual(d, e)
Exemplo n.º 13
0
 def test_difference_deferred(self):
     a = TracingGenerator()
     self.assertEqual(a.trace, [])
     b = [3, 7, 2, 9, 10]
     c = Queryable(a).difference(b)
     self.assertEqual(a.trace, [])
     d = c.take(10).to_list()
     e = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
     self.assertEqual(a.trace, e)
Exemplo n.º 14
0
 def test_union_deferred(self):
     a = TracingGenerator()
     self.assertEqual(a.trace, [])
     b = [3, 7, 2, 9, 10]
     c = Queryable(a).union(b)
     self.assertEqual(a.trace, [])
     d = c.take(5).to_list()
     e = [0, 1, 2, 3, 4]
     self.assertEqual(a.trace, e)
Exemplo n.º 15
0
 def test_intersect_deferred(self):
     a = TracingGenerator()
     self.assertEqual(a.trace, [])
     b = [3, 7, 2, 9, 10]
     c = Queryable(a).intersect(b)
     self.assertEqual(a.trace, [])
     d = c.take(5).to_list()
     e = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
     self.assertEqual(a.trace, e)
Exemplo n.º 16
0
 def test_take_while_is_deferred(self):
     a = TracingGenerator()
     self.assertEqual(a.trace, [])
     b = Queryable(a).take_while(lambda x: x < 3)
     self.assertEqual(a.trace, [])
     c = b.to_list()
     # 3 is included here in the trace because it must have been consumed in order to test
     # whether it satisfies the predicate
     self.assertEqual(a.trace, [0, 1, 2, 3])
Exemplo n.º 17
0
 def test_zip_deferred(self):
     a = TracingGenerator()
     self.assertEqual(a.trace, [])
     b = TracingGenerator()
     self.assertEqual(b.trace, [])
     c = Queryable(a).zip(b)
     self.assertEqual(a.trace, [])
     self.assertEqual(b.trace, [])
     d = c.take(4).to_list()
     self.assertEqual(d, [(0, 0), (1, 1), (2, 2), (3, 3)])
Exemplo n.º 18
0
 def test_min_selector_not_callable(self):
     a = [5, 7, -3, 2, 1, 9, 3, 2, 1, -13, 7]
     self.assertRaises(TypeError, lambda: Queryable(a).min("not callable"))
Exemplo n.º 19
0
 def test_single_or_default_predicate_not_callable(self):
     a = ["Aardvark", "Cat", "Elephant"]
     self.assertRaises(TypeError, lambda: Queryable(a).single_or_default('Animal', "not callable"))
Exemplo n.º 20
0
 def test_min_closed(self):
     b = Queryable([1])
     b.close()
     self.assertRaises(ValueError, lambda: b.min())
Exemplo n.º 21
0
 def test_aggregate_closed(self):
     b = Queryable([])
     b.close()
     self.assertRaises(ValueError, lambda: b.aggregate(operator.add, 72))
Exemplo n.º 22
0
 def test_zip_non_iterable(self):
     a = [1, 2, 3]
     b = 5
     self.assertRaises(TypeError, lambda: Queryable(a).zip(b))
Exemplo n.º 23
0
 def test_zip_longer_shorter(self):
     a = [1, 2, 3]
     b = [4, 5]
     c = Queryable(a).zip(b).to_list()
     self.assertEqual(c, [(1, 4), (2, 5)])
Exemplo n.º 24
0
 def test_last_closed(self):
     b = Queryable([])
     b.close()
     self.assertRaises(ValueError, lambda: b.last())
Exemplo n.º 25
0
 def test_single_or_default_empty(self):
     a = []
     b = Queryable(a).single_or_default(7)
     self.assertEqual(b, 7)
Exemplo n.º 26
0
 def test_zip_func(self):
     a = [1, 2, 3]
     b = [4, 5, 6]
     c = Queryable(a).zip(b, lambda x, y: int(str(x) + str(y))).to_list()
     self.assertEqual(c, [(14), (25), (36)])
Exemplo n.º 27
0
 def test_single_or_default(self):
     a = [5]
     b = Queryable(a).single_or_default(7)
     self.assertEqual(b, 5)
Exemplo n.º 28
0
 def test_single_multiple(self):
     a = [4, 7]
     self.assertRaises(ValueError, lambda: Queryable(a).single())
Exemplo n.º 29
0
 def test_single_empty(self):
     a = []
     self.assertRaises(ValueError, lambda: Queryable(a).single())
Exemplo n.º 30
0
 def test_zip(self):
     a = [1, 2, 3]
     b = [4, 5, 6]
     c = Queryable(a).zip(b).to_list()
     self.assertEqual(c, [(1, 4), (2, 5), (3, 6)])
Exemplo n.º 31
0
 def test_single_or_default_predicate_negative(self):
     a = ["Aardvark", "Cat", "Elephant"]
     b = Queryable(a).single_or_default('Animal', lambda x: x.startswith('D'))
     self.assertEqual(b, "Animal")
Exemplo n.º 32
0
 def test_zip_infinite(self):
     c = Queryable(infinite()).zip(infinite()).take(4).to_list()
     self.assertEqual(c, [(0, 0), (1, 1), (2, 2), (3, 3)])
Exemplo n.º 33
0
 def test_single_or_default_multiple(self):
     a = [5, 7, 2, 3, 1]
     self.assertRaises(ValueError, lambda: Queryable(a).single_or_default(13))
Exemplo n.º 34
0
 def test_zip_longer_empty(self):
     a = [1, 2, 3]
     b = []
     c = Queryable(a).zip(b).to_list()
     self.assertEqual(c, [])
Exemplo n.º 35
0
 def test_min(self):
     a = [5, 7, -3, 2, 1, 9, 3, 2, 1, -8, 7]
     b = Queryable(a).min()
     self.assertEqual(b, -8)
Exemplo n.º 36
0
 def test_zip_closed(self):
     a = Queryable([1, 2, 3])
     a.close()
     self.assertRaises(ValueError, lambda: a.zip([4, 5, 6]))
Exemplo n.º 37
0
 def test_select_many_closed(self):
     b = Queryable([1, 2, 4, 8])
     b.close()
     self.assertRaises(ValueError, lambda: b.select_many(lambda x: x * 2))
Exemplo n.º 38
0
 def test_zip_empty_longer(self):
     a = []
     b = [4, 5, 6]
     c = Queryable(a).zip(b).to_list()
     self.assertEqual(c, [])
Exemplo n.º 39
0
 def test_single_or_default_predicate_empty(self):
     a = []
     b = Queryable(a).single_or_default('foo', lambda x: x.startswith('D'))
     self.assertEqual(b, 'foo')
Exemplo n.º 40
0
 def test_first_closed(self):
     a = ['Agapanthus', 'Allium', 'Alpina', 'Alstroemeria', 'Amaranthus', 'Amarylis', 'Bouvardia', 'Carnations',
          'Cattleya', 'Celosia', 'Chincherinchee', 'Chrysanthemum']
     b = Queryable(a)
     b.close()
     self.assertRaises(ValueError, lambda: b.group_by(lambda x: x[0]))
Exemplo n.º 41
0
 def test_single_predicate(self):
     a = ["Aardvark", "Cat", "Dog", "Elephant"]
     b = Queryable(a).single(lambda x: x.startswith('D'))
     self.assertEqual(b, "Dog")
Exemplo n.º 42
0
 def test_zip_not_callable(self):
     a = [1, 2, 3]
     b = [4, 5, 6]
     self.assertRaises(TypeError,
                       lambda: Queryable(a).zip(b, "not callable"))
 def test_first_or_default_closed(self):
     b = Queryable([])
     b.close()
     self.assertRaises(ValueError, lambda: b.first_or_default(37))
Exemplo n.º 44
0
 def test_single_predicate_not_callable(self):
     a = ["Aardvark", "Cat", "Dog", "Elephant"]
     self.assertRaises(TypeError,
                       lambda: Queryable(a).single("not callable"))
Exemplo n.º 45
0
 def test_select_with_index_closed(self):
     a = [27, 74, 18, 48, 57, 97, 76, 20, 91, 8, 80, 59, 20, 32, 58, 12, 74, 78, 4]
     b = Queryable(a)
     b.close()
     self.assertRaises(ValueError, lambda: b.select_with_index(lambda x, y: x*y))
Exemplo n.º 46
0
 def test_single_predicate_empty(self):
     a = []
     self.assertRaises(
         ValueError,
         lambda: Queryable(a).single(lambda x: x.startswith('D')))
Exemplo n.º 47
0
 def test_single_predicate_multiple(self):
     a = ["Aardvark", "Cat", "Dog", "Elephant", "Dolphin"]
     self.assertRaises(
         ValueError,
         lambda: Queryable(a).single(lambda x: x.startswith('D')))
Exemplo n.º 48
0
 def test_single_closed(self):
     a = [5]
     b = Queryable(a)
     b.close()
     self.assertRaises(ValueError, lambda: b.single())
Exemplo n.º 49
0
 def test_to_str_closed(self):
     a = ['Aardvark', 'Balloon', 'Carrot', 'Daisy', 'Ecological']
     b = Queryable(a)
     b.close()
     self.assertRaises(ValueError, lambda: b.to_str())
Exemplo n.º 50
0
 def test_skip_closed(self):
     a = ['a', 'b', 'c']
     b = Queryable(a)
     b.close()
     self.assertRaises(ValueError, lambda: b.skip(1))
Exemplo n.º 51
0
 def test_group_join_closed(self):
     a = [1, 2]
     b = [2, 3]
     c = Queryable(a)
     c.close()
     self.assertRaises(ValueError, lambda: c.group_join(b))
Exemplo n.º 52
0
 def test_contains_closed(self):
     b = Queryable([1])
     b.close()
     self.assertRaises(ValueError, lambda: b.contains(5))
Exemplo n.º 53
0
 def test_single(self):
     a = [5]
     b = Queryable(a).single()
     self.assertEqual(b, 5)
Exemplo n.º 54
0
 def test_min_empty(self):
     self.assertRaises(ValueError, lambda: Queryable([]).min())
Exemplo n.º 55
0
 def test_getitem_closed(self):
     b = Queryable([1])
     b.close()
     self.assertRaises(ValueError, lambda: b[0])
Exemplo n.º 56
0
 def test_group_join_non_iterable(self):
     a = [1, 2, 3]
     b = None
     self.assertRaises(TypeError, lambda: Queryable(a).group_join(b))
Exemplo n.º 57
0
 def test_single_closed(self):
     a = [5]
     b = Queryable(a)
     b.close()
     self.assertRaises(ValueError, lambda: b.single())
Exemplo n.º 58
0
 def test_group_join_closed(self):
     a = [1, 2]
     b = [2, 3]
     c = Queryable(a)
     c.close()
     self.assertRaises(ValueError, lambda: c.group_join(b))
Exemplo n.º 59
0
 def test_any_closed(self):
     b = Queryable([1])
     b.close()
     self.assertRaises(ValueError, lambda: b.any())
Exemplo n.º 60
0
 def test_min_selector(self):
     a = [5, 7, -3, 2, 1, 9, 3, 2, 1, -8, 7]
     b = Queryable(a).min(abs)
     self.assertEqual(b, 1)