def testComplexClassMemberAssignment(self): a = itypes.ClassType('A', [], '') a.add_attr('x', itypes.TypeSet(self.int)) b = itypes.ClassType('B', [], '') context = {'C': itypes.TypeSet(a, b)} assignment.assign_to_node('C.x', itypes.TypeSet(self.str), context) self.assertEqual(a.get_attr('x'), '<int> | <str>') self.assertEqual(b.get_attr('x'), '<str>')
def getStarredContext(self): f = itypes.FunctionType('f', ['a', 'b'], itypes.UnknownType('b'), "") tpl = itypes.create_tuple(self.int, self.float) lst = itypes.create_list(self.int, self.str) ts = itypes.TypeSet(tpl, lst) context = {'f': f, 'lst': lst, 'tpl': tpl, 'ts': ts} return context
def testUnknownResponse(self): f = itypes.FunctionType( 'f', ['a', 'b'], itypes.TypeSet(itypes.UnknownType('a'), itypes.UnknownType('b')), "") context = {'f': f} self.checkExpr("f()", "Unknown", context=context)
def testComplexContingentFunctionCall(self): f = itypes.FunctionType( 'f', ['a', 'b'], itypes.TypeSet(itypes.UnknownType('a'), itypes.UnknownType('b')), "") context = {'f': f} self.checkExpr("f(1, 'str')", "<int> | <str>", context=context)
def testListSliceTotalAssignment(self): context = {'l': itypes.TypeSet(itypes.create_list(self.int))} l2 = itypes.TypeSet(itypes.create_list(self.str)) assignment.assign_to_node('l[:]', l2, context) self.assertEqual(context, {'l': '[<int> | <str>]'})
def testListIndexAssigment(self): """Test assignment to a list index works""" context = {'l': itypes.TypeSet(itypes.create_list(self.int))} assignment.assign_to_node('l[0]', self.str, context) self.assertEqual(context, {'l': '[<int> | <str>]'})
def testClassMemberAssignment(self): context = {'C': itypes.TypeSet(itypes.ClassType('C', [], ''))} assignment.assign_to_node('C.x', itypes.TypeSet(self.int), context) self.assertEqual(context['C'].get_attr('x'), '<int>')
def testSimpleAssignment(self): context = {} assignment.assign_to_node('a', itypes.TypeSet(self.int), context) self.assertEqual({'a': '<int>'}, context)