def test_can_compose_process(self): def mut_fn_fail(e, m) -> Element: raise Exception("Oops!") def mut_fn(e, m) -> Element: return e def trans_fn(i, o, m) -> list: return [] def trans_fn_fail(i, o, m) -> list: raise Exception("Oops!") result = Process(selector=Selector(chains=[ AllChain(ordered_events=[ Selector(chains=[ AllChain(ordered_events=[ Mutable(fn=mut_fn), Transformer(fn=trans_fn), ], ), AllChain( ordered_events=[ Mutable(fn=mut_fn_fail), ], tag=0, ), ], ) ]), AllChain( ordered_events=[ Selector(chains=[ AnyChain(ordered_events=[ Transformer(fn=trans_fn_fail), Transformer(fn=trans_fn), ]) ]) ], tag=99, ) ])).run(elements=[ Element( input={}, tag=99, ), Element( input={}, tag=0, # Should fail ), Element(input={}, ), ]) self.assertEqual(len(result.outputs(filter=lambda x: x is None)), 1) self.assertEqual(len(result.outputs(filter=lambda x: x is not None)), 2)
def test_special_case_two(self): fake_logger = FakeLogger() elements = self.helper_get_elements() if elements: pre_result = Process( selector=Selector( chains=[ AllChain( ordered_events=[ Mutable( fn=mute_price_rule_components_to_strings, ), Transformer( fn=transform_price_rule_to_constraints, ), Mutable(fn=mute_set_id, ) ], id="price-rule-conv-chain", ) ], logger=fake_logger, ), meta=ConfigGeneralMeta, ).run(elements=elements, ) self.assertEqual(len(pre_result.notices), 0) post_process = Process( selector=Selector(chains=[ AllChain(ordered_events=[ Transformer(fn=transform_package_price, ) ]) ]), meta=PreProcessMeta(config_rules={'X': [ "Y", "Z", ]}, prices=pre_result.outputs( filter=lambda x: x is not None, )), ).run(pre_result.filter(fn=lambda x: x.output is None, )) not_none_outputs = post_process.outputs(filter=lambda x: x is None) self.assertGreater(len(not_none_outputs), 0)