bicyclerepair-cvslog Mailing List for Bicycle Repair Man!
Status: Alpha
Brought to you by:
pdawes
You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(7) |
Oct
(8) |
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(6) |
Oct
(25) |
Nov
(42) |
Dec
(47) |
2002 |
Jan
(75) |
Feb
(19) |
Mar
(38) |
Apr
(8) |
May
(27) |
Jun
(18) |
Jul
(22) |
Aug
(7) |
Sep
|
Oct
|
Nov
(12) |
Dec
(9) |
2003 |
Jan
(53) |
Feb
(25) |
Mar
(32) |
Apr
(5) |
May
(4) |
Jun
(8) |
Jul
(9) |
Aug
(54) |
Sep
(13) |
Oct
|
Nov
|
Dec
|
2004 |
Jan
(17) |
Feb
(46) |
Mar
|
Apr
|
May
|
Jun
(6) |
Jul
|
Aug
|
Sep
|
Oct
(4) |
Nov
(8) |
Dec
|
From: Phil D. <pd...@us...> - 2004-11-19 12:05:45
|
Update of /cvsroot/bicyclerepair/bicyclerepair/bike/query In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6158/bike/query Modified Files: common.py findDefinition.py getTypeOf.py test_findDefinition.py Log Message: 2004-11-19 Phil Dawes <pd...@us...> * bike/query/findDefinition.py: Added import alias handling to searchImportedModulesForDefinition. removes dependency on getTypeOf. * bike/query/findDefinition.py: Fixed a bug where if was finding defn from a function call 'e.g. theFunction()', and call was made in a method of same name, would find the method rather than look for a function. (i.e. as if call was self.theFunction()) Index: common.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/query/common.py,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- common.py 17 Nov 2004 12:02:29 -0000 1.33 +++ common.py 19 Nov 2004 12:05:36 -0000 1.34 @@ -323,6 +323,10 @@ return isinstance(node,compiler.ast.Function) and \ isinstance(scope,Class) +def scopeIsAMethod(scope): + return isinstance(scope,Function) and isinstance(scope.getParent(),Class) + + def convertNodeToMatchObject(node,confidence=100): m = Match() m.sourcenode = node.module.getSourceNode() Index: findDefinition.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/query/findDefinition.py,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- findDefinition.py 18 Nov 2004 09:52:22 -0000 1.27 +++ findDefinition.py 19 Nov 2004 12:05:36 -0000 1.28 @@ -2,7 +2,8 @@ from bike.query.common import Match, MatchFinder, \ getScopeForLine, indexToCoordinates, \ translateSourceCoordsIntoASTNode, scanScopeForMatches, \ - isAMethod, convertNodeToMatchObject, walkLinesContainingStrings + isAMethod, convertNodeToMatchObject, walkLinesContainingStrings, \ + scopeIsAMethod from bike.parsing.parserutils import generateLogicalLines,\ generateLogicalLinesAndLineNumbers, \ splitLogicalLines, makeLineParseable @@ -47,79 +48,80 @@ def findDefinitionFromASTNode(scope,node): - #print node assert node is not None - if isinstance(node,Name) or isinstance(node,AssName): - while 1: - # try scope children - childscope = scope.getChild(node.name) - if childscope is not None: - return convertNodeToMatchObject(childscope,100) - - if isinstance(scope,Package): - scope = scope.getChild("__init__") - - # try arguments and assignments - match = scanScopeAST(scope,node.name, - AssignmentAndFnArgsSearcher(node.name)) - if match is not None: - return match - # try imports - match = searchImportedModulesForDefinition(scope,node) - if match is not None: - return match - - - if not isinstance(scope,Module): - # try parent scope - scope = scope.getParent() - else: - break - assert isinstance(scope,Module) + + if isinstance(scope,Package): + scope = scope.getChild("__init__") + if isinstance(node,Name) or isinstance(node,AssName): + match = findDefinitionOfNameAST(scope, node) elif isinstance(node,Getattr) or isinstance(node,AssAttr): - exprtype = getTypeOfExpr(scope,node.expr) - if not (exprtype is None or isinstance(exprtype,UnfoundType)): - if isinstance(exprtype,Instance): - exprtype = exprtype.getType() - match = findDefinitionOfAttributeFromASTNode(exprtype, - node.attrname) - if match is None: - #try the class scope itself - match = findDefinitionFromASTNode(exprtype, - Name(node.attrname)) - else: - match = findDefinitionFromASTNode(exprtype, - Name(node.attrname)) - if match is not None: - return match - + match = findDefinitionOfAttributeAST(scope, node) elif isinstance(node,compiler.ast.Function) or \ isinstance(node,compiler.ast.Class): if isAMethod(scope,node): - match = findDefinitionOfAttributeFromASTNode(scope, - node.name) + match = findDefinitionOfAttributeGivenType(scope,node.name) else: match = findDefinitionFromASTNode(scope,Name(node.name)) - if match is not None: - return match + if match is not None: + return match - type = getTypeOfExpr(scope,node) - if type is not None and (not isinstance(type,UnfoundType)) and \ - (not isinstance(type,Instance)): - return convertNodeToMatchObject(type,100) - else: - return None +def findDefinitionOfNameAST(scope, node): + while 1: + # try scope children + childscope = scope.getChild(node.name) + if childscope is not None: + return convertNodeToMatchObject(childscope,100) + # try arguments and assignments + match = scanScopeAST(scope,node.name, + AssignmentAndFnArgsSearcher(node.name)) + if match is not None: + return match + # try imports + match = searchImportedModulesForDefinition(scope,node) + if match is not None: + return match + + if not isinstance(scope,Module): + if scopeIsAMethod(scope): + # can't access class scope from a method, + scope = scope.getParent().getParent() + else: + # try parent scope + scope = scope.getParent() + else: + break + return None # couldn't find it + +def findDefinitionOfAttributeAST(scope, node): + assert isinstance(node,Getattr) or isinstance(node,AssAttr) + exprtype = getTypeOfExpr(scope,node.expr) + match = None + if not (exprtype is None or isinstance(exprtype,UnfoundType)): + if isinstance(exprtype,Instance): + exprtype = exprtype.getType() + match = findDefinitionOfAttributeGivenType(exprtype, + node.attrname) + if match is None: + #try the class scope itself + match = findDefinitionFromASTNode(exprtype, + Name(node.attrname)) + else: + match = findDefinitionFromASTNode(exprtype, + Name(node.attrname)) + if match is not None: + return match + return match -def findDefinitionOfAttributeFromASTNode(type,name): +def findDefinitionOfAttributeGivenType(type,attrname): assert isinstance(type,Class) - attrfinder = AttrbuteDefnFinder([type],name) + attrfinder = AttrbuteDefnFinder([type],attrname) # first scan the method names: for child in type.getChildNodes(): - if child.name == name: + if child.name == attrname: return convertNodeToMatchObject(child,100) # then scan the method source for attribues for child in type.getChildNodes(): @@ -127,7 +129,7 @@ try: return scanScopeForMatches(child.module.getSourceNode(), child, attrfinder, - name).next() + attrname).next() except StopIteration: continue @@ -183,6 +185,12 @@ if match is not None: self.match = match return + elif alias == self.target.name: + match = findDefinitionFromASTNode(module,Name(name)) + if match is not None: + self.match = match + return + match = visitor.walk(ast, ImportVisitor(node)).match Index: getTypeOf.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/query/getTypeOf.py,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- getTypeOf.py 18 Feb 2004 13:05:54 -0000 1.23 +++ getTypeOf.py 19 Nov 2004 12:05:36 -0000 1.24 @@ -27,21 +27,19 @@ if isinstance(scope, Root): assert False, "Can't use getTypeOf to resolve from Root. Use getModuleOrPackageUsingFQN instead" - #print "getTypeOf:"+fqn+" -- "+str(scope) #print #print str(getTypeOfStack) #print + + # wraps the getTypeOf_impl method, caching results and protecting from + # stack overflow if (fqn,scope) in getTypeOfStack: # loop protection return None - - # this is crap! - hashcode = str(scope)+fqn - try: getTypeOfStack.append((fqn,scope)) - try: + hashcode = str(scope)+fqn # this is crap! type = Cache.instance.typecache[hashcode] except KeyError: type = getTypeOf_impl(scope, fqn) @@ -53,7 +51,6 @@ def getTypeOf_impl(scope, fqn): - #print "getTypeOf_impl",scope,fqn if fqn == "None": return None Index: test_findDefinition.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/query/test_findDefinition.py,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- test_findDefinition.py 18 Nov 2004 09:52:22 -0000 1.26 +++ test_findDefinition.py 19 Nov 2004 12:05:36 -0000 1.27 @@ -449,8 +449,6 @@ c = TheClass() """) - - root = createSourceNodeAt(importsrc,"a.__init__") root = createSourceNodeAt(src, "mymodule") filename = os.path.abspath("mymodule.py") |
From: Phil D. <pd...@us...> - 2004-11-19 12:05:45
|
Update of /cvsroot/bicyclerepair/bicyclerepair In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6158 Modified Files: ChangeLog Log Message: 2004-11-19 Phil Dawes <pd...@us...> * bike/query/findDefinition.py: Added import alias handling to searchImportedModulesForDefinition. removes dependency on getTypeOf. * bike/query/findDefinition.py: Fixed a bug where if was finding defn from a function call 'e.g. theFunction()', and call was made in a method of same name, would find the method rather than look for a function. (i.e. as if call was self.theFunction()) Index: ChangeLog =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/ChangeLog,v retrieving revision 1.126 retrieving revision 1.127 diff -u -r1.126 -r1.127 --- ChangeLog 18 Nov 2004 09:52:22 -0000 1.126 +++ ChangeLog 19 Nov 2004 12:05:35 -0000 1.127 @@ -1,3 +1,13 @@ +2004-11-19 Phil Dawes <pd...@us...> + + * bike/query/findDefinition.py: Added import alias handling to + searchImportedModulesForDefinition. removes dependency on getTypeOf. + + * bike/query/findDefinition.py: Fixed a bug where if was finding + defn from a function call 'e.g. theFunction()', and call was made + in a method of same name, would find the method rather than look + for a function. (i.e. as if call was self.theFunction()) + 2004-11-18 Phil Dawes <pd...@us...> * bike/query/findDefinition.py: Fixed another bug unit testcase |
From: Phil D. <pd...@us...> - 2004-11-18 09:52:40
|
Update of /cvsroot/bicyclerepair/bicyclerepair/bike/query In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19586/bike/query Modified Files: findDefinition.py test_findDefinition.py Log Message: 2004-11-18 Phil Dawes <pd...@us...> * bike/query/findDefinition.py: Fixed another bug unit testcase submitted by Aaron Bingham. This one highlighted that class scopes weren't being checked when finding variable definitions - this effected renames to class variables. Index: findDefinition.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/query/findDefinition.py,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- findDefinition.py 10 Feb 2004 11:29:58 -0000 1.26 +++ findDefinition.py 18 Nov 2004 09:52:22 -0000 1.27 @@ -27,13 +27,11 @@ def findAllPossibleDefinitionsByCoords(filepath,lineno,col): - #try: node = translateSourceCoordsIntoASTNode(filepath,lineno,col) #except: # import traceback # traceback.print_exc() - if node is None: raise "selected node type not supported" scope = getScopeForLine(getSourceNode(filepath),lineno) @@ -49,6 +47,7 @@ def findDefinitionFromASTNode(scope,node): + #print node assert node is not None if isinstance(node,Name) or isinstance(node,AssName): while 1: @@ -65,7 +64,6 @@ AssignmentAndFnArgsSearcher(node.name)) if match is not None: return match - # try imports match = searchImportedModulesForDefinition(scope,node) if match is not None: @@ -86,6 +84,10 @@ exprtype = exprtype.getType() match = findDefinitionOfAttributeFromASTNode(exprtype, node.attrname) + if match is None: + #try the class scope itself + match = findDefinitionFromASTNode(exprtype, + Name(node.attrname)) else: match = findDefinitionFromASTNode(exprtype, Name(node.attrname)) Index: test_findDefinition.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/query/test_findDefinition.py,v retrieving revision 1.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- test_findDefinition.py 18 Feb 2004 13:05:54 -0000 1.25 +++ test_findDefinition.py 18 Nov 2004 09:52:22 -0000 1.26 @@ -421,6 +421,24 @@ assert defn[0].confidence == 100 + def test_findsDefnOfFunctionNamedSameAsMethod(self): + src = trimLines(""" + def theFunction(): + pass + + class TheClass: + def theFunction(self): + theFunction() + """) + root = createSourceNodeAt(src,"mymodule") + filename = os.path.abspath("mymodule.py") + defn = [x for x in findAllPossibleDefinitionsByCoords(filename,6,8)] + assert defn[0].filename == os.path.abspath("mymodule.py") + assert defn[0].lineno == 1 + assert defn[0].colno == 4 + assert defn[0].confidence == 100 + + def test_findsClassDeclaredIn__init__Module(self): importsrc=trimLines(""" class TheClass: |
From: Phil D. <pd...@us...> - 2004-11-18 09:52:40
|
Update of /cvsroot/bicyclerepair/bicyclerepair/bike/refactor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19586/bike/refactor Modified Files: test_rename.py Log Message: 2004-11-18 Phil Dawes <pd...@us...> * bike/query/findDefinition.py: Fixed another bug unit testcase submitted by Aaron Bingham. This one highlighted that class scopes weren't being checked when finding variable definitions - this effected renames to class variables. Index: test_rename.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/refactor/test_rename.py,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- test_rename.py 17 Nov 2004 12:02:29 -0000 1.10 +++ test_rename.py 18 Nov 2004 09:52:22 -0000 1.11 @@ -59,6 +59,25 @@ src = self.helper(src,"",2,10,"b") self.assertEqual(srcAfter,src) + def test_renamesClassVariable(self): + src=trimLines(""" + class Foo: + A = 0 + def bar(): + return self.A + print Foo.A + print Foo().A + """) + srcAfter=trimLines(""" + class Foo: + B = 0 + def bar(): + return self.B + print Foo.B + print Foo().B + """) + src = self.helper(src,"",2,4,"B") + self.assertEqual(srcAfter,src) def helper(self, src, classsrc, line, col, newname): try: |
From: Phil D. <pd...@us...> - 2004-11-18 09:52:39
|
Update of /cvsroot/bicyclerepair/bicyclerepair In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19586 Modified Files: AUTHORS ChangeLog Log Message: 2004-11-18 Phil Dawes <pd...@us...> * bike/query/findDefinition.py: Fixed another bug unit testcase submitted by Aaron Bingham. This one highlighted that class scopes weren't being checked when finding variable definitions - this effected renames to class variables. Index: AUTHORS =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/AUTHORS,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- AUTHORS 17 Nov 2004 12:02:29 -0000 1.12 +++ AUTHORS 18 Nov 2004 09:52:21 -0000 1.13 @@ -21,7 +21,7 @@ Peter Astrand <pe...@ce...> Adam Feuer Troy Frever -Aaron Bingham +Aaron Bingham <bi...@ce...> See ChangeLog for more details. Index: ChangeLog =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/ChangeLog,v retrieving revision 1.125 retrieving revision 1.126 diff -u -r1.125 -r1.126 --- ChangeLog 17 Nov 2004 12:02:29 -0000 1.125 +++ ChangeLog 18 Nov 2004 09:52:22 -0000 1.126 @@ -1,3 +1,10 @@ +2004-11-18 Phil Dawes <pd...@us...> + + * bike/query/findDefinition.py: Fixed another bug unit testcase + submitted by Aaron Bingham. This one highlighted that class scopes + weren't being checked when finding variable definitions - this + effected renames to class variables. + 2004-11-17 Phil Dawes <pd...@us...> * bike/refactor/test_rename.py: Fixed a couple of bugs which |
From: Phil D. <pd...@us...> - 2004-11-17 12:02:42
|
Update of /cvsroot/bicyclerepair/bicyclerepair/bike/refactor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25946/bike/refactor Modified Files: test_rename.py Log Message: 2004-11-17 Phil Dawes <pd...@us...> * bike/refactor/test_rename.py: Fixed a couple of bugs which surrounded the renaming of keyword arg variables. The bug and testcases that helped me fix them were submitted by Aaron Bingham. Index: test_rename.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/refactor/test_rename.py,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- test_rename.py 22 Oct 2004 22:38:17 -0000 1.9 +++ test_rename.py 17 Nov 2004 12:02:29 -0000 1.10 @@ -35,6 +35,31 @@ src = self.helper(src,"",2,4,"b") self.assertEqual(srcAfter,src) + def test_renamesKeywordParameterInSignature(self): + src=trimLines(""" + def foo(a=None): + bar(a=a) + """) + srcAfter=trimLines(""" + def foo(b=None): + bar(a=b) + """) + src = self.helper(src,"",1,8,"b") + self.assertEqual(srcAfter,src) + + def test_renamesKeywordParameterInBody(self): + src=trimLines(""" + def foo(a=None): + bar(a=a) + """) + srcAfter=trimLines(""" + def foo(b=None): + bar(a=b) + """) + src = self.helper(src,"",2,10,"b") + self.assertEqual(srcAfter,src) + + def helper(self, src, classsrc, line, col, newname): try: createPackageStructure(src,classsrc) |
From: Phil D. <pd...@us...> - 2004-11-17 12:02:42
|
Update of /cvsroot/bicyclerepair/bicyclerepair/bike/query In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25946/bike/query Modified Files: common.py findReferences.py Log Message: 2004-11-17 Phil Dawes <pd...@us...> * bike/refactor/test_rename.py: Fixed a couple of bugs which surrounded the renaming of keyword arg variables. The bug and testcases that helped me fix them were submitted by Aaron Bingham. Index: common.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/query/common.py,v retrieving revision 1.32 retrieving revision 1.33 diff -u -r1.32 -r1.33 --- common.py 11 Feb 2004 14:06:36 -0000 1.32 +++ common.py 17 Nov 2004 12:02:29 -0000 1.33 @@ -263,6 +263,10 @@ self.node = node self.popWordsUpTo(node.attrname) + def visitKeyword(self,node): + self.popWordsUpTo(node.name) + self.visit(node.expr) + def visitFunction(self, node): if self.checkIfNameMatchesColumn(node.name): self.node = node Index: findReferences.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/query/findReferences.py,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- findReferences.py 22 Oct 2004 22:38:17 -0000 1.23 +++ findReferences.py 17 Nov 2004 12:02:29 -0000 1.24 @@ -113,6 +113,10 @@ visitAssName = visitName + def visitKeyword(self,node): + self.popWordsUpTo(node.name) # keyword arg renaming not supported yet + self.visit(node.expr) + def visitFunction(self, node): self.popWordsUpTo(node.name) for arg, default in self.zipArgs(node.argnames, node.defaults): |
From: Phil D. <pd...@us...> - 2004-11-17 12:02:42
|
Update of /cvsroot/bicyclerepair/bicyclerepair In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25946 Modified Files: AUTHORS ChangeLog setup.py Log Message: 2004-11-17 Phil Dawes <pd...@us...> * bike/refactor/test_rename.py: Fixed a couple of bugs which surrounded the renaming of keyword arg variables. The bug and testcases that helped me fix them were submitted by Aaron Bingham. Index: AUTHORS =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/AUTHORS,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- AUTHORS 22 Oct 2004 22:38:16 -0000 1.11 +++ AUTHORS 17 Nov 2004 12:02:29 -0000 1.12 @@ -21,6 +21,7 @@ Peter Astrand <pe...@ce...> Adam Feuer Troy Frever +Aaron Bingham See ChangeLog for more details. Index: ChangeLog =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/ChangeLog,v retrieving revision 1.124 retrieving revision 1.125 diff -u -r1.124 -r1.125 --- ChangeLog 22 Oct 2004 22:38:17 -0000 1.124 +++ ChangeLog 17 Nov 2004 12:02:29 -0000 1.125 @@ -1,3 +1,9 @@ +2004-11-17 Phil Dawes <pd...@us...> + + * bike/refactor/test_rename.py: Fixed a couple of bugs which + surrounded the renaming of keyword arg variables. The bug and + testcases that helped me fix them were submitted by Aaron Bingham. + 2004-10-22 Phil Dawes <pd...@us...> * bike/query/findReferences.py: Fixed a bug submitted by Parzival Index: setup.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/setup.py,v retrieving revision 1.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- setup.py 22 Oct 2004 22:38:17 -0000 1.38 +++ setup.py 17 Nov 2004 12:02:29 -0000 1.39 @@ -11,7 +11,7 @@ setup(name="bicyclerepair", - version="0.9.1", + version="0.9.2", description="Bicycle Repair Man, the Python refactoring tool", maintainer="Phil Dawes", maintainer_email="pd...@us...", |
From: Phil D. <pd...@us...> - 2004-10-22 22:38:26
|
Update of /cvsroot/bicyclerepair/bicyclerepair/bike/refactor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5018/bike/refactor Modified Files: extractMethod.py moveToModule.py test_moveToModule.py test_rename.py Log Message: some patches and fixes - see changelog for details Index: extractMethod.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/refactor/extractMethod.py,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- extractMethod.py 9 Feb 2004 21:40:22 -0000 1.22 +++ extractMethod.py 22 Oct 2004 22:38:17 -0000 1.23 @@ -11,7 +11,7 @@ reverseCoordsIfWrongWayRound from bike.transformer.save import queueFileToSave from bike.parsing.load import getSourceNode -TABSIZE = 4 +DEFAULT_TABSIZE = 4 class coords: def __init__(self, line, column): @@ -87,12 +87,18 @@ def getTabwidthOfParentFunction(self): line = self.sourcenode.getLines()[self.fn.getStartLine()-1] - match = re.match("\s+",line) - if match is None: - return 0 - else: - return match.end(0) + return getTabWidthOfLine(line) + def getTabwidthOfFunctionBody(self): + line = self.sourcenode.getLines()[self.fn.getStartLine()] + tabwidth = getTabWidthOfLine(line) + parentTabwidth = self.getTabwidthOfParentFunction() + if tabwidth < parentTabwidth: + tabwidth = parentTabwidth + DEFAULT_TABSIZE + if tabwidth < DEFAULT_TABSIZE: + tabwidth = DEFAULT_TABSIZE + return tabwidth + # should be in the transformer module def insertNewFunctionIntoSrcLines(self,srclines,newfn,insertpos): tabwidth = self.getTabwidthOfParentFunction() @@ -118,8 +124,7 @@ srclines.insert(insertpos,tabwidth*" "+fndefn) insertpos +=1 - tabwidth += TABSIZE - + tabwidth = self.getTabwidthOfFunctionBody() if self.extractedCodeIsAnExpression(srclines): assert len(self.extractedLines) == 1 Index: moveToModule.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/refactor/moveToModule.py,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- moveToModule.py 18 Feb 2004 13:05:55 -0000 1.3 +++ moveToModule.py 22 Oct 2004 22:38:17 -0000 1.4 @@ -116,7 +116,7 @@ -def composeNewFileImportLines(importModules, linesep): +def composeNewFileImportLines(importModules, dfLineSep): importlines = [] for mpath in importModules: importlines += "from %s import %s"%(mpath, Index: test_moveToModule.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/refactor/test_moveToModule.py,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- test_moveToModule.py 1 Jun 2004 10:19:57 -0000 1.4 +++ test_moveToModule.py 22 Oct 2004 22:38:17 -0000 1.5 @@ -32,6 +32,7 @@ finally: removePackageStructure() +''' class TestMoveFunction(BRMTestCase): def test_importsNameReference(self): src1=trimLines(""" @@ -235,7 +236,7 @@ finally: removePackageStructure() - +''' if __name__ == "__main__": unittest.main() Index: test_rename.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/refactor/test_rename.py,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- test_rename.py 11 Feb 2004 14:06:36 -0000 1.8 +++ test_rename.py 22 Oct 2004 22:38:17 -0000 1.9 @@ -6,6 +6,21 @@ from bike.testutils import * class TestRenameTemporary(BRMTestCase): + def test_renamesDefaultArgument(self): + src=trimLines(""" + a = 'hello' + def amethod(a=a): + pass + """) + srcAfter=trimLines(""" + b = 'hello' + def amethod(a=b): + pass + """) + src = self.helper(src,"",1,0,"b") + self.assertEqual(srcAfter,src) + + def test_renamesSimpleReferencesGivenAssignment(self): src=trimLines(""" def foo(): |
From: Phil D. <pd...@us...> - 2004-10-22 22:38:26
|
Update of /cvsroot/bicyclerepair/bicyclerepair In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5018 Modified Files: AUTHORS ChangeLog setup.py Log Message: some patches and fixes - see changelog for details Index: AUTHORS =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/AUTHORS,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- AUTHORS 10 Feb 2004 19:53:46 -0000 1.10 +++ AUTHORS 22 Oct 2004 22:38:16 -0000 1.11 @@ -19,6 +19,8 @@ Jonathan <jon...@in...> Steve <the...@ya...> Peter Astrand <pe...@ce...> +Adam Feuer +Troy Frever See ChangeLog for more details. Index: ChangeLog =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/ChangeLog,v retrieving revision 1.123 retrieving revision 1.124 diff -u -r1.123 -r1.124 --- ChangeLog 1 Jun 2004 10:29:56 -0000 1.123 +++ ChangeLog 22 Oct 2004 22:38:17 -0000 1.124 @@ -1,3 +1,16 @@ +2004-10-22 Phil Dawes <pd...@us...> + + * bike/query/findReferences.py: Fixed a bug submitted by Parzival + Herzog via Detlev Offenbach. Actually turned out to be 2 bugs in + one - the first was that function args get erroneously renamed if + they are the same name as a global, and the second was that + default args *don't* get renamed. + +2004-10-08 Phil Dawes <pd...@us...> + + * bike/refactor/extractMethod.py: Committed Adam Feuer's and Troy + Frever's patch to better handle different tab sizes in extractMethod + 2004-06-01 Phil Dawes <pd...@us...> * ide-integration/BicycleRepairMan_Idle.py: Committed Kerim Index: setup.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/setup.py,v retrieving revision 1.37 retrieving revision 1.38 diff -u -r1.37 -r1.38 --- setup.py 1 Jun 2004 10:19:57 -0000 1.37 +++ setup.py 22 Oct 2004 22:38:17 -0000 1.38 @@ -11,7 +11,7 @@ setup(name="bicyclerepair", - version="0.9", + version="0.9.1", description="Bicycle Repair Man, the Python refactoring tool", maintainer="Phil Dawes", maintainer_email="pd...@us...", |
From: Phil D. <pd...@us...> - 2004-10-22 22:38:26
|
Update of /cvsroot/bicyclerepair/bicyclerepair/bike In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5018/bike Modified Files: logging.py Log Message: some patches and fixes - see changelog for details Index: logging.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/logging.py,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- logging.py 5 Aug 2002 10:14:35 -0000 1.1 +++ logging.py 22 Oct 2004 22:38:17 -0000 1.2 @@ -705,7 +705,7 @@ are expected to be encodable within 16 bits (i.e. < 32767 bytes). """ - def __init__(self, host, port): + def __init__(self, host, portbase): """ Initializes the handler with a specific host address and port. """ @@ -787,7 +787,7 @@ (i.e. < 32767 bytes). """ - def __init__(self, host, port): + def __init__(self, host, portbase): """ Initializes the handler with a specific host address and port. """ @@ -1875,7 +1875,7 @@ # _listener holds the server object doing the listening _listener = None -def listen(port=DEFAULT_LOGGING_CONFIG_PORT): +def listen(portbase=DEFAULT_LOGGING_CONFIG_PORT): """ Start up a socket server on the specified port, and listen for new configurations. These will be sent as a file suitable for processing @@ -1935,7 +1935,7 @@ allow_reuse_address = 1 - def __init__(self, host='localhost', port=DEFAULT_LOGGING_CONFIG_PORT, + def __init__(self, host='localhost', portbase=DEFAULT_LOGGING_CONFIG_PORT, handler=None): ThreadingTCPServer.__init__(self, (host, port), handler) _acquireLock() |
From: Phil D. <pd...@us...> - 2004-10-22 22:38:26
|
Update of /cvsroot/bicyclerepair/bicyclerepair/bike/query In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5018/bike/query Modified Files: findReferences.py Log Message: some patches and fixes - see changelog for details Index: findReferences.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/query/findReferences.py,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- findReferences.py 10 Feb 2004 11:29:58 -0000 1.22 +++ findReferences.py 22 Oct 2004 22:38:17 -0000 1.23 @@ -116,13 +116,24 @@ def visitFunction(self, node): self.popWordsUpTo(node.name) for arg, default in self.zipArgs(node.argnames, node.defaults): - if arg == self.targetstr: + potentualMatch = findDefinitionFromASTNode(self.scope,Name(arg)) + if potentualMatch is not None and \ + potentualMatch == self.targetMatch: self.appendMatch(arg) self.popWordsUpTo(arg) if default is not None: - self.visit(default) + self.handleDefaultArg(default) self.visit(node.code) + def handleDefaultArg(self, node): + if node.name == self.targetstr: + potentualMatch = findDefinitionFromASTNode(self.scope.getParent(), + node) + if potentualMatch is not None and \ + potentualMatch == self.targetMatch: + self.appendMatch(node.name) + self.popWordsUpTo(node.name) + def visitFrom(self, node): for elem in node.modname.split("."): @@ -142,7 +153,7 @@ self.popWordsUpTo(alias) - def visitGetattr(self, node): + def visitGetattr(self, node): for c in node.getChildNodes(): self.visit(c) if node.attrname == self.targetstr: |
From: Phil D. <pd...@us...> - 2004-06-01 10:30:05
|
Update of /cvsroot/bicyclerepair/bicyclerepair In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12362 Modified Files: ChangeLog Log Message: Applied Kerims patch to fix corrupted symbols Index: ChangeLog =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/ChangeLog,v retrieving revision 1.122 retrieving revision 1.123 diff -u -r1.122 -r1.123 --- ChangeLog 18 Feb 2004 13:05:54 -0000 1.122 +++ ChangeLog 1 Jun 2004 10:29:56 -0000 1.123 @@ -1,3 +1,8 @@ +2004-06-01 Phil Dawes <pd...@us...> + + * ide-integration/BicycleRepairMan_Idle.py: Committed Kerim + Borchaev's patch to fix corrupted symbols. + 2004-02-18 Phil Dawes <pd...@us...> * bike/query/getTypeOf.py: Added feature to |
From: Phil D. <pd...@us...> - 2004-06-01 10:30:04
|
Update of /cvsroot/bicyclerepair/bicyclerepair/ide-integration In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12362/ide-integration Modified Files: BicycleRepairMan_Idle.py Log Message: Applied Kerims patch to fix corrupted symbols Index: BicycleRepairMan_Idle.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/ide-integration/BicycleRepairMan_Idle.py,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- BicycleRepairMan_Idle.py 5 Feb 2004 22:03:15 -0000 1.23 +++ BicycleRepairMan_Idle.py 1 Jun 2004 10:29:56 -0000 1.24 @@ -300,21 +300,21 @@ return 1 - def confirm_buffer_is_saved(self, editwin): - if not editwin.get_saved(): - name = (editwin.short_title()or - editwin.long_title()or - "Untitled") - reply = tkMessageBox.askokcancel("Bicycle Repair Man", - "The buffer for %s is not saved.\n\n"%name+ - "Save it and continue?", - master = self.editwin.text) - &nbs p; self.editwin.text.focus_set() - if reply: - editwin.io.save(None) - else: - return 0 - return 1 + def confirm_buffer_is_saved(self, editwin): + if not editwin.get_saved(): + name = (editwin.short_title()or + editwin.long_title()or + "Untitled") + reply = tkMessageBox.askokcancel("Bicycle Repair Man", + "The buffer for %s is not saved.\n\n"%name+ + "Save it and continue?", + master = self.editwin.text) + self.editwin.text.focus_set() + if reply: + editwin.io.save(None) + else: + return 0 + return 1 def errorbox(self, title, message): tkMessageBox.showerror(title, message, master = self.editwin.text) |
From: Phil D. <pd...@us...> - 2004-06-01 10:20:07
|
Update of /cvsroot/bicyclerepair/bicyclerepair/ide-integration In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10721/ide-integration Modified Files: bikeemacs.py Log Message: Synch with my local copy - see changelog Index: bikeemacs.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/ide-integration/bikeemacs.py,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- bikeemacs.py 9 Feb 2004 21:40:22 -0000 1.19 +++ bikeemacs.py 1 Jun 2004 10:19:57 -0000 1.20 @@ -74,14 +74,15 @@ ["Rename" brm-rename t] ["Extract-Method" brm-extract-method t] ["Extract-Local-Variable" brm-extract-local-variable t] - ["Move-Class-To-New-Module" brm-move-class t] - ["Move-Function-To-New-Module" brm-move-class t] ["Inline-Local-Variable" brm-inline-local-variable t] ["Undo Last Refactoring" brm-undo t] )) (add-hook 'python-mode-hook (lambda () (easy-menu-add brm-menu))) """) + # ["Move-Class-To-New-Module" brm-move-class t] + # ["Move-Function-To-New-Module" brm-move-class t] + self.ctx.setProgressLogger(logger) |
From: Phil D. <pd...@us...> - 2004-06-01 10:20:07
|
Update of /cvsroot/bicyclerepair/bicyclerepair In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10721 Modified Files: DESIGN.html setup.py Log Message: Synch with my local copy - see changelog Index: DESIGN.html =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/DESIGN.html,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- DESIGN.html 27 Jan 2004 10:14:35 -0000 1.1 +++ DESIGN.html 1 Jun 2004 10:19:57 -0000 1.2 @@ -49,9 +49,9 @@ (see python docs). This parser generates very accurate AST. Unfortunately this proved to be far too slow for interactive use, and so I built a seperate parser which does a basic job of parsing, -but very fast. BRM uses this basic parser to locate and navigate round -the code, and then applies the compiler package to small bits of code -where necessary. +but very fast. BRM uses this basic parser to navigate the code, and +then applies the compiler package to small bits of code where +necessary. </p> <p> @@ -182,7 +182,7 @@ <address><a href="mailto:pd...@us...">Phil Dawes</a></address> <!-- Created: Mon Jan 26 17:43:32 GMT 2004 --> <!-- hhmts start --> -Last modified: Mon Jan 26 18:40:51 GMT 2004 +Last modified: Tue Apr 13 07:45:08 BST 2004 <!-- hhmts end --> </body> </html> Index: setup.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/setup.py,v retrieving revision 1.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- setup.py 12 Jan 2004 10:28:22 -0000 1.36 +++ setup.py 1 Jun 2004 10:19:57 -0000 1.37 @@ -11,7 +11,7 @@ setup(name="bicyclerepair", - version="0.9-080104", + version="0.9", description="Bicycle Repair Man, the Python refactoring tool", maintainer="Phil Dawes", maintainer_email="pd...@us...", |
From: Phil D. <pd...@us...> - 2004-06-01 10:20:06
|
Update of /cvsroot/bicyclerepair/bicyclerepair/bike/refactor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10721/bike/refactor Modified Files: test_moveToModule.py Log Message: Synch with my local copy - see changelog Index: test_moveToModule.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/refactor/test_moveToModule.py,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- test_moveToModule.py 18 Feb 2004 13:05:55 -0000 1.3 +++ test_moveToModule.py 1 Jun 2004 10:19:57 -0000 1.4 @@ -193,7 +193,7 @@ moveFunctionToNewModule(pkgstructureFile1,1, pkgstructureFile0) save() - print file(pkgstructureFile0).read() + #print file(pkgstructureFile0).read() self.assertEqual(src0after,file(pkgstructureFile0).read()) finally: removePackageStructure() |
From: Phil D. <pd...@us...> - 2004-06-01 10:20:06
|
Update of /cvsroot/bicyclerepair/bicyclerepair/ide-integration/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10721/ide-integration/test Modified Files: README Log Message: Synch with my local copy - see changelog Index: README =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/ide-integration/test/README,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- README 25 Aug 2003 11:49:03 -0000 1.9 +++ README 1 Jun 2004 10:19:57 -0000 1.10 @@ -39,7 +39,7 @@ - Goto scrap.py, select 'find references'. Check that it tells you to highlight a class/function/method. -- Highlight 'myMethod' and try again Check that it displays a list of +- Highlight 'myMethod' and try again. Check that it displays a list of references to this method. |
From: Phil D. <pd...@us...> - 2004-02-18 13:15:34
|
Update of /cvsroot/bicyclerepair/bicyclerepair/bike/refactor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1469/bike/refactor Modified Files: moveToModule.py test_moveToModule.py Log Message: Another fix to the path stuff. some more work on moveFunction to new module. See Changelog Index: moveToModule.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/refactor/moveToModule.py,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- moveToModule.py 10 Feb 2004 19:53:46 -0000 1.2 +++ moveToModule.py 18 Feb 2004 13:05:55 -0000 1.3 @@ -43,7 +43,7 @@ linesep = getLineSeperator(srcnode.getLines()[0]) - matches = findReferences(origfile, line, scope.getColumnOfName()) + matches =[m for m in findReferences(origfile, line, scope.getColumnOfName())] origFileImport = [] fromline = 'from %s import %s'%(filenameToModulePath(newfile),scope.name) @@ -63,12 +63,20 @@ reMatch = re.match(exactFromRE%(scope.name),maskedline) if reMatch and not (',' in reMatch.group(2) or \ '\\' in reMatch.group(2)): - restOfOrigLine = origline[len(reMatch.group(1)):] - s.getLines()[match.lineno-1] = fromline + restOfOrigLine + # i.e. line is 'from module import foo' + + if match.filename == newfile: + #remove the import + s.getLines()[match.lineno-1:match.lineno] = [] + pass + else: + restOfOrigLine = origline[len(reMatch.group(1)):] + s.getLines()[match.lineno-1] = fromline + restOfOrigLine elif re.match(fromRE,maskedline): + # i.e. line is 'from module import foo,bah,baz' #remove the element from the import stmt - line = re.sub('%s\s*?,'%(scope.name),'',origline) + line = removeNameFromMultipleImportLine(scope.name, origline) s.getLines()[match.lineno-1] = line #and add a new line nextline = match.lineno + maskedline.count('\\') + 1 @@ -99,6 +107,14 @@ queueFileToSave(srcnode.filename,srcnode.getSource()) queueFileToSave(targetsrcnode.filename,targetsrcnode.getSource()) +def removeNameFromMultipleImportLine(name, origline): + def replacefn(match): + return match.group(1) + line = re.sub('(\W)%s\s*?,'%(name),replacefn,origline) + return line + + + def composeNewFileImportLines(importModules, linesep): importlines = [] Index: test_moveToModule.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/refactor/test_moveToModule.py,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- test_moveToModule.py 10 Feb 2004 19:53:46 -0000 1.2 +++ test_moveToModule.py 18 Feb 2004 13:05:55 -0000 1.3 @@ -170,6 +170,59 @@ finally: removePackageStructure() + def test_updatesFromImportMultiplesInTargetModule(self): + src0=trimLines(""" + from a.foo import something,theFunction,somethingelse #comment + print theFunction() + """) + src1=trimLines(""" + def theFunction(self): + pass + something = '' + somethingelse = 0 + """) + + src0after=trimLines(""" + from a.foo import something,somethingelse #comment + print theFunction() + def theFunction(self): + pass + """) + try: + createPackageStructure(src1,"",src0) + moveFunctionToNewModule(pkgstructureFile1,1, + pkgstructureFile0) + save() + print file(pkgstructureFile0).read() + self.assertEqual(src0after,file(pkgstructureFile0).read()) + finally: + removePackageStructure() + + + def test_updatesFromImportInTargetModule(self): + src0=trimLines(""" + from a.foo import theFunction + print theFunction() + """) + src1=trimLines(""" + def theFunction(self): + pass + """) + + src0after=trimLines(""" + print theFunction() + def theFunction(self): + pass + """) + try: + createPackageStructure(src1,"",src0) + moveFunctionToNewModule(pkgstructureFile1,1, + pkgstructureFile0) + save() + self.assertEqual(src0after,file(pkgstructureFile0).read()) + finally: + removePackageStructure() + def helper(self, src1, src2after): |
From: Phil D. <pd...@us...> - 2004-02-18 13:15:34
|
Update of /cvsroot/bicyclerepair/bicyclerepair/bike/query In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1469/bike/query Modified Files: getTypeOf.py test_findDefinition.py Log Message: Another fix to the path stuff. some more work on moveFunction to new module. See Changelog Index: getTypeOf.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/query/getTypeOf.py,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- getTypeOf.py 11 Feb 2004 14:06:36 -0000 1.22 +++ getTypeOf.py 18 Feb 2004 13:05:54 -0000 1.23 @@ -5,6 +5,7 @@ from bike.parsing import visitor from bike import log from bike.parsing.newstuff import getModuleOrPackageUsingFQN +from bike.parsing.pathutils import getPackageBaseDirectory from bike.parsing.load import Cache import os import re @@ -360,9 +361,17 @@ node = getModuleOrPackageUsingFQN(fqn,path) if node is not None: return node - # try searching from the root - node = getModuleOrPackageUsingFQN(fqn) + + # try searching in same package hierarchy + basedir = getPackageBaseDirectory(scope.module.filename) + if fqn.split('.')[0] == os.path.split(basedir)[-1]: + # base package in fqn matches base directory + restOfFqn = ".".join(fqn.split('.')[1:]) + node = getModuleOrPackageUsingFQN(restOfFqn,basedir) if node is not None: return node - + # try searching the python path + node = getModuleOrPackageUsingFQN(fqn) + if node is not None: + return node Index: test_findDefinition.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/query/test_findDefinition.py,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- test_findDefinition.py 11 Feb 2004 14:06:36 -0000 1.24 +++ test_findDefinition.py 18 Feb 2004 13:05:54 -0000 1.25 @@ -585,7 +585,7 @@ deleteTmpTestFile() - def test_findsDefnInSameNonPackageHierarchyAndRootNotInPath(self): + def test_findsDefnInPackageSubDirectoryAndRootNotInPath(self): src=trimLines(""" from b.bah import TheClass """) @@ -601,6 +601,21 @@ assert defn[0].colno == 6 assert defn[0].confidence == 100 + def test_findsDefnInSamePackageHierarchyAndRootNotInPath(self): + src=trimLines(""" + from a.b.bah import TheClass + """) + classsrc=trimLines(""" + class TheClass: + def theMethod(self): + pass + """) + getRoot().pythonpath = [] # clear the python path + defn = self.helper(src, classsrc, 1, 20) + assert defn[0].filename == pkgstructureFile2 + assert defn[0].lineno == 1 + assert defn[0].colno == 6 + assert defn[0].confidence == 100 def helper(self, src, classsrc, line, col): try: |
From: Phil D. <pd...@us...> - 2004-02-18 13:15:33
|
Update of /cvsroot/bicyclerepair/bicyclerepair In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1469 Modified Files: ChangeLog Log Message: Another fix to the path stuff. some more work on moveFunction to new module. See Changelog Index: ChangeLog =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/ChangeLog,v retrieving revision 1.121 retrieving revision 1.122 diff -u -r1.121 -r1.122 --- ChangeLog 11 Feb 2004 14:06:36 -0000 1.121 +++ ChangeLog 18 Feb 2004 13:05:54 -0000 1.122 @@ -1,3 +1,9 @@ +2004-02-18 Phil Dawes <pd...@us...> + + * bike/query/getTypeOf.py: Added feature to + resolveImportedModuleOrPackage that searches the package hierarchy + of the scope even if it isn't in the pythonpath. + 2004-02-11 Phil Dawes <pd...@us...> * bike/query/getTypeOf.py: rewrote resolveImportedModuleOrPackage |
From: Phil D. <pd...@us...> - 2004-02-11 14:10:51
|
Update of /cvsroot/bicyclerepair/bicyclerepair/bike/parsing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22940/bike/parsing Modified Files: fastparserast.py newstuff.py pathutils.py test_newstuff.py Log Message: Various fixes and refactoring. See Changelog Index: fastparserast.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/parsing/fastparserast.py,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- fastparserast.py 10 Feb 2004 19:53:46 -0000 1.16 +++ fastparserast.py 11 Feb 2004 14:06:36 -0000 1.17 @@ -145,6 +145,11 @@ yield self.attachLinenum(line,lineno) lineno +=1 + def generateLinesWithLineNumbers(self,startline=1): + srclines = self.getMaskedModuleLines() + for lineno in range(startline,len(srclines)+1): + yield self.attachLinenum(srclines[lineno-1],lineno) + def attachLinenum(self,line,lineno): line = Line(line) line.linenum = lineno Index: newstuff.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/parsing/newstuff.py,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- newstuff.py 9 Feb 2004 21:40:21 -0000 1.16 +++ newstuff.py 11 Feb 2004 14:06:36 -0000 1.17 @@ -16,15 +16,12 @@ # scope is the scope to search from -def getModuleOrPackageUsingFQN(fqn, scope=None): +def getModuleOrPackageUsingFQN(fqn, dirpath=None): pythonpath = getPythonPath() #print "getModuleOrPackageUsingFQN",pythonpath,fqn - if scope is not None: - if not isinstance(scope,Package): - # shouldnt happen, so dump some trace - print "scope = "+str(scope) - assert isinstance(scope,Package) - pythonpath = [scope.path] + pythonpath + if dirpath is not None: + assert os.path.isdir(dirpath) + pythonpath = [dirpath] + pythonpath filename = getPathOfModuleOrPackage(fqn,pythonpath) #print "getModuleOrPackageUsingFQN - filename",filename if filename is not None: Index: pathutils.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/parsing/pathutils.py,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- pathutils.py 10 Feb 2004 19:53:46 -0000 1.3 +++ pathutils.py 11 Feb 2004 14:06:36 -0000 1.4 @@ -148,7 +148,6 @@ - def filenameToModulePath(fname): directoriesPreceedingRoot = getRootDirectory(fname) import os Index: test_newstuff.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/parsing/test_newstuff.py,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- test_newstuff.py 10 Feb 2004 19:53:46 -0000 1.12 +++ test_newstuff.py 11 Feb 2004 14:06:36 -0000 1.13 @@ -8,9 +8,6 @@ generateModuleFilenamesInPythonPath, getSourceNodesContainingRegex,\ generatePackageDependencies -from bike.query.getTypeOf import getTypeOf - - class TestGetModuleOrPackageUsingFQN(BRMTestCase): def test_worksForFullPath(self): @@ -35,14 +32,14 @@ try: createPackageStructure("pass","pass") fnames = [f for f in \ - generateModuleFilenamesInPythonPath()] + generateModuleFilenamesInPythonPath(pkgstructureFile2)] assert os.path.join(pkgstructureBasedir,"__init__.py") in fnames assert pkgstructureFile1 in fnames assert os.path.join(pkgstructureChilddir,"__init__.py") in fnames assert pkgstructureFile2 in fnames - assert len(fnames) == 4 + assert len(fnames) == 5 finally: removePackageStructure() @@ -67,7 +64,6 @@ def test_doesScanFilesInTheRootDirectory(self): - print "HELLO" try: createPackageStructure("pass","pass","pass") fnames = [f for f in \ @@ -75,10 +71,24 @@ assert pkgstructureFile0 in fnames finally: #os.remove(initfile) - os.remove(newfile) - os.removedirs(nonPkgDir) removePackageStructure() + def test_returnsOtherFilesInSameNonPackageDirectory(self): + try: + oldpath = getRoot().pythonpath + getRoot().pythonpath = [] # clear the python path + writeTmpTestFile("") + newtmpfile = os.path.join(tmproot,"baz.py") + writeFile(newtmpfile, "") + fnames = [f for f in \ + generateModuleFilenamesInPythonPath(tmpfile)] + assert newtmpfile in fnames + finally: + os.remove(newtmpfile) + deleteTmpTestFile() + getRoot().pythonpath = oldpath + + def test_doesntTraverseIntoNonPackagesUnderRoot(self): try: |
From: Phil D. <pd...@us...> - 2004-02-11 14:10:51
|
Update of /cvsroot/bicyclerepair/bicyclerepair In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22940 Modified Files: ChangeLog Log Message: Various fixes and refactoring. See Changelog Index: ChangeLog =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/ChangeLog,v retrieving revision 1.120 retrieving revision 1.121 diff -u -r1.120 -r1.121 --- ChangeLog 10 Feb 2004 19:53:46 -0000 1.120 +++ ChangeLog 11 Feb 2004 14:06:36 -0000 1.121 @@ -1,3 +1,18 @@ +2004-02-11 Phil Dawes <pd...@us...> + + * bike/query/getTypeOf.py: rewrote resolveImportedModuleOrPackage + to use purely getModuleOrPackageUsingFQN searches. (doesnt use + getTypeOf Root searching any more) + + * bike/query/common.py: rewrote getLogicalLine to handle + multilines that parse seperately. (But was submitted by Peter + Astrand) + +2004-02-10 Phil Dawes <pd...@us...> + + * bike/query/getTypeOf.py: Added functionality to search from the + current directory if looking for an import and scope is a module + 2004-02-10 Phil Dawes <pd...@us...> * bike/refactor/moveToModule.py: Added handling of individual |
From: Phil D. <pd...@us...> - 2004-02-11 14:10:51
|
Update of /cvsroot/bicyclerepair/bicyclerepair/bike/query In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22940/bike/query Modified Files: common.py getTypeOf.py test_common.py test_findDefinition.py test_findReferences.py test_getReferencesToMethod.py test_getTypeOf.py Log Message: Various fixes and refactoring. See Changelog Index: common.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/query/common.py,v retrieving revision 1.31 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- common.py 10 Feb 2004 19:53:46 -0000 1.31 +++ common.py 11 Feb 2004 14:06:36 -0000 1.32 @@ -1,7 +1,7 @@ from __future__ import generators from bike.globals import * from bike.parsing.fastparserast import getRoot, Function, Class, Module, getModule -from bike.parsing.parserutils import generateLogicalLines, makeLineParseable, UnbalancedBracesException +from bike.parsing.parserutils import generateLogicalLines, makeLineParseable, UnbalancedBracesException, generateLogicalLinesAndLineNumbers from bike.parsing.newstuff import getSourceNodesContainingRegex from bike.parsing import visitor from bike import log @@ -213,19 +213,7 @@ def translateSourceCoordsIntoASTNode(filename,lineno,col): module = getModule(filename) maskedlines = module.getMaskedModuleLines() - - # backtrack to previous line if it's joined with a '\' - backtrackchars = 0 - try: - previousline = maskedlines[lineno-2] - while '\\' in previousline: - backtrackchars = len(maskedlines[lineno-2]) - lineno -=1 - previousline = maskedlines[lineno-2] - except IndexError: #there was no previousline - pass - - lline,backtrackchars = getLogicalLine(module, lineno, backtrackchars) + lline,backtrackchars = getLogicalLine(module, lineno) doctoredline = makeLineParseable(lline) ast = compiler.parse(doctoredline) idx = backtrackchars+col @@ -235,23 +223,25 @@ raise CouldNotLocateNodeException("Could not translate editor coordinates into source node") return node -#returns (logicalline,backtrackedchars) -# backtrackedchars is the number of characters backtracked to find -# the start of the logical line -def getLogicalLine(module, lineno, backtrackchars=0): - maskedlines = module.getMaskedModuleLines() - try: - lline = generateLogicalLines( - maskedlines[lineno-1:]).next() - except StopIteration: - # try backtracking a line - return getLogicalLine(module,lineno-1, - backtrackchars+len(maskedlines[lineno-2])) - except UnbalancedBracesException: - # try backtracking a line - return getLogicalLine(module,lineno-1, - backtrackchars+len(maskedlines[lineno-2])) - return lline, backtrackchars +def getLogicalLine(module, lineno): + # we know that the scope is the start of a logical line, so + # we search from there + scope = getScopeForLine(module.getSourceNode(), lineno) + linegenerator = \ + module.generateLinesWithLineNumbers(scope.getStartLine()) + for lline,llinenum in \ + generateLogicalLinesAndLineNumbers(linegenerator): + if llinenum > lineno: + break + prevline = lline + prevlinenum = llinenum + + backtrackchars = 0 + for i in range(prevlinenum,lineno): + backtrackchars += len(module.getSourceNode().getLines()[i-1]) + return prevline, backtrackchars + + class ASTNodeFinder(MatchFinder): # line is a masked line of text Index: getTypeOf.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/query/getTypeOf.py,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- getTypeOf.py 10 Feb 2004 11:29:58 -0000 1.21 +++ getTypeOf.py 11 Feb 2004 14:06:36 -0000 1.22 @@ -23,6 +23,10 @@ # returns an fastparser-ast object representing the type # or None if type not found def getTypeOf(scope, fqn): + if isinstance(scope, Root): + assert False, "Can't use getTypeOf to resolve from Root. Use getModuleOrPackageUsingFQN instead" + + #print "getTypeOf:"+fqn+" -- "+str(scope) #print #print str(getTypeOfStack) @@ -62,25 +66,23 @@ #print "couldnt find "+rcdr+" in "+str(scope) pass - #if not isinstance(scope,Instance): - # print "getTypeOf",scope.fqn,fqn - assert scope is not None #assert not ("." in fqn) if isinstance(scope,UnfoundType): return UnfoundType() - if isinstance(scope, Root) or isinstance(scope, Package): + if isinstance(scope, Package): + #assert 0,scope return handlePackageScope(scope, fqn) elif isinstance(scope,Instance): return handleClassInstanceAttribute(scope, fqn) else: - return handleSourceClassOrFunctionScope(scope,fqn) + return handleModuleClassOrFunctionScope(scope,fqn) -def handleSourceClassOrFunctionScope(scope,name): +def handleModuleClassOrFunctionScope(scope,name): if name == "self" and isinstance(scope,Function) and \ isinstance(scope.getParent(),Class): return Instance(scope.getParent()) @@ -104,7 +106,7 @@ # through self (is this true?) parentScope = parentScope.getParent() - if not isinstance(parentScope,Package): + if not (isinstance(parentScope,Package) or isinstance(parentScope,Root)): return getTypeOf(parentScope, name) @@ -135,7 +137,7 @@ return getModuleOrPackageUsingFQN(fqn) # try searching the fs - node = getModuleOrPackageUsingFQN(fqn,package) + node = getModuleOrPackageUsingFQN(fqn,package.path) if node: return node @@ -199,7 +201,11 @@ scope = resolveImportedModuleOrPackage(self.scope, node.modname) if scope is not None: - self.match = getTypeOf(scope, name) + if isinstance(scope,Package): + self.match = getModuleOrPackageUsingFQN(name,scope.path) + else: + assert isinstance(scope,Module) + self.match = getTypeOf(scope, name) @@ -349,19 +355,14 @@ def resolveImportedModuleOrPackage(scope,fqn): - parentPackage = scope.module.getParent() - node = getTypeOf(parentPackage,fqn) - if node is None: - # try a root tree search - node = getTypeOf(getRoot(),fqn) - - if node is None: - #try a direct fs search - if isinstance(scope,Module): - scope = scope.getParent() - if scope != getRoot(): - node = getModuleOrPackageUsingFQN(fqn,scope) - else: - node = getModuleOrPackageUsingFQN(fqn) + # try searching from directory containing scope module + path = os.path.dirname(scope.module.filename) + node = getModuleOrPackageUsingFQN(fqn,path) + if node is not None: + return node + # try searching from the root + node = getModuleOrPackageUsingFQN(fqn) + if node is not None: + return node + - return node Index: test_common.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/query/test_common.py,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- test_common.py 5 Feb 2004 22:03:15 -0000 1.12 +++ test_common.py 11 Feb 2004 14:06:36 -0000 1.13 @@ -7,7 +7,8 @@ from bike.parsing.load import getSourceNode from bike.parsing.fastparser import fastparser from bike.parsing.fastparserast import Module, Class -from common import indexToCoordinates, getScopeForLine, walkLinesContainingStrings +from common import indexToCoordinates, getScopeForLine, walkLinesContainingStrings, translateSourceCoordsIntoASTNode + class TestGetScopeForLine(BRMTestCase): @@ -62,13 +63,27 @@ class TestTranslateSourceCoordsIntoASTNode(BRMTestCase): def test_worksOnImport(self): - from common import translateSourceCoordsIntoASTNode src = trimLines(''' from foo import bar, baz ''') createSourceNodeAt(src,"mymodule") filename = os.path.abspath("mymodule.py") - node = translateSourceCoordsIntoASTNode(filename, 0, 17) + node = translateSourceCoordsIntoASTNode(filename, 1, 17) + assert node.name == 'bar' + + def test_worksOnMultiline(self): + src = trimLines(""" + def foo(x, + y, + z): + return x*y*z + """) + createSourceNodeAt(src,"mymodule") + filename = os.path.abspath("mymodule.py") + node = translateSourceCoordsIntoASTNode(filename, 3, 8) + assert node.name == 'z' + + class TestMatchFinder(BRMTestCase): Index: test_findDefinition.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/query/test_findDefinition.py,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- test_findDefinition.py 4 Feb 2004 10:17:36 -0000 1.23 +++ test_findDefinition.py 11 Feb 2004 14:06:36 -0000 1.24 @@ -5,12 +5,10 @@ from bike import testdata from bike.query.findDefinition import findAllPossibleDefinitionsByCoords -from bike.query.getTypeOf import getTypeOf -from bike.testutils import BRMTestCase, trimLines, \ - createSourceNodeAt, writeTmpTestFile, deleteTmpTestFile, tmpfile, \ - createPackageStructure, removePackageStructure, pkgstructureFile1, \ - pkgstructureRootDir, pkgstructureFile2 - +from bike.query.getTypeOf import getTypeOf,resolveImportedModuleOrPackage +from bike.parsing.newstuff import getModuleOrPackageUsingFQN +from bike.parsing.fastparserast import getRoot +from bike.testutils import * class TestFindDefinitionByCoords(BRMTestCase): @@ -169,7 +167,7 @@ """) root = createSourceNodeAt(src,"a.foo") root = createSourceNodeAt(classsrc, "a.b.bah") - module = getTypeOf(root,"a.foo") + module = getModuleOrPackageUsingFQN("a.foo") filename = os.path.abspath(os.path.join("a","foo.py")) defn = [x for x in findAllPossibleDefinitionsByCoords(filename,1,21)] assert defn[0].filename == os.path.abspath(os.path.join("a","b","bah.py")) @@ -548,7 +546,7 @@ self.assertEqual(8,defn[0].colno) self.assertEqual(100,defn[0].confidence) - def test_philbug(self): + def test_worksIfFindingDefnOfRefInSlashMultiline(self): classsrc=trimLines(""" class TheClass: def theMethod(self): @@ -566,6 +564,44 @@ self.assertEqual(8,defn[0].colno) self.assertEqual(100,defn[0].confidence) + def test_findsDefnInSameNonPackageDirectory(self): + try: + getRoot().pythonpath = [] # clear the python path + classsrc = trimLines(""" + def testFunction(): + print 'hello' + """) + src = trimLines(""" + from baz import testFunction + """) + writeTmpTestFile(src) + newtmpfile = os.path.join(tmproot,"baz.py") + writeFile(newtmpfile, classsrc) + refs = [x for x in findAllPossibleDefinitionsByCoords(tmpfile,1,16)] + assert refs[0].filename == newtmpfile + assert refs[0].lineno == 1 + finally: + os.remove(newtmpfile) + deleteTmpTestFile() + + + def test_findsDefnInSameNonPackageHierarchyAndRootNotInPath(self): + src=trimLines(""" + from b.bah import TheClass + """) + classsrc=trimLines(""" + class TheClass: + def theMethod(self): + pass + """) + getRoot().pythonpath = [] # clear the python path + defn = self.helper(src, classsrc, 1, 18) + assert defn[0].filename == pkgstructureFile2 + assert defn[0].lineno == 1 + assert defn[0].colno == 6 + assert defn[0].confidence == 100 + + def helper(self, src, classsrc, line, col): try: createPackageStructure(src,classsrc) Index: test_findReferences.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/query/test_findReferences.py,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- test_findReferences.py 10 Feb 2004 11:29:58 -0000 1.22 +++ test_findReferences.py 11 Feb 2004 14:06:36 -0000 1.23 @@ -208,7 +208,7 @@ def test_getsReferenceOfMethodCallFromClassImportedWithAlias(self): src = trimLines(""" - import b.bah.TheClass as MyTheClass + from b.bah import TheClass as MyTheClass def foo(): a = MyTheClass() @@ -461,6 +461,31 @@ """) refs = self.helper("",src,1,6) + + def test_returnsOtherFilesInSameNonPackageDirectory(self): + try: + getRoot().pythonpath = [] # clear the python path + classsrc = trimLines(""" + def testFunction(): + print 'hello' + """) + src = trimLines(""" + from baz import testFunction + """) + writeTmpTestFile(src) + newtmpfile = os.path.join(tmproot,"baz.py") + writeFile(newtmpfile, classsrc) + refs = [x for x in findReferences(newtmpfile,1,4)] + + assert refs[0].filename == tmpfile + assert refs[0].lineno == 1 + finally: + os.remove(newtmpfile) + deleteTmpTestFile() + + + + def helper(self, src, classsrc, line, col): try: createPackageStructure(src,classsrc) Index: test_getReferencesToMethod.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/query/test_getReferencesToMethod.py,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- test_getReferencesToMethod.py 4 Feb 2004 10:17:36 -0000 1.9 +++ test_getReferencesToMethod.py 11 Feb 2004 14:06:36 -0000 1.10 @@ -28,7 +28,7 @@ def test_getsReferenceOfMethodCallFromClassImportedWithAlias(self): src = trimLines(""" - import b.bah.TheClass as MyTheClass + from b.bah import TheClass as MyTheClass def foo(): a = MyTheClass() Index: test_getTypeOf.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/query/test_getTypeOf.py,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- test_getTypeOf.py 5 Feb 2004 22:03:15 -0000 1.14 +++ test_getTypeOf.py 11 Feb 2004 14:06:36 -0000 1.15 @@ -7,6 +7,7 @@ from bike.query.getTypeOf import getTypeOf, UnfoundType,\ attemptToConvertGetattrToFqn from bike.parsing.fastparserast import Class, Function, Instance +from bike.parsing.newstuff import getModuleOrPackageUsingFQN from compiler.ast import Getattr,CallFunc,Name class TestGetTypeOf(BRMTestCase): @@ -18,7 +19,7 @@ """) root = createSourceNodeAt(src,"a.foo") root = createSourceNodeAt(testdata.TheClass, "a.b.bah") - module = getTypeOf(root,"a.foo") + module = getModuleOrPackageUsingFQN("a.foo") res = getTypeOf(module,"a") assert isinstance(res,Instance) assert isinstance(res.getType(),Class) @@ -31,7 +32,7 @@ """) root = createSourceNodeAt(src,"a.foo") root = createSourceNodeAt(testdata.TheClass, "a.b.bah") - module = getTypeOf(root,"a.foo") + module = getModuleOrPackageUsingFQN("a.foo") res = getTypeOf(module,"a") assert isinstance(res,Instance) assert isinstance(res.getType(),Class) @@ -44,7 +45,7 @@ """) root = createSourceNodeAt(src,"a.foo") root = createSourceNodeAt(testdata.TheClass, "a.b.bah") - module = getTypeOf(root,"a.foo") + module = getModuleOrPackageUsingFQN("a.foo") res = getTypeOf(module,"a") assert isinstance(res,Instance) assert isinstance(res.getType(),Class) @@ -63,8 +64,9 @@ self.a.theMethod() """) root = createSourceNodeAt(src,"a.foo") - theclass = getTypeOf(root,"a.foo.TheClass") - fn = getTypeOf(root,"a.foo.AnotherClass.anotherFn") + module = getModuleOrPackageUsingFQN('a.foo') + theclass = getTypeOf(module,"TheClass") + fn = getTypeOf(module,"AnotherClass.anotherFn") self.assertEqual(getTypeOf(fn,"self.a").getType().name, "TheClass") #self.assertEqual(getTypeOf(fn,"self.a").getType(), theclass) @@ -81,7 +83,7 @@ root = createSourceNodeAt(src,"a.foo") root = createSourceNodeAt(testdata.TheClass, "a.b.bah") - themodule = getTypeOf(root,"a.foo") + themodule = getModuleOrPackageUsingFQN("a.foo") assert isinstance(getTypeOf(themodule,"a"),UnfoundType) @@ -92,7 +94,7 @@ """) root = createSourceNodeAt(src,"a.foo") root = createSourceNodeAt(testdata.TheClass, "a.b.bah") - themodule = getTypeOf(root,"a.foo") + themodule = getModuleOrPackageUsingFQN("a.foo") self.assertEqual(getTypeOf(themodule,"FooBah").name,"TheClass") self.assertEqual(getTypeOf(themodule,"FooBah").filename, os.path.abspath(os.path.join("a","b","bah.py"))) @@ -109,7 +111,7 @@ createSourceNodeAt(src,"a.foo") createSourceNodeAt(testdata.TheClass, "a.b.bah") createSourceNodeAt(initfile,"a.b.__init__") - themodule = getTypeOf(getRoot(),"a.foo") + themodule = getModuleOrPackageUsingFQN("a.foo") self.assertEqual(getTypeOf(themodule,"b.TheClass").name,"TheClass") self.assertEqual(getTypeOf(themodule,"b.TheClass").filename, os.path.abspath(os.path.join("a","b","bah.py"))) @@ -131,7 +133,8 @@ node = node.getPackage('something') """) root = createSourceNodeAt(src,"a.foo") - fn = getTypeOf(root,"a.foo.fn") + m = getModuleOrPackageUsingFQN("a.foo") + fn = getTypeOf(m,"fn") getTypeOf(fn,"node") # stack overflow! @@ -143,7 +146,7 @@ val = fn(3) """) root = createSourceNodeAt(src,"a.foo") - mod = getTypeOf(root,"a.foo") + mod = getModuleOrPackageUsingFQN("a.foo") getTypeOf(mod,"val") # stack overflow! def test_getsModuleImportedWithFrom(self): @@ -168,7 +171,7 @@ def test_getsTypeOfClassImportedAsAlias(self): importsrc = trimLines(""" - import b.bah.TheClass as MyTheClass + from b.bah import TheClass as MyTheClass def foo(): a = MyTheClass() @@ -182,8 +185,6 @@ type = self.helper(importsrc,src,'MyTheClass') self.assertEqual("TheClass",type.name) - def test_doesntBarfWhenAttemptingToGetNonExistantPackage(self): - getTypeOf(getRoot(),"doesntexist") if __name__ == "__main__": |
From: Phil D. <pd...@us...> - 2004-02-11 14:10:51
|
Update of /cvsroot/bicyclerepair/bicyclerepair/bike/refactor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22940/bike/refactor Modified Files: test_rename.py test_renameMethod.py Log Message: Various fixes and refactoring. See Changelog Index: test_rename.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/refactor/test_rename.py,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- test_rename.py 5 Feb 2004 22:03:15 -0000 1.7 +++ test_rename.py 11 Feb 2004 14:06:36 -0000 1.8 @@ -4,7 +4,6 @@ from bike import testdata from rename import rename from bike.testutils import * -from bike.query.getTypeOf import getTypeOf class TestRenameTemporary(BRMTestCase): def test_renamesSimpleReferencesGivenAssignment(self): Index: test_renameMethod.py =================================================================== RCS file: /cvsroot/bicyclerepair/bicyclerepair/bike/refactor/test_renameMethod.py,v retrieving revision 1.40 retrieving revision 1.41 diff -u -r1.40 -r1.41 --- test_renameMethod.py 5 Feb 2004 22:03:15 -0000 1.40 +++ test_renameMethod.py 11 Feb 2004 14:06:36 -0000 1.41 @@ -387,13 +387,13 @@ def test_renamesReferenceOfClassImportedAsAnotherName(self): srcBefore=trimLines(""" - import b.bah.TheClass as MyTheClass + from b.bah import TheClass as MyTheClass def foo(): a = MyTheClass() a.theMethod() """) srcAfter=trimLines(""" - import b.bah.TheClass as MyTheClass + from b.bah import TheClass as MyTheClass def foo(): a = MyTheClass() a.newName() @@ -418,13 +418,13 @@ def test_renamesReferenceWhenObjectCreatedInSameFunctionAsReference(self): srcBefore=trimLines(""" - import b.bah.TheClass + import b.bah def foo(): a = b.bah.TheClass() a.theMethod() """) srcAfter=trimLines(""" - import b.bah.TheClass + import b.bah def foo(): a = b.bah.TheClass() a.newName() @@ -454,14 +454,14 @@ def test_renamesReferenceOfImportedClass(self): srcBefore=trimLines(""" - import b.bah.TheClass + import b.bah def foo(): a = b.bah.TheClass() a.theMethod() """) srcAfter=trimLines(""" - import b.bah.TheClass + import b.bah def foo(): a = b.bah.TheClass() @@ -472,7 +472,7 @@ def test_doesntRenameReferenceOfDifferentImportedClass(self): srcBefore=trimLines(""" - import b.bah.DifferentClass + from b.bah import DifferentClass def foo(): a = b.bah.TheClass() |