Esempio 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"))
Esempio 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"))
Esempio 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)
Esempio n. 4
0
 def test_to_str(self):
     a = "This is a string"
     b = str(Queryable(a))
     self.assertEqual(a, b)
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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)
Esempio n. 9
0
 def test_count_finite_collection(self):
     a = [1, 2, 3]
     b = Queryable(a).count()
     self.assertEqual(b, 3)
Esempio n. 10
0
 def test_reverse_closed(self):
     b = Queryable([1, 2, 4, 8])
     b.close()
     self.assertRaises(ValueError, lambda: b.reverse())
Esempio n. 11
0
 def test_reverse_empty(self):
     a = []
     b = Queryable(a).reverse().to_list()
     c = []
     self.assertEqual(a, c)
Esempio 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)
Esempio n. 13
0
 def test_first(self):
     a = [42, 45, 23, 12]
     b = Queryable(a).first()
     self.assertEqual(b, 42)
Esempio n. 14
0
 def test_first_predicate_infinite(self):
     a = infinite()
     b = Queryable(a).first(lambda x: x >= 50)
     self.assertEqual(b, 50)
Esempio n. 15
0
 def test_to_unicode_from_empty_sequence(self):
     a = []
     b = u("")
     c = unicode(Queryable(a))
     self.assertEqual(b, c)
Esempio 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)
Esempio n. 17
0
 def test_non_iterable(self):
     self.assertRaises(TypeError, lambda: Queryable(5))
Esempio 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"))
Esempio n. 19
0
 def test_to_str_from_empty_sequence(self):
     a = []
     b = ""
     c = str(Queryable(a))
     self.assertEqual(b, c)
Esempio n. 20
0
 def test_count_closed(self):
     b = Queryable([1])
     b.close()
     self.assertRaises(ValueError, lambda: b.count())
Esempio 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))
Esempio n. 22
0
 def test_count_empty_collection(self):
     b = Queryable([]).count()
     self.assertEqual(b, 0)
Esempio 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())
Esempio 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"))
Esempio 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)
Esempio n. 26
0
 def test_to_unicode(self):
     a = u("This is a string")
     b = unicode(Queryable(a))
     self.assertEqual(a, b)
Esempio 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))
Esempio 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)
Esempio 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)
Esempio 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))