def processFunction( func_node, in_class=False ): fixIndents( func_node ) func_gath = FunctionConverter( in_class ) func_matches = func_gath.gather( func_node ) func_gath.processAll( func_matches ) gath_classes = [ AssignmentConverter, BoolOpsConverter, ComparisonConverter, DecoratorConverter, DictComprehensionConverter, ExceptionConverter, ForLoopConverter, IfElifElseConverter, KeyWordCallConverter, ListComprehensionConverter, ListSliceConverter, NegateConverter, SelfConverter, StringInterpolationConverter, SuperConverter, TryExceptConverter, TupleConverter, WhileLoopConverter, ] ConverterChain( gath_classes ).convertAll( func_node ) fixComments( func_node ) fixPassStatements( func_node ) fixSemicolons( func_node ) fixSimpleRenames( func_node )
def test_TryExceptProcess_04(): src = """ if 1: if 1: if 1: try: bim() except IndexError as exy: bam() raise """ nodes = parseSource(src) fixIndents(nodes) cvtr = TryExceptConverter() matches = cvtr.gather(nodes) cvtr.processAll(matches) # dumpTree( nodes ) # dumpNodes( nodes ) assert nodesToLines(nodes) == [ "if 1:", " if 1:", " if 1:", " try {", " bim()", " } catch( exy ) /* IndexError */ {", " bam()", " raise", " }", ]
def test_ForLoopProcess_01(): src = """ for x in y: doit( x ) """ nodes = parseSource(src) fixIndents(nodes) cvtr = ForLoopConverter() matches = cvtr.gather(nodes) cvtr.processAll(matches) # dumpTree( nodes ) # dumpNodes( nodes ) assert nodesToString(nodes) == """for( let x of y ) {
def test_ForLoopProcess_03(): src = """ for x in c1: for y in c2: for z in c3: doit( x, y, z ) """ nodes = parseSource(src) fixIndents(nodes) cvtr = ForLoopConverter() matches = cvtr.gather(nodes) cvtr.processAll(matches) # dumpTree( nodes ) # dumpNodes( nodes ) assert nodesToString(nodes) == """for( let x of c1 ) {
def test_ForLoopProcess_02(): src = """ if 1: for idx, x in enumerate( zip( l1, l2 ) ): doit( x ) return 123 """ nodes = parseSource(src) fixIndents(nodes) cvtr = ForLoopConverter() matches = cvtr.gather(nodes) cvtr.processAll(matches) # dumpTree( nodes ) # dumpLines( nodesToString( nodes ) ) assert nodesToString(nodes) == """if 1:
def test_WhileLoopProcess_01(): src = """ if 1: while self.hasDUnit( name ): name = makeAutoDUnitName() return something """ nodes = parseSource(src) fixIndents(nodes) cvtr = WhileLoopConverter() matches = cvtr.gather(nodes) cvtr.processAll(matches) # dumpTree( nodes ) # dumpNodes( nodes ) assert nodesToString(nodes) == """if 1:
def test_ForLoopProcess_04(): src = """ for ( x, y ) in y: doit( x, y ) """ nodes = parseSource(src) fixIndents(nodes) cvtr = ForLoopConverter() matches = cvtr.gather(nodes) cvtr.processAll(matches) # dumpTree( nodes ) # dumpLines( nodesToString( nodes ) ) assert nodesToLines(nodes) == [ 'for( let [ x, y ] of y ) {', ' doit( x, y )', '}', ]