def test_first_predicate_not_callable(self): a = [37, 54, 57, 23, 12] self.assertRaises(TypeError, lambda: Queryable(a).first("not callable"))
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"))
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)
def test_to_str(self): a = "This is a string" b = str(Queryable(a)) self.assertEqual(a, b)
def test_log_default(self): a = [1, 6, 4, 3, 9, 2] b = Queryable(a).log().to_list() self.assertEqual(a, b)
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)
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)
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)
def test_count_finite_collection(self): a = [1, 2, 3] b = Queryable(a).count() self.assertEqual(b, 3)
def test_reverse_closed(self): b = Queryable([1, 2, 4, 8]) b.close() self.assertRaises(ValueError, lambda: b.reverse())
def test_reverse_empty(self): a = [] b = Queryable(a).reverse().to_list() c = [] self.assertEqual(a, c)
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)
def test_first(self): a = [42, 45, 23, 12] b = Queryable(a).first() self.assertEqual(b, 42)
def test_first_predicate_infinite(self): a = infinite() b = Queryable(a).first(lambda x: x >= 50) self.assertEqual(b, 50)
def test_to_unicode_from_empty_sequence(self): a = [] b = u("") c = unicode(Queryable(a)) self.assertEqual(b, c)
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)
def test_non_iterable(self): self.assertRaises(TypeError, lambda: Queryable(5))
def test_count_predicate_non_callable(self): a = [1, 78, 45, 34, 98, 54, 53] self.assertRaises(TypeError, lambda: Queryable(a).count("not callable"))
def test_to_str_from_empty_sequence(self): a = [] b = "" c = str(Queryable(a)) self.assertEqual(b, c)
def test_count_closed(self): b = Queryable([1]) b.close() self.assertRaises(ValueError, lambda: b.count())
def test_to_str_closed(self): a = ['Aardvark', 'Balloon', 'Carrot', 'Daisy', 'Ecological'] b = Queryable(a) b.close() self.assertRaises(ValueError, lambda: str(b))
def test_count_empty_collection(self): b = Queryable([]).count() self.assertEqual(b, 0)
def test_log_closed(self): a = [1, 6, 4, 3, 9, 2] b = Queryable(a) b.close() self.assertRaises(ValueError, lambda: b.log())
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"))
def test_log_disable(self): a = [1, 6, 4, 3, 9, 2] b = Queryable(a).log(logger=None).to_list() self.assertEqual(a, b)
def test_to_unicode(self): a = u("This is a string") b = unicode(Queryable(a)) self.assertEqual(a, b)
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))
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)
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)
def test_first_predicate_missing(self): a = [37, 42, 23, 12] self.assertRaises(ValueError, lambda: Queryable(a).first(lambda x: x >= 50))