def test_handlesRecursionProblem(self):
     src = trimLines("""
     def fn(root):
         node = root
         node = node.getPackage('something')
     """)
     root = createSourceNodeAt(src,"a.foo")
     m = getModuleOrPackageUsingFQN("a.foo")
     fn = getTypeOf(m,"fn")
     getTypeOf(fn,"node")   # stack overflow!
 def test_doesntGotIntoRecursiveLoopWhenEvaluatingARecursiveFunction(self):
     src = trimLines("""
     def fn(v):
         if v < 45:
             return fn(root+1)
     val = fn(3)
     """)
     root = createSourceNodeAt(src,"a.foo")
     mod = getModuleOrPackageUsingFQN("a.foo")
     getTypeOf(mod,"val")   # stack overflow!
 def test_getsTypeOfClassReferencedViaAlias(self):
     src = trimLines("""
     from b.bah import TheClass as FooBah
     FooBah()
     """)
     root = createSourceNodeAt(src,"a.foo")
     root = createSourceNodeAt(testdata.TheClass, "a.b.bah")
     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")))
 def test_getsTypeOfClassImportedFromPackageScope(self):
     initfile = trimLines("""
     from bah import TheClass
     """)
     src = trimLines("""
     from a import b
     b.TheClass()
     """)
     createSourceNodeAt(src,"a.foo")
     createSourceNodeAt(testdata.TheClass, "a.b.bah")
     createSourceNodeAt(initfile,"a.b.__init__")
     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")))
Esempio n. 5
0
 def helper(self,src,classname):
     try:
         createPackageStructure(src,testdata.TheClass)
         classobj = getTypeOf(getModule(pkgstructureFile1),classname,[pkgstructureRootDir])
         return getRootClassesOfHierarchy(classobj,[pkgstructureRootDir])
     finally:
         removePackageStructure()
 def test_getsTypeOfInstanceThatIsAnAttributeOfSelf(self):
     src = trimLines("""
     class TheClass:
         def theMethod(self):
             pass
     
     class AnotherClass:
         def __init__(self):
             self.a = TheClass()
         def anotherFn(self):
             self.a.theMethod()
     """)
     root = createSourceNodeAt(src,"a.foo")
     module = getModuleOrPackageUsingFQN('a.foo')
     theclass = getTypeOf(module,"TheClass")
     fn = getTypeOf(module,"AnotherClass.anotherFn")
     self.assertEqual(getTypeOf(fn,"self.a").getType().name, "TheClass")
 def helper(self,importsrc,src,name):
     try:
         createPackageStructure(importsrc,src)
         from bike.parsing.newstuff import getModule
         scope = getModule(pkgstructureFile1)
         return getTypeOf(scope,name)
     finally:
         removePackageStructure()
Esempio n. 8
0
 def test_getsTypeOfImportedClassReference(self):
     src = trimLines("""
     import b.bah
     a = b.bah.TheClass()
     """)
     root = createSourceNodeAt(src,"a.foo")
     root = createSourceNodeAt(testdata.TheClass, "a.b.bah")
     module = getModuleUsingFQN("a.foo",[pkgstructureRootDir])
     res =  getTypeOf(module,"a",[pkgstructureRootDir])
     assert isinstance(res,Instance)
     assert isinstance(res.getType(),Class)
     assert res.getType().name == "TheClass"
 def test_getsTypeOfClassReferenceFromImportedPackage(self):
     src = trimLines("""
     import b
     a = b.bah.TheClass()
     """)
     root = createSourceNodeAt(src,"a.foo")
     root = createSourceNodeAt(testdata.TheClass, "a.b.bah")
     module = getModuleOrPackageUsingFQN("a.foo")
     res =  getTypeOf(module,"a")
     assert isinstance(res,Instance)
     assert isinstance(res.getType(),Class)
     assert res.getType().name == "TheClass"
Esempio n. 10
0
 def test_getsTypeOfImportedClassReference(self):
     src = trimLines("""
     import b.bah
     a = b.bah.TheClass()
     """)
     root = createSourceNodeAt(src, "a.foo")
     root = createSourceNodeAt(testdata.TheClass, "a.b.bah")
     module = getModuleUsingFQN("a.foo", [pkgstructureRootDir])
     res = getTypeOf(module, "a", [pkgstructureRootDir])
     assert isinstance(res, Instance)
     assert isinstance(res.getType(), Class)
     assert res.getType().name == "TheClass"
Esempio n. 11
0
 def test_doesntGetTypeDefinedInChildFunction(self):
     src = trimLines("""
     from b.bah import TheClass
     a = AnotherClass()
     def foo():
         a = TheClass()
     a.theMethod()
     """)
     root = createSourceNodeAt(src,"a.foo")
     root = createSourceNodeAt(testdata.TheClass, "a.b.bah")
     
     themodule = getModuleOrPackageUsingFQN("a.foo")
     assert isinstance(getTypeOf(themodule,"a"),UnfoundType)
Esempio n. 12
0
 def test_doesntGetTypeDefinedInChildFunction(self):
     src = trimLines("""
     from b.bah import TheClass
     a = AnotherClass()
     def foo():
         a = TheClass()
     a.theMethod()
     """)
     root = createSourceNodeAt(src,"a.foo")
     root = createSourceNodeAt(testdata.TheClass, "a.b.bah")
     
     themodule = getModuleUsingFQN("a.foo",[pkgstructureRootDir])
     assert getTypeOf(themodule,"a",[pkgstructureRootDir]) is None
Esempio n. 13
0
 def test_getsTypeOfSimpleClassInstanceReference(self):
     src = trimLines("""
     from b.bah import TheClass
     a = TheClass()
     a.theMethod()
     """)
     root = createSourceNodeAt(src,"a.foo")
     root = createSourceNodeAt(testdata.TheClass, "a.b.bah")
     module = getModuleOrPackageUsingFQN("a.foo")
     res =  getTypeOf(module,"a")
     assert isinstance(res,Instance)
     assert isinstance(res.getType(),Class)
     assert res.getType().name == "TheClass"
Esempio n. 14
0
    def test_doesntGetTypeDefinedInChildFunction(self):
        src = trimLines("""
        from b.bah import TheClass
        a = AnotherClass()
        def foo():
            a = TheClass()
        a.theMethod()
        """)
        root = createSourceNodeAt(src, "a.foo")
        root = createSourceNodeAt(testdata.TheClass, "a.b.bah")

        themodule = getModuleUsingFQN("a.foo", [pkgstructureRootDir])
        assert getTypeOf(themodule, "a", [pkgstructureRootDir]) is None
Esempio n. 15
0
 def test_returnsEndLineWithSimpleFunction(self):
     src = trimLines("""
     class TheClass:
         def theMethod():
             pass
     def foo():
         b = TheClass()
         return b
     a = foo()
     a.theMethod()
     """)
     root = fastparser(src)
     fn = getTypeOf(root, "foo")
     self.assertEqual(fn.getEndLine(), 7)
 def test_returnsEndLineWithSimpleFunction(self):
     src = trimLines("""
     class TheClass:
         def theMethod():
             pass
     def foo():
         b = TheClass()
         return b
     a = foo()
     a.theMethod()
     """)
     root = fastparser(src)
     fn = getTypeOf(root,"foo")
     self.assertEqual(fn.getEndLine(),7)
Esempio n. 17
0
 def test_worksWithFunctionsThatHaveEmptyLinesInThem(self):
     src = fnWithEmptyLineInIt
     root = fastparser(src)
     fn = getTypeOf(root, "TheClass.theFunction")
     self.assertEqual(fn.getEndLine(), 8)
 def test_worksWithFunctionsThatHaveEmptyLinesInThem(self):
     src = fnWithEmptyLineInIt
     root = fastparser(src)
     fn = getTypeOf(root,"TheClass.theFunction")
     self.assertEqual(fn.getEndLine(),8)