def testFindFullScopesHangingScope(self): #a = 1 #def b(f): # pass scp1 = scopes.Scope('__main__',0,-1, line_end=3) scp2 = scopes.Scope('def',2,0, parent=scp1) lines = [(0,0),(1,0),(2,4)] new_scopes = list(scp1.create_scope_list(lines)) self.assertEqual(new_scopes[1].line_end,3)
def getType(self, expr, context=None): if context is None: context = scopes.Scope('__test__', 0, -1) return expressions.get_expression_type(expr, context)
def testScopeListFailsOutsideArea(self): s = scopes.ScopeList() dcta = {'a':int} s.add(scopes.Scope('name',line_start=0, indent=4, line_end=10, context=dcta)) self.assertIsNone(s.get_scope(12,0))
def testIndentedScopeMatches(self): sc = scopes.Scope('name', line_start=0, indent=0, line_end=100) self.assertTrue(sc.matches(50,4))
def testScopeListFailsWithWrongIndent(self): s = scopes.ScopeList() dcta = {'a':int} s.add(scopes.Scope('name',line_start=0, indent=4, line_end=10, context=dcta)) self.assertIsNone(s.get_scope(5,0))
def checkScope(self, scope_list, position, match): s = scopes.ScopeList() for scope in scope_list: s.add(scopes.Scope(*scope)) result = s.get_scope(*position) self.assertEqual(result.context,match)
def testBaseScopeMatches(self): sc = scopes.Scope('name', line_start=0, indent=-1, line_end=100) self.assertTrue(sc.matches(50,0))
def testScopeTrees(self): sc1 = scopes.Scope('sc1', line_start=0, indent=-1) sc2 = scopes.Scope('sc2', line_start=4, indent=0, parent=sc1) self.assertIn(sc2,sc1.get_all_children())
def testOutsideScopeDoesNotMatch(self): sc = scopes.Scope('name', line_start=0, indent=0, line_end=10) self.assertFalse(sc.matches(50,0))