def test_chain(self):
        with self.subTest("Test chain function with two lists"):
            iter_1 = [1, 2, 3]
            iter_2 = "abcd"
            result = list(generators.chain(iter_1, iter_2))
            self.assertEqual(result, [1, 2, 3, "a", "b", "c", "d"])

        with self.subTest("Test chain function with emty list"):
            iter_1 = []
            iter_2 = iter_1
            self.assertEqual(list(generators.chain(iter_1, iter_2)), [])
예제 #2
0
파일: __init__.py 프로젝트: fcarena/graphdb
 def __getattribute__(self, key):
     if key in VList._slots:
         return object.__getattribute__(self, key)
     else:
         # run the attribute query on all elements in self
         g = lambda: gen.chain((fv for fv in getattr(v, key)) for v in self)
         return VList(g())
예제 #3
0
    def sets():
        strategies = easy_street.strings(), easy_street.ints(
        ), easy_street.floats(), easy_street.bools()
        strategies = list(
            gen.chain(product(strategies, repeat=len(strategies))))
        lengths = cycle(list(range(0, 21)))

        for _ in gen.loop():
            for length in lengths:
                for strat in strategies:
                    yield {i for i in islice(strat, length)}
예제 #4
0
    def dicts():
        strategies = easy_street.strings(), easy_street.ints(
        ), easy_street.floats(), easy_street.bools()
        strategies = list(
            gen.chain(product(strategies, repeat=len(strategies))))
        lengths = cycle(list(range(1, 21)))

        for _ in gen.loop():
            for length in lengths:
                for strat in strategies:
                    yield {
                        k: v
                        for k, v in gen.chunks(islice(strat, length * 2), 2)
                    }
예제 #5
0
 def garbage():
     strategies = [
         easy_street.strings(),
         easy_street.ints(),
         easy_street.floats(),
         easy_street.bools(),
         easy_street.dicts(),
         easy_street.sets(),
         easy_street.lists(),
         easy_street.tuples()
     ]
     while 1:
         shuffle(strategies)
         for strat in gen.chain(product(strategies,
                                        repeat=len(strategies))):
             yield next(strat)
예제 #6
0
 def test_whether_in_chain_list_and_set_arguments_are_given_and_return_value_is_converted_in_list(
         self):
     list_result = list(generators.chain([1, 2, 3], {3, 2}))
     expected_result = [1, 2, 3, 2, 3]
     self.assertEqual(list_result, expected_result)
예제 #7
0
 def test_wheter_in_chain_two_sets_are_given_and_return_value_is_converted_in_set(
         self):
     set_result = set(generators.chain({1, 2, 3}, {3, 2, 'i'}))
     expected_result = {1, 2, 3, 'i'}
     self.assertEqual(set_result, expected_result)
예제 #8
0
 def test_chain(self):
     res = list(chain(range(0, 4), range(4, 8)))
     expected = [0, 1, 2, 3, 4, 5, 6, 7]
     self.assertEqual(res, expected)
예제 #9
0
    for i in range(1, 5):
        print(i)
        db[5].greater_than = i

    print(db[5].greater_than.to(list))

    db.show_objects()
    db.show_relations()
    print(list(db.relations_of(5)))

    print()

    print(
        list(
            gen.chain(((r, i.obj) for i in db.find(5, r))
                      for r in db.relations_of(5))))

    for r in db.relations_of(5):
        print(r)
        print([i.obj for i in db.find(5, r)])

    print(db(5).greater_than(list))
    print(db(5).greater_than.where(lambda i: i % 2 == 0)(list))
    print(db(5).greater_than.precedes(list))
    print(
        db(5).greater_than.precedes.precedes.precedes.precedes.precedes.
        precedes(list))

    print(db(5).greater_than.where('even', lambda i: i == True)(list))
    print(db(5).greater_than.where('even', bool)(list))
예제 #10
0
 def test_chain_when_two_ranges_are_passed_then_returns_another_one_that_concatenate_the_two_iterables(self):
     expr1 = range(0,4)
     expr2 = range(4, 8)
     expected_result = [0, 1, 2, 3, 4, 5, 6, 7]
     self.assertEqual(list(generators.chain(expr1, expr2)), expected_result)
예제 #11
0
 def test_if_iterables_are_passed_to_chain_list_of_both_is_returned(self):
     expected_result = [0, 1, 2, 3, 4, 5, 6, 7]
     actual_result = list(chain(range(0, 4), range(4, 8)))
     self.assertEqual(expected_result, actual_result)
예제 #12
0
 def test_when_one_iterable_is_list_and_other_is_set(self):
     chained = list(chain([1, 3, 3], {2, 3, 1}))
     expected_result = [1, 3, 3, 1, 2, 3]
     self.assertEqual(chained, expected_result)
예제 #13
0
 def floats():
     non_zero_ints = (i for i in easy_street.ints() if i != 0)
     stream1 = gen.chain(i[:8] for i in gen.chunks(non_zero_ints, 10))
     stream2 = gen.chain(i[:8] for i in gen.chunks(non_zero_ints, 12))
     for i in stream1:
         yield next(stream2) / (1.0 * i)
예제 #14
0
    def test_chain_chains_two_different_types(self):
        testgenerator = chain(range(0, 6), [6, 7, 8, 9, 10])
        result = list(testgenerator)
        expected = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

        self.assertEqual(result, expected)
예제 #15
0
 def test_chain(self):
     expected = [0, 1, 2, 3, 4, 5, 6, 7]
     actual = list(chain(range(0, 4), range(4, 8)))
     self.assertEqual(actual, expected)
예제 #16
0
 def test_if_when_sets_are_passed_list_of_both_is_returned(self):
     expected_result = [1, 2, 3, 3, 4, 5]
     actual_result = list(chain({1, 2, 3}, {3, 4, 5}))
     self.assertEqual(expected_result, actual_result)
예제 #17
0
 def test_if_when_list_and_set_are_passed_list_of_both_is_returned(self):
     expected_result = [1, 2, 3, 3, 4, 5, 6]
     actual_result = list(chain([1, 2, 3], {3, 4, 5, 6}))
     self.assertEqual(expected_result, actual_result)
예제 #18
0
 def test_when_both_iterables_are_sets(self):
     chained = list(chain({1, 3, 4}, {2, 5, 6}))
     expected_result = [1, 3, 4, 2, 5, 6]
     self.assertEqual(chained, expected_result)
예제 #19
0
파일: __init__.py 프로젝트: fcarena/graphdb
 def connections_of(self, target):
     ''' generate tuples containing (relation, object_that_applies) '''
     return gen.chain(((r, i) for i in self.find(target, r))
                      for r in self.relations_of(target))
예제 #20
0
 def test_when_both_iterables_are_range(self):
     chained = list(chain(range(0, 4), range(4, 8)))
     expected_result = [0, 1, 2, 3, 4, 5, 6, 7]
     self.assertEqual(chained, expected_result)
예제 #21
0
파일: __init__.py 프로젝트: fcarena/graphdb
def run_tests():
    ''' use this function to ensure everything is working correctly with graphdb '''
    db = GraphDB()

    for i in range(1, 10):
        src, dst = (i - 1, i)
        #print(db._id_of(i))
        print('testing', (src, 'precedes', dst))
        db.store_relation(src, 'precedes', dst)
        db.store_relation(src, 'even', (not src % 2))
        db(src).odd = bool(src % 2)

    print(6 in db)  # search the db to see if youve already stored something

    #db.show_objects()
    #db.show_relations()

    for i in range(5):
        for ii in db.find(i, 'precedes'):
            print(i, ii)

    print(list(db.relations_of(7)))
    print(list(db[6].precedes()))
    print(db[6].precedes.even.to(list))
    print(list(db[6].precedes.even()))
    print(db[6].precedes.precedes.to(list))
    print(db[6].precedes.precedes.even.to(list))

    seven = db[6].precedes
    print(seven)
    print(seven.to(list))
    print('setting an attribute')

    db.show_objects()
    db.show_relations()
    seven.prime = True
    print(db[5].precedes.precedes.prime.to(list))
    print(db._id_of(99))

    for i in range(1, 5):
        print(i)
        db[5].greater_than = i

    print(db[5].greater_than.to(list))

    #db.show_objects()
    #db.show_relations()
    print(list(db.relations_of(5)))

    print()

    print(
        list(
            gen.chain(
                ((r, i) for i in db.find(5, r)) for r in db.relations_of(5))))

    for r in db.relations_of(5):
        print(r)
        print(list(db.find(5, r)))

    print(db(5).greater_than(list))
    print(db(5).greater_than.where(lambda i: i % 2 == 0)(list))
    print(db(5).greater_than.precedes(list))
    print(
        db(5).greater_than.precedes.precedes.precedes.precedes.precedes.
        precedes(list))

    print(db(5).greater_than.where('even', lambda i: i == True)(list))
    print(db(5).greater_than.where('even', bool)(list))

    db.delete_relation(5, 'greater_than', 2)
    db.delete_relation(5, 'greater_than', 2)
    db.delete_relation(5, 'greater_than', 3)

    db.show_relations()
    print('-')
    print(list(db.relations_of(5)))
    print('-')
    print(list(db.relations_of(5, True)))
    print('-')
    print(list(db.relations_to(5)))
    print('-')
    print(list(db.relations_to(5, True)))

    db.replace_item(5, 'waffles')
    db.delete_item(6)
    db.show_relations()

    for i in db:
        print(i)

    for i in db.list_relations():
        print(i)

    db._destroy()
예제 #22
0
 def test_chain_when_two_sets_are_passed_then_returns_another_one_that_concatenate_the_two_iterables(self):
     expr1 = {1,2,3,4}
     expr2 = {1,7,8}
     expected_result = [1, 2, 3, 4, 1, 7, 8]
     self.assertEqual(list(generators.chain(expr1, expr2)).sort(), expected_result.sort())