Permalink
Browse files

Moved testdata from Tests to TestData

Added support for standalone modules (no leading dot)
  • Loading branch information...
1 parent be511d0 commit 32c1365ae2ae0dc4a59b3f5dacb36d74f4254af6 @orestis committed Oct 12, 2008
File renamed without changes.
File renamed without changes.
File renamed without changes.
View
@@ -0,0 +1 @@
+NOPACKAGE = 'Cool'
View
@@ -87,11 +87,11 @@ def assertDictsEqual(self, actualDict, expectedDict):
def testMultiPackage(self):
- if os.path.exists('Tests/PYSMELLTAGS'):
- os.remove('Tests/PYSMELLTAGS')
- subprocess.call(["python", "../pysmelltags.py", "PackageA", "PackageB"], cwd='Tests')
- self.assertTrue(os.path.exists('Tests/PYSMELLTAGS'))
- PYSMELLDICT = eval(open('Tests/PYSMELLTAGS').read())
+ if os.path.exists('TestData/PYSMELLTAGS'):
+ os.remove('TestData/PYSMELLTAGS')
+ subprocess.call(["python", "../pysmelltags.py", "PackageA", "PackageB"], cwd='TestData')
+ self.assertTrue(os.path.exists('TestData/PYSMELLTAGS'))
+ PYSMELLDICT = eval(open('TestData/PYSMELLTAGS').read())
expectedDict = {}
expectedDict.update(self.packageA)
expectedDict['CLASSES'].update(self.packageB['CLASSES'])
@@ -102,46 +102,58 @@ def testMultiPackage(self):
def testPackageA(self):
- if os.path.exists('Tests/PYSMELLTAGS'):
- os.remove('Tests/PYSMELLTAGS')
- subprocess.call(["python", "../pysmelltags.py", "PackageA"], cwd='Tests')
- self.assertTrue(os.path.exists('Tests/PYSMELLTAGS'))
- PYSMELLDICT = eval(open('Tests/PYSMELLTAGS').read())
+ if os.path.exists('TestData/PYSMELLTAGS'):
+ os.remove('TestData/PYSMELLTAGS')
+ subprocess.call(["python", "../pysmelltags.py", "PackageA"], cwd='TestData')
+ self.assertTrue(os.path.exists('TestData/PYSMELLTAGS'))
+ PYSMELLDICT = eval(open('TestData/PYSMELLTAGS').read())
expectedDict = self.packageA
self.assertDictsEqual(PYSMELLDICT, expectedDict)
- foundDict = idehelper.findPYSMELLDICT(os.path.join('Tests', 'PackageA', 'something'))
+ foundDict = idehelper.findPYSMELLDICT(os.path.join('TestData', 'PackageA', 'something'))
self.assertDictsEqual(foundDict, expectedDict)
def testPackageB(self):
- if os.path.exists('Tests/PYSMELLTAGS'):
- os.remove('Tests/PYSMELLTAGS')
- subprocess.call(["python", "../pysmelltags.py", "PackageB"], cwd='Tests')
- self.assertTrue(os.path.exists('Tests/PYSMELLTAGS'))
- PYSMELLDICT = eval(open('Tests/PYSMELLTAGS').read())
+ if os.path.exists('TestData/PYSMELLTAGS'):
+ os.remove('TestData/PYSMELLTAGS')
+ subprocess.call(["python", "../pysmelltags.py", "PackageB"], cwd='TestData')
+ self.assertTrue(os.path.exists('TestData/PYSMELLTAGS'))
+ PYSMELLDICT = eval(open('TestData/PYSMELLTAGS').read())
expectedDict = self.packageB
self.assertDictsEqual(PYSMELLDICT, expectedDict)
def testPackageDot(self):
- if os.path.exists('Tests/PackageA/PYSMELLTAGS'):
- os.remove('Tests/PackageA/PYSMELLTAGS')
- subprocess.call(["python", "../../pysmelltags.py", "."], cwd='Tests/PackageA')
- self.assertTrue(os.path.exists('Tests/PackageA/PYSMELLTAGS'))
- PYSMELLDICT = eval(open('Tests/PackageA/PYSMELLTAGS').read())
+ if os.path.exists('TestData/PackageA/PYSMELLTAGS'):
+ os.remove('TestData/PackageA/PYSMELLTAGS')
+ subprocess.call(["python", "../../pysmelltags.py", "."], cwd='TestData/PackageA')
+ self.assertTrue(os.path.exists('TestData/PackageA/PYSMELLTAGS'))
+ PYSMELLDICT = eval(open('TestData/PackageA/PYSMELLTAGS').read())
expectedDict = self.packageA
self.assertDictsEqual(PYSMELLDICT, expectedDict)
def testAllPackages(self):
- self.fail("when the a dir is not a package, search for packages")
- subprocess.call(["python", "pysmelltags.py", "Tests"]) # should generate equivalent to PackageA, PackageB
+ if os.path.exists('TestData/PYSMELLTAGS'):
+ os.remove('TestData/PYSMELLTAGS')
+ subprocess.call(["python", "../pysmelltags.py", "."], cwd='TestData')
+ self.assertTrue(os.path.exists('TestData/PYSMELLTAGS'))
+ PYSMELLDICT = eval(open('TestData/PYSMELLTAGS').read())
+ expectedDict = {}
+ expectedDict.update(self.packageA)
+ expectedDict['CLASSES'].update(self.packageB['CLASSES'])
+ expectedDict['CONSTANTS'].extend(self.packageB['CONSTANTS'])
+ expectedDict['CONSTANTS'].append('standalone.NOPACKAGE')
+ expectedDict['FUNCTIONS'].extend(self.packageB['FUNCTIONS'])
+ expectedDict['HIERARCHY'].extend(self.packageB['HIERARCHY'])
+ expectedDict['HIERARCHY'].append('standalone')
+ self.assertDictsEqual(PYSMELLDICT, expectedDict)
def testSingleFile(self):
"should recurse up until it doesn't find __init__.py"
- path = 'Tests/PackageA/NestedPackage/EvenMore/'
+ path = 'TestData/PackageA/NestedPackage/EvenMore/'
if os.path.exists('%sPYSMELLTAGS' % path):
os.remove('%sPYSMELLTAGS' % path)
subprocess.call(["python", "../../../../pysmelltags.py", "ModuleC.py"], cwd=path)
@@ -159,7 +171,7 @@ def testSingleFile(self):
def testSingleFilesWithPaths(self):
- path = 'Tests'
+ path = 'TestData'
pysmell = os.path.join(path, 'PYSMELLTAGS')
if os.path.exists(pysmell):
os.remove(pysmell)
@@ -179,19 +191,19 @@ def testSingleFilesWithPaths(self):
def testOutputRedirect(self):
- if os.path.exists('Tests/OUTPUTREDIR'):
- os.remove('Tests/OUTPUTREDIR')
+ if os.path.exists('TestData/OUTPUTREDIR'):
+ os.remove('TestData/OUTPUTREDIR')
subprocess.call(["python", "../pysmelltags.py", "PackageA", "-o",
- "OUTPUTREDIR"], cwd='Tests')
- self.assertTrue(os.path.exists('Tests/OUTPUTREDIR'))
- PYSMELLDICT = eval(open('Tests/OUTPUTREDIR').read())
+ "OUTPUTREDIR"], cwd='TestData')
+ self.assertTrue(os.path.exists('TestData/OUTPUTREDIR'))
+ PYSMELLDICT = eval(open('TestData/OUTPUTREDIR').read())
expectedDict = self.packageA
self.assertDictsEqual(PYSMELLDICT, expectedDict)
- absPath = os.path.join(os.getcwd(), 'Tests', 'OUTPUTREDIR2')
+ absPath = os.path.join(os.getcwd(), 'TestData', 'OUTPUTREDIR2')
if os.path.exists(absPath):
os.remove(absPath)
- subprocess.call(["python", "../pysmelltags.py", "PackageA", "-o", absPath], cwd='Tests')
+ subprocess.call(["python", "../pysmelltags.py", "PackageA", "-o", absPath], cwd='TestData')
self.assertTrue(os.path.exists(absPath))
PYSMELLDICT = eval(open(absPath).read())
expectedDict = self.packageA
@@ -220,6 +232,8 @@ def testNoArgs(self):
-t Will print timing information.
+ -v Verbose mode; useful for debugging
+
""").splitlines()
self.assertEquals(stdout.splitlines(), expected)
View
@@ -131,14 +131,14 @@ def sth(self):
self.
""")
- pathParts = ['Tests', 'PackageB', 'NewModule.py'] # Tests/PackageB contains an __init__.py file
+ pathParts = ['TestData', 'PackageB', 'NewModule.py'] # TestData/PackageB contains an __init__.py file
relPath = os.path.join(*pathParts)
inferred, parents = inferClass(relPath, source, 3, self.nestedDict, None)
self.assertEquals(inferred, 'PackageB.NewModule.NewClass')
self.assertEquals(parents, ['object'])
cwd = os.getcwd()
- pathParts = [cwd, 'Tests', 'PackageB', 'NewModule.py'] # Tests/PackageB contains an __init__.py file
+ pathParts = [cwd, 'TestData', 'PackageB', 'NewModule.py'] # TestData/PackageB contains an __init__.py file
absPath = os.path.join(*pathParts)
inferred, parents = inferClass(absPath, source, 3, self.nestedDict, None)
self.assertEquals(inferred, 'PackageB.NewModule.NewClass')
@@ -152,7 +152,7 @@ def sth(self):
self.
""")
- klass, parents = inferClass(os.path.join('Tests', 'PackageA', 'Module.py'), source,
+ klass, parents = inferClass(os.path.join('TestData', 'PackageA', 'Module.py'), source,
4, self.nestedDict)
self.assertEquals(klass, 'PackageA.Module.Other')
self.assertEquals(parents, ['Nested.Package.Module.Class'])
@@ -165,7 +165,7 @@ def sth(self):
self.
""")
- klass, parents = inferClass(os.path.join('Tests', 'PackageA', 'Module.py'), source,
+ klass, parents = inferClass(os.path.join('TestData', 'PackageA', 'Module.py'), source,
4, self.nestedDict)
self.assertEquals(klass, 'PackageA.Module.Bother')
self.assertEquals(parents, ['Nested.Package.Module.Class'])
@@ -179,7 +179,7 @@ def sth(self):
self.
""")
- klass, parents = inferClass(os.path.join('Tests', 'PackageA', 'Module.py'), source,
+ klass, parents = inferClass(os.path.join('TestData', 'PackageA', 'Module.py'), source,
4, self.nestedDict)
self.assertEquals(klass, 'PackageA.Module.Bother')
self.assertEquals(parents, ['Nested.Package.Module.Class'])
@@ -256,7 +256,7 @@ def sth(self):
self.
""")
- options = detectCompletionType(os.path.join('Tests', 'PackageA', 'Module.py'), source,
+ options = detectCompletionType(os.path.join('TestData', 'PackageA', 'Module.py'), source,
"%sself." % (' ' * 8), 4, 13, '', self.nestedDict)
expected = CompletionOptions(isAttrLookup=True,
klass='PackageA.Module.Other', parents=['Nested.Package.Module.Class'],
@@ -270,7 +270,7 @@ def testDetectModuleCompletionInitial(self):
""")
line = "from Nested.Package.Mo"
- options = detectCompletionType(os.path.join('Tests', 'PackageA', 'Module.py'), source,
+ options = detectCompletionType(os.path.join('TestData', 'PackageA', 'Module.py'), source,
line, 1, len(line), '', self.nestedDict)
expected = CompletionOptions(isAttrLookup=False,
klass=None, parents=None,
@@ -296,7 +296,7 @@ def testDetectModuleCompletionTwo(self):
""")
line = "from Nested.Package import "
- options = detectCompletionType(os.path.join('Tests', 'PackageA', 'Module.py'), source,
+ options = detectCompletionType(os.path.join('TestData', 'PackageA', 'Module.py'), source,
line, 1, len(line), '', self.nestedDict)
expected = CompletionOptions(isAttrLookup=False,
klass=None, parents=None,
@@ -309,7 +309,7 @@ def testDetectModuleCompletionTwo(self):
""")
line = "from Nested import "
- options = detectCompletionType(os.path.join('Tests', 'PackageA', 'Module.py'), source,
+ options = detectCompletionType(os.path.join('TestData', 'PackageA', 'Module.py'), source,
line, 1, len(line), '', self.nestedDict)
expected = CompletionOptions(isAttrLookup=False,
klass=None, parents=None,
@@ -322,7 +322,7 @@ def testDetectModuleCompletionTwo(self):
""")
line = "from Nested import Pack"
- options = detectCompletionType(os.path.join('Tests', 'PackageA', 'Module.py'), source,
+ options = detectCompletionType(os.path.join('TestData', 'PackageA', 'Module.py'), source,
line, 1, len(line), '', self.nestedDict)
expected = CompletionOptions(isAttrLookup=False,
klass=None, parents=None,
@@ -337,7 +337,7 @@ def testModuleCompletionThree(self):
""")
line = "import Nested.Package."
- options = detectCompletionType(os.path.join('Tests', 'PackageA', 'Module.py'), source,
+ options = detectCompletionType(os.path.join('TestData', 'PackageA', 'Module.py'), source,
line, 1, len(line), '', self.nestedDict)
expected = CompletionOptions(isAttrLookup=False,
klass=None, parents=None,
View
@@ -157,9 +157,18 @@ def __init__(self):
BaseVisitor.__init__(self)
self.modules = ModuleDict()
self.module = '__module__'
- self.package = '__package__'
+ self.__package = '__package__'
self.path = '__path__'
+
+ def __setPackage(self, package):
+ if package:
+ self.__package = package + '.'
+ else:
+ self.__package = ''
+
+ package = property(lambda s: s.__package, __setPackage)
+
@property
def inClass(self):
return (len(self.scope) > 0 and (isinstance(self.scope[-1], ast.Class)
@@ -187,9 +196,9 @@ def currentClass(self):
def visitModule(self, node):
if self.module == '__init__':
- self.modules.enterModule('%s' % self.package)
+ self.modules.enterModule('%s' % self.package[:-1]) # remove dot
else:
- self.modules.enterModule('%s.%s' % (self.package, self.module))
+ self.modules.enterModule('%s%s' % (self.package, self.module))
self.visit(node.node)
self.modules.exitModule()
@@ -222,7 +231,7 @@ def visitFrom(self, node):
asName = name[1] or name[0]
imported = name[0]
if self.isRelativeImport(node.modname):
- imported = "%s.%s.%s" % (self.package, node.modname, imported)
+ imported = "%s%s.%s" % (self.package, node.modname, imported)
else:
imported = "%s.%s" % (node.modname, imported)
self.modules.addPointer("%s.%s" % (self.modules.currentModule, asName), imported)
@@ -233,7 +242,7 @@ def visitImport(self, node):
asName = name[1] or name[0]
imported = name[0]
if self.isRelativeImport(imported):
- imported = "%s.%s" % (self.package, imported)
+ imported = "%s%s" % (self.package, imported)
self.modules.addPointer("%s.%s" % (self.modules.currentModule, asName), imported)
def isRelativeImport(self, imported):

0 comments on commit 32c1365

Please sign in to comment.