Beispiel #1
0
    def test_07(self):
        logger = FoxylibLogger.func_level2logger(self.test_07, logging.DEBUG)

        produced = []
        consumed = []

        producer_list = [partial(P2C.producer, produced) for _ in range(5)]
        piper_batch_list_1 = [FunctionTool.func2batch(P2C.piper) for _ in range(7)]
        piper_batch_list_2 = [FunctionTool.func2batch(P2C.piper) for _ in range(1)]
        piper_batch_list_3 = [FunctionTool.func2batch(P2C.piper) for _ in range(4)]
        consumer_batch_list = [FunctionTool.func2batch(partial(P2C.consumer, consumed)) for x in range(10)]
        batches_list = [producer_list,
                        piper_batch_list_1,
                        piper_batch_list_2,
                        piper_batch_list_3,
                        consumer_batch_list,
                        ]
        config_list = [None,
                       AioPipeline.Config(dequeue_chunksize=4, dequeue_timeout=1.0),
                       None,
                       AioPipeline.Config(dequeue_chunksize=5, dequeue_timeout=1.0),
                       ]

        pipeline_coro = AioPipeline.batches_list2pipelined(batches_list, config_list=config_list)
        AioTool.awaitable2result(pipeline_coro)

        self.assertEqual(len(produced), len(consumed))
        self.assertEqual(sorted(produced), sorted(consumed))
Beispiel #2
0
 def method2hideout(cls, owner, method):
     """
     owner needs to be passed because classmethod has no "__self__" before decorator
     """
     dict_method2hideout = AttributeTool.get_or_init(
         owner, CacheManager.Constant.ATTRIBUTE_NAME, {})
     hideout = DictTool.get_or_init(dict_method2hideout,
                                    FunctionTool.func2name(method), {})
     return hideout
Beispiel #3
0
 def rootname_func2name(cls, rootname, func):
     return ".".join(
         list(
             chain([rootname],
                   FunctionTool.func2class_func_name_list(func))))
Beispiel #4
0
            for k, v_IN in x.items():
                if kv2is_uuid(k, v_IN):
                    v_OUT = uuid_converter(v_IN)
                else:
                    v_OUT = cls._collection2convert_uuid(
                        v_IN, kv2is_uuid, uuid_converter)
                h[k] = v_OUT
            return h

        return x

    @classmethod
    def h2j(cls, h, kv2is_uuid):
        return cls._collection2convert_uuid(
            h,
            kv2is_uuid,
            cls.x2hex,
        )

    @classmethod
    def j2h(cls, j, kv2is_uuid):
        return cls._collection2convert_uuid(
            j,
            kv2is_uuid,
            cls.x2uuid,
        )


uuid_in = UUIDTool.contained_by
uuid_not_in = FunctionTool.wrap2negate(uuid_in)
Beispiel #5
0
 def key4objectmethod(cls, key):
     return FunctionTool.shift_args(key, 1)
Beispiel #6
0
 def key4classmethod(cls, key):
     return FunctionTool.shift_args(key, 1)
Beispiel #7
0
 def args_kwargs2k_list(_key, _indexes_each, _args, _kwargs):
     _args_list = FunctionTool.args2split(_args, _indexes_each)
     return [key(*_args_each, **_kwargs) for _args_each in _args_list]
Beispiel #8
0
 def _func2key(cls, f):
     return FunctionTool.func2module_qualname(f)
Beispiel #9
0
 def owner_function2method(cls, owner, function):
     return getattr(owner, FunctionTool.func2name(function))
Beispiel #10
0
 def func2endpoint(cls, func):
     return FunctionTool.func2fullpath(func)
Beispiel #11
0
    def test_05(self):
        hyp = FunctionTool.func2module_qualname(self.Test05.A.subtest_05)
        ref = ('foxylib.tools.function.tests.test_function_tool', 'TestFunctionTool.Test05.A.subtest_05')

        # pprint(hyp)
        self.assertEqual(hyp, ref)
Beispiel #12
0
 def test_03(self):
     f = lambda x,y:x+y
     self.assertEqual(FunctionTool.f_args2f_tuple(f)((2,3)), 5)
Beispiel #13
0
 def test_02(self):
     self.assertEqual(FunctionTool.xf2y(3, lambda x:x+1), 4)
Beispiel #14
0
    def test_01(self):
        def f1():
            return 1

        self.assertEqual(FunctionTool.shift_args(f1, 1)("a"), 1)