示例#1
0
 def testAssignmentToStarredFromList(self):
     context = {}
     mytuple = itypes.create_list(self.int, self.str, self.float)
     assignment.assign_to_node('(a, *b)', mytuple, context)
     self.assertEqual(context, {
         'a': '<float> | <int> | <str>',
         'b': '[<float> | <int> | <str>]'
     })
示例#2
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>')
示例#3
0
 def testAssignmentToStarredFromStarred(self):
     context = {
         'x': self.int,
         'y': itypes.create_tuple(self.float, self.str, self.int)
     }
     assignment.assign_to_node('(a, b, *c)', '(x, *y)', context)
     self.assertEqual(context['a'], '<int>')
     self.assertEqual(context['b'], '<float>')
     self.assertEqual(context['c'], '[<int> | <str>]')
示例#4
0
 def testMultipleAssignmentFromTuple(self):
     context = {}
     mytuple = itypes.create_tuple(self.int, self.str)
     assignment.assign_to_node('a, b', mytuple, context)
     self.assertEqual(context, {'a': '<int>', 'b': '<str>'})
示例#5
0
 def testMultipleAssignmentFromList(self):
     context = {}
     mylist = itypes.create_list(self.int, self.str)
     assignment.assign_to_node('a, b', mylist, context)
     self.assertEqual(context, {'a': '<int> | <str>', 'b': '<int> | <str>'})
示例#6
0
 def testCallResultAssignmentDoesNothing(self):
     context = {'l': self.int}
     assignment.assign_to_node('l()', self.str, context)
     self.assertEqual(context, {'l': '<int>'})
示例#7
0
 def testDictIndexAssignment(self):
     context = {'d': itypes.create_dict([self.str], [self.int])}
     assignment.assign_to_node("d['abc']", self.float, context)
     self.assertEqual(context, {'d': '{<str>: <float> | <int>}'})
示例#8
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>]'})
示例#9
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>]'})
示例#10
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>')
示例#11
0
 def testSimpleAssignment(self):
     context = {}
     assignment.assign_to_node('a', itypes.TypeSet(self.int), context)
     self.assertEqual({'a': '<int>'}, context)