def test_processModule_02(): src = """ class Tests( unittest.TestCase ): def test_getAttr( self ): try: getattr( obj, 'bom' ) except: excepted = True assert excepted """ nodes = parseSource(src) infos = processTestModule(nodes) # dumpTree( nodes ) # dumpNodes( nodes ) assert nodesToLines(nodes) == [ "describe( 'Tests', () => {", " it( 'test_getAttr', () => {", " try {", " _pyjs.getAttr( obj, 'bom' );", " } catch( e ) {", " let excepted = true;", " }", "expect( excepted ).to.be.ok;", "", " } );", " } );", ]
def test_TupleGather_03(): src = """ ( a, b, c ) = func( x, y, z ) """ matches = TupleConverter().gather(parseSource(src)) assert matches[0].contents.toString() == "a, b, c" assert len(matches) == 1
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_TupleGather_02(): src = """ l = ( 'a', ( 1, 2, 3 ), 'b' ) """ matches = TupleConverter().gather(parseSource(src)) assert matches[0].contents.toString() == "'a', ( 1, 2, 3 ), 'b'" assert matches[1].contents.toString() == "1, 2, 3"
def test_TryExceptProcess_02(): src = """ try: bim() except ( IndexError, KeyError ): bam() raise finally: bom() return 123 """ nodes = parseSource(src) cvtr = TryExceptConverter() matches = cvtr.gather(nodes) cvtr.processAll(matches) # dumpTree( nodes ) # dumpNodes( nodes ) assert nodesToLines(nodes) == [ "try {", " bim()", "} catch( e ) /* ( IndexError, KeyError ) */ {", " bam()", " raise", "} finally {", " bom()", "}", "return 123", ]
def test_FunctionToMochaItProcess_01(self): src = """ class Tests( unittest.TestCase ): def test_func1( self ): assert aval == 'bim' def test_func2( self ): assert afunc() def notATestFunc( self ): assert whatever == 'bam' """ nodes = parseSource(src) matches = PytestMethodToMochaItConverter(in_class=True).gather(nodes) PytestMethodToMochaItConverter(in_class=True).processAll(matches) # dumpNodes( nodes ) assert nodesToLines(nodes) == [ "class Tests( unittest.TestCase ):", " it( 'test_func1', () => {", " assert aval == 'bim'", " } );", " it( 'test_func2', () => {", " assert afunc()", " } );", " notATestFunc() {", " assert whatever == 'bam'", " }", ]
def test_processFunction_04(): src = ''' class StringBuff( object ): """ test """ def numLines( self ): return len( self.lines ) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - def addLine( self, line ): """ add a new line to the output """ self.lines.append( self.indent_act + self.tag_closer + line ) self.tag_closer = "" ''' nodes = parseSource(src) matches = FunctionConverter().gather(nodes) processFunction(matches[0].node) processFunction(matches[1].node) # dumpTree( nodes ) # dumpNodes( nodes ) assert nodesToLines(nodes) == [ "class StringBuff( object ):", " \"\"\" test \"\"\"", " function numLines() {", " return len( this.lines );", " }", "", " // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -", " function addLine( line ) {", " /* add a new line to the output */", " this.lines.push( this.indent_act + this.tag_closer + line );", " this.tag_closer = \"\";", " }", ]
def test_processFunction_02(): src = ''' def addTagOpener( self, opener ): """ opener can be the first part of a tag ("<html_tag") or a complete tag up to the closing ">" """ if self.tag_closer: try: self.lines[ -1 ] += opener except IndexError: self.addLine( opener ) ''' nodes = parseSource(src) matches = FunctionConverter().gather(nodes) processFunction(matches[0].node) # dumpTree( nodes ) # dumpNodes( nodes ) assert nodesToLines(nodes) == [ "function addTagOpener( opener ) {", " /* opener can be the first part of a tag (\"<html_tag\") or a complete tag up", " to the closing \">\" */", " if( this.tag_closer ) {", " try {", " this.lines[ -1 ] += opener;", " } catch( e ) /* IndexError */ {", " this.addLine( opener );", " }", "", " }", "}", ]
def test_TryExceptGather_03(): src = """ try: bim() except ( IndexError, KeyError ) as exy: bam() finally: bom() """ matches = TryExceptConverter().gather(parseSource(src)) match = matches[0] assert match.try_word.toString() == 'try' assert match.try_colon.toString() == ':' assert match.try_suite.toString() == 'bim()' assert match.exc_word.toString() == 'except' assert match.exc_what.toString() == '( IndexError, KeyError )' assert match.exc_as.toString() == "as" assert match.exc_as_name.toString() == "exy" assert match.exc_colon.toString() == ':' assert match.exc_suite.toString() == "bam()" assert match.fin_word.toString() == 'finally' assert match.fin_colon.toString() == ':' assert match.fin_suite.toString() == 'bom()'
def test_fixSemicolons_02(): """ don't put semicolons after comments """ src = ''' def afunc(): """ this is a comment """ doStuff() x = "this is not a comment" 'but this is' ''' nodes = parseSource( src ) fixSemicolons( nodes ) # dumpTree( nodes ) # dumpNodes( nodes ) assert nodesToLines( nodes ) == [ "def afunc():", ' """ this', " is", " a", ' comment """', " doStuff();", " x = \"this is not a comment\";", " 'but this is'", ]
def test_StringInterpolationGather_02(): src = """ "%s:%s" % ( aval, bval ) """ matches = StringInterpolationConverter().gather( parseSource( src ) ) match = matches[ 0 ] assert match.left.toString() == '"%s:%s"' assert match.right.toString() == '( aval, bval )'
def test_SelfGather_02(): src = """ self.callMethA( self.callMethB( self.bam ) ) """ matches = SelfConverter().gather( parseSource( src ) ) assert str( matches[ 0 ].right ) + str( matches[ 0 ].rest ) == 'callMethA( self.callMethB( self.bam ) )' assert str( matches[ 1 ].right ) + str( matches[ 1 ].rest ) == 'callMethB( self.bam )' assert str( matches[ 2 ].right ) == 'bam'
def test_ImportNameGather_01(): src = """ import amodule """ matches = ImportNameConverter().gather(parseSource(src)) match = matches[0] assert match.import_word.toString() == 'import' assert nodesToString(match.imported) == 'amodule'
def test_NegateGather_01(): src = """ x = not y """ matches = NegateConverter().gather(parseSource(src)) match = matches[0] assert match.not_word.toString() == 'not' assert nodesToString(match.right) == 'y'
def test_SuperGather_01(): src = """ super( SPVEBorderColorMixed, self ).setupValue() """ matches = SuperConverter().gather(parseSource(src)) match = matches[0] assert match.super_args.toString() == '( SPVEBorderColorMixed, self )' assert match.super_method.toString() == '.setupValue' assert match.method_args.toString() == '()'
def test_ImportNameProcess_02(): src = """ import amodule, bmodule, cmodule """ nodes = parseSource(src) cvtr = ImportNameConverter() matches = cvtr.gather(nodes) cvtr.processAll(matches) assert nodesToString(nodes) == """const amodule = require( './amodule' )
def test_ExceptionGather_02(): src = """ raise NameError( "bimbambom" ) """ matches = ExceptionConverter().gather( parseSource( src ) ) match = matches[ 0 ] assert match.raise_word.toString() == 'raise' assert match.exc_name.toString() == 'NameError' assert match.args.toString() == '"bimbambom"'
def test_ExceptionGather_01(): src = """ raise NameError """ matches = ExceptionConverter().gather( parseSource( src ) ) match = matches[ 0 ] assert match.raise_word.toString() == 'raise' assert match.exc_name.toString() == 'NameError' assert "args" not in match
def test_ExceptionProcess_02(): src = """ raise NameError( "bimbambom" ) """ nodes = parseSource( src ) cvtr = ExceptionConverter() matches = cvtr.gather( nodes ) cvtr.processAll( matches ) assert nodesToString( nodes ) == """throw new Error( 'NameError', "bimbambom" )"""
def test_ListSliceProcess_05(): src = """ alist[ : ] """ nodes = parseSource(src) cvtr = ListSliceConverter() matches = cvtr.gather(nodes) cvtr.processAll(matches) assert nodesToString(nodes) == """alist.slice()"""
def test_ListSliceGather_01(): src = """ alist[ start : finish ] """ matches = ListSliceConverter().gather(parseSource(src)) match = matches[0] assert match.start.toString() == 'start' assert match.colon.toString() == ':' assert match.finish.toString() == 'finish'
def test_AssignmentGather_02(): src = """ [ a, b, c ] = ( 1, 2, 3 ) """ matches = AssignmentConverter().gather(parseSource(src)) assn_clause = matches[0] assert assn_clause.left.toString() == '[ a, b, c ]' assert assn_clause.equals.toString() == '=' assert assn_clause.right.toString() == '( 1, 2, 3 )'
def test_StringInterpolationGather_01(): src = """ astring % aval """ matches = StringInterpolationConverter().gather( parseSource( src ) ) match = matches[ 0 ] assert match.left.toString() == 'astring' assert match.percent_sym.toString() == '%' assert match.right.toString() == 'aval'
def test_KeyWordCallProcess_03(): src = """ return sorted( props, key=sortKey ) """ nodes = parseSource( src ) cvtr = KeyWordCallConverter() matches = cvtr.gather( nodes ) cvtr.processAll( matches ) assert nodesToString( nodes ) == """return sorted( props, { key: sortKey } )"""
def test_KeyWordCallProcess_01(): src = """ x = func( a, b="hello", c=doIt() ) """ nodes = parseSource( src ) cvtr = KeyWordCallConverter() matches = cvtr.gather( nodes ) cvtr.processAll( matches ) assert nodesToString( nodes ) == """x = func( a, { b: "hello", c: doIt() } )"""
def test_ImportFromProcess_01(): src = """ from xyz import funcy """ nodes = parseSource(src) cvtr = ImportFromConverter() matches = cvtr.gather(nodes) cvtr.processAll(matches) assert nodesToString(nodes) == """const { funcy } = require( './xyz' )"""
def test_ComparisonProcess_06(): src = """ x is not y """ nodes = parseSource(src) cvtr = ComparisonConverter() matches = cvtr.gather(nodes) cvtr.processAll(matches) assert nodesToString(nodes) == """!Object.is( x, y )"""
def test_ListSliceGather_04(): src = """ alist[ : ] """ matches = ListSliceConverter().gather(parseSource(src)) match = matches[0] assert "start" not in match assert match.colon.toString() == ':' assert "finish" not in match
def test_ComparisonProcess_04(): src = """ x is not None """ nodes = parseSource(src) cvtr = ComparisonConverter() matches = cvtr.gather(nodes) cvtr.processAll(matches) assert nodesToString(nodes) == """x !== null"""
def test_ComparisonProcess_07(): src = """ dflt is ... """ nodes = parseSource(src) cvtr = ComparisonConverter() matches = cvtr.gather(nodes) cvtr.processAll(matches) assert nodesToString(nodes) == """!_pyjs.isDef( dflt )"""