Beispiel #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'])
Beispiel #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, source, 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, source, 3, NESTEDDICT, None)
        self.assertEquals(inferred, 'PackageB.NewModule.NewClass')
        self.assertEquals(parents, ['object'])
Beispiel #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, source, 3, NESTEDDICT, None)
     self.assertEquals(inferred, 'Nested.Package.Module.Class')
Beispiel #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')
Beispiel #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'), source,
                         4, NESTEDDICT)
     self.assertEquals(klass, 'PackageA.Module.Bother')
     self.assertEquals(parents, ['Nested.Package.Module.Class'])
Beispiel #6
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'), source,
                         4, NESTEDDICT)
     self.assertEquals(klass, 'PackageA.Module.Other')
     self.assertEquals(parents, ['Nested.Package.Module.Class'])
Beispiel #7
0
 def testInferClassParentsWithPointers(self):
     source = dedent("""\
         from Another import Thing
         class Bother(Thing):
             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'])
Beispiel #8
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'])
Beispiel #9
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'])
Beispiel #10
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, source, 3, NESTEDDICT, None)
     self.assertEquals(inferred, 'Nested.Package.Module.Class')
Beispiel #11
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')