Esempio n. 1
0
 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>')
Esempio n. 2
0
 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
Esempio n. 3
0
 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)
Esempio n. 4
0
 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)
Esempio n. 5
0
 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>]'})
Esempio n. 6
0
 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>]'})
Esempio n. 7
0
 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>')
Esempio n. 8
0
 def testSimpleAssignment(self):
     context = {}
     assignment.assign_to_node('a', itypes.TypeSet(self.int), context)
     self.assertEqual({'a': '<int>'}, context)