Exemplo n.º 1
0
 def test_first_predicate_not_callable(self):
     a = [37, 54, 57, 23, 12]
     self.assertRaises(TypeError,
                       lambda: Queryable(a).first("not callable"))
Exemplo n.º 2
0
 def test_log_label_eager(self):
     a = [1, 6, 4, 3, 9, 2]
     logger = Logger()
     b = Queryable(a).log(logger, label="Test2", eager=True).to_list()
     for line in logger.log:
         self.assertTrue(line.startswith("Test2"))
Exemplo n.º 3
0
 def test_union_disjoint(self):
     a = [1, 2, 3, 4, 5]
     b = [6, 7, 8, 9, 10]
     c = Queryable(a).union(b).to_list()
     d = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
     self.assertEqual(c, d)
Exemplo n.º 4
0
 def test_to_str(self):
     a = "This is a string"
     b = str(Queryable(a))
     self.assertEqual(a, b)
Exemplo n.º 5
0
 def test_log_default(self):
     a = [1, 6, 4, 3, 9, 2]
     b = Queryable(a).log().to_list()
     self.assertEqual(a, b)
Exemplo n.º 6
0
 def test_to_str_from_sequence(self):
     a = ["This ", "is ", "a ", "string!"]
     b = "This is a string!"
     c = str(Queryable(a))
     self.assertEqual(b, c)
Exemplo n.º 7
0
 def test_stringify_items(self):
     a = [1, 5, 9, 34, 12, 3, 67, 1, 0]
     b = str(Queryable(a))
     c = "159341236710"
     self.assertEqual(b, c)
Exemplo n.º 8
0
 def test_reverse(self):
     a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
     b = Queryable(a).reverse().to_list()
     c = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
     self.assertEqual(b, c)
Exemplo n.º 9
0
 def test_count_finite_collection(self):
     a = [1, 2, 3]
     b = Queryable(a).count()
     self.assertEqual(b, 3)
Exemplo n.º 10
0
 def test_reverse_closed(self):
     b = Queryable([1, 2, 4, 8])
     b.close()
     self.assertRaises(ValueError, lambda: b.reverse())
Exemplo n.º 11
0
 def test_reverse_empty(self):
     a = []
     b = Queryable(a).reverse().to_list()
     c = []
     self.assertEqual(a, c)
Exemplo n.º 12
0
 def test_reverse_non_sequence(self):
     a = infinite()
     b = Queryable(a).take(10).reverse().to_list()
     c = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
     self.assertEqual(b, c)
Exemplo n.º 13
0
 def test_first(self):
     a = [42, 45, 23, 12]
     b = Queryable(a).first()
     self.assertEqual(b, 42)
Exemplo n.º 14
0
 def test_first_predicate_infinite(self):
     a = infinite()
     b = Queryable(a).first(lambda x: x >= 50)
     self.assertEqual(b, 50)
Exemplo n.º 15
0
 def test_to_unicode_from_empty_sequence(self):
     a = []
     b = u("")
     c = unicode(Queryable(a))
     self.assertEqual(b, c)
Exemplo n.º 16
0
 def test_count_predicate(self):
     a = [1, 78, 45, 34, 98, 54, 53]
     b = Queryable(a).count(lambda x: x > 50)
     self.assertEqual(b, 4)
Exemplo n.º 17
0
 def test_non_iterable(self):
     self.assertRaises(TypeError, lambda: Queryable(5))
Exemplo n.º 18
0
 def test_count_predicate_non_callable(self):
     a = [1, 78, 45, 34, 98, 54, 53]
     self.assertRaises(TypeError,
                       lambda: Queryable(a).count("not callable"))
Exemplo n.º 19
0
 def test_to_str_from_empty_sequence(self):
     a = []
     b = ""
     c = str(Queryable(a))
     self.assertEqual(b, c)
Exemplo n.º 20
0
 def test_count_closed(self):
     b = Queryable([1])
     b.close()
     self.assertRaises(ValueError, lambda: b.count())
Exemplo n.º 21
0
 def test_to_str_closed(self):
     a = ['Aardvark', 'Balloon', 'Carrot', 'Daisy', 'Ecological']
     b = Queryable(a)
     b.close()
     self.assertRaises(ValueError, lambda: str(b))
Exemplo n.º 22
0
 def test_count_empty_collection(self):
     b = Queryable([]).count()
     self.assertEqual(b, 0)
Exemplo n.º 23
0
 def test_log_closed(self):
     a = [1, 6, 4, 3, 9, 2]
     b = Queryable(a)
     b.close()
     self.assertRaises(ValueError, lambda: b.log())
Exemplo n.º 24
0
 def test_to_lookup_value_selector_not_callable(self):
     a = ['Aardvark', 'Balloon', 'Carrot', 'Daisy', 'Ecological']
     self.assertRaises(
         TypeError,
         lambda: Queryable(a).to_lookup(value_selector="not callable"))
Exemplo n.º 25
0
 def test_log_disable(self):
     a = [1, 6, 4, 3, 9, 2]
     b = Queryable(a).log(logger=None).to_list()
     self.assertEqual(a, b)
Exemplo n.º 26
0
 def test_to_unicode(self):
     a = u("This is a string")
     b = unicode(Queryable(a))
     self.assertEqual(a, b)
Exemplo n.º 27
0
 def test_union_non_iterable(self):
     a = [1, 2, 3, 4, 5, 6, 7, 8]
     b = None
     self.assertRaises(TypeError, lambda: Queryable(a).union(b))
Exemplo n.º 28
0
 def test_to_unicode_from_sequence(self):
     a = [u("This "), u("is "), u("a "), u("string!")]
     b = u("This is a string!")
     c = unicode(Queryable(a))
     self.assertEqual(b, c)
Exemplo n.º 29
0
 def test_union_selector(self):
     a = [1, 2, 3, 4, -5, 6, 7, -8]
     b = [-2, -4, 5, -9]
     c = Queryable(a).union(b, abs).to_list()
     d = [1, 2, 3, 4, -5, 6 , 7, -8, -9]
     self.assertEqual(c, d)
Exemplo n.º 30
0
 def test_first_predicate_missing(self):
     a = [37, 42, 23, 12]
     self.assertRaises(ValueError,
                       lambda: Queryable(a).first(lambda x: x >= 50))