Ejemplo n.º 1
0
    def testInferClassYouDontKnowAbout(self):
        source = dedent("""\
            class NewClass(object):
                def sth(self):
                    self.
        
        """)
        pathParts = ['TestData', 'PackageB', 'NewModule.py'] # TestData/PackageB contains an __init__.py file
        relPath = os.path.join(*pathParts)
        inferred, parents = inferClass(relPath, getSafeTree(source, 3), 3, NESTEDDICT, None)
        self.assertEquals(inferred, 'PackageB.NewModule.NewClass')
        self.assertEquals(parents, ['object'])

        cwd = os.getcwd()
        pathParts = [cwd, 'TestData', 'PackageB', 'NewModule.py'] # TestData/PackageB contains an __init__.py file
        absPath = os.path.join(*pathParts)
        inferred, parents = inferClass(absPath, getSafeTree(source, 3), 3, NESTEDDICT, None)
        self.assertEquals(inferred, 'PackageB.NewModule.NewClass')
        self.assertEquals(parents, ['object'])
Ejemplo n.º 2
0
    def testInferClassYouDontKnowAbout(self):
        source = dedent("""\
            class NewClass(object):
                def sth(self):
                    self.
        
        """)
        pathParts = ['TestData', 'PackageB', 'NewModule.py'] # TestData/PackageB contains an __init__.py file
        relPath = os.path.join(*pathParts)
        inferred, parents = inferClass(relPath, getSafeTree(source, 3), 3, NESTEDDICT, None)
        self.assertEquals(inferred, 'PackageB.NewModule.NewClass')
        self.assertEquals(parents, ['object'])

        cwd = os.getcwd()
        pathParts = [cwd, 'TestData', 'PackageB', 'NewModule.py'] # TestData/PackageB contains an __init__.py file
        absPath = os.path.join(*pathParts)
        inferred, parents = inferClass(absPath, getSafeTree(source, 3), 3, NESTEDDICT, None)
        self.assertEquals(inferred, 'PackageB.NewModule.NewClass')
        self.assertEquals(parents, ['object'])
Ejemplo n.º 3
0
 def testInferClassRelative(self):
     source = dedent("""\
         class Class(object):
             def sth(self):
                 self.
     
     """)
     pathParts = ["Nested", "Package", "Module.py"]
     relPath = os.path.join(*pathParts)
     inferred, _ = inferClass(relPath, getSafeTree(source, 3), 3, NESTEDDICT, None)
     self.assertEquals(inferred, 'Nested.Package.Module.Class')
Ejemplo n.º 4
0
 def testInferClassRelative(self):
     source = dedent("""\
         class Class(object):
             def sth(self):
                 self.
     
     """)
     pathParts = ["Nested", "Package", "Module.py"]
     relPath = os.path.join(*pathParts)
     inferred, _ = inferClass(relPath, getSafeTree(source, 3), 3, NESTEDDICT, None)
     self.assertEquals(inferred, 'Nested.Package.Module.Class')
Ejemplo n.º 5
0
 def testInferClassParentsWithPointersToStar(self):
     source = dedent("""\
         from Star import Class
         class Bother(Class):
             def sth(self):
                 self.
     
     """)
     klass, parents = inferClass(os.path.join('TestData', 'PackageA', 'Module.py'),
         getSafeTree(source, 4), 4, NESTEDDICT)
     self.assertEquals(klass, 'PackageA.Module.Bother')
     self.assertEquals(parents, ['Nested.Package.Module.Class'])
Ejemplo n.º 6
0
 def testInferClassParentsWithPointersToStar(self):
     source = dedent("""\
         from Star import Class
         class Bother(Class):
             def sth(self):
                 self.
     
     """)
     klass, parents = inferClass(os.path.join('TestData', 'PackageA', 'Module.py'),
         getSafeTree(source, 4), 4, NESTEDDICT)
     self.assertEquals(klass, 'PackageA.Module.Bother')
     self.assertEquals(parents, ['Nested.Package.Module.Class'])
Ejemplo n.º 7
0
 def testInferUnknownClassParents(self):
     source = dedent("""\
         from Nested.Package.Module import Class
         class Other(Class):
             def sth(self):
                 self.
     
     """)
     klass, parents = inferClass(
         os.path.join('TestData', 'PackageA', 'Module.py'),
         getSafeTree(source, 4), 4, NESTEDDICT)
     self.assertEqual(klass, 'PackageA.Module.Other')
     self.assertEqual(parents, ['Nested.Package.Module.Class'])
Ejemplo n.º 8
0
 def testInferClassAbsolute(self):
     source = dedent("""\
         class Class(object):
             def sth(self):
                 self.
     
     """)
     pathParts = ["DevFolder", "BlahBlah", "Nested", "Package", "Module.py"]
     if os.name == 'posix':
         pathParts.insert(0, "/")
     else:
         pathParts.insert(0, "C:")
     absPath = os.path.join(*pathParts)
     inferred, _ = inferClass(absPath, getSafeTree(source, 3), 3, NESTEDDICT, None)
     self.assertEquals(inferred, 'Nested.Package.Module.Class')
Ejemplo n.º 9
0
 def testInferClassAbsolute(self):
     source = dedent("""\
         class Class(object):
             def sth(self):
                 self.
     
     """)
     pathParts = ["DevFolder", "BlahBlah", "Nested", "Package", "Module.py"]
     if os.name == 'posix':
         pathParts.insert(0, "/")
     else:
         pathParts.insert(0, "C:")
     absPath = os.path.join(*pathParts)
     inferred, _ = inferClass(absPath, getSafeTree(source, 3), 3, NESTEDDICT, None)
     self.assertEquals(inferred, 'Nested.Package.Module.Class')