def test_tweak_generator_graph(self): def f(n, x, y, z): z *= 10 yield n + 1 z -= 10 # space = FlowObjSpace() graph = space.build_flow(f, tweak_for_generator=False) GeneratorIterator = make_generatoriterator_class(graph) replace_graph_with_bootstrap(GeneratorIterator, graph) func1 = attach_next_method(GeneratorIterator, graph) if option.view: graph.show() # assert func1._generator_next_method_of_ is GeneratorIterator assert hasattr(GeneratorIterator, 'next') # graph_next = space.build_flow(GeneratorIterator.next.im_func) join_blocks(graph_next) if option.view: graph_next.show() # graph1 = space.build_flow(func1, tweak_for_generator=False) tweak_generator_body_graph(GeneratorIterator.Entry, graph1) if option.view: graph1.show()
def test_tweak_generator_body_graph(self): def f(n, x, y, z=3): z *= 10 yield n + 1 z -= 10 # space = FlowObjSpace() graph = space.build_flow(f, tweak_for_generator=False) class Entry: varnames = ['g_n', 'g_x', 'g_y', 'g_z'] tweak_generator_body_graph(Entry, graph) if option.view: graph.show() # XXX how to test directly that the graph is correct? :-( assert len(graph.startblock.inputargs) == 1 assert graph.signature == Signature(['entry']) assert graph.defaults == ()