示例#1
0
 def testReadTypeSimple(self):
     for i in ('int', 'str', 'bytes', 'float', 'complex', 'bool'):
         self.assertEqual(signatures.read_type(i, self.scope),
                          builtins.get_type_by_name('<{}>'.format(i)))
         self.assertEqual(signatures.read_type(i + ' ', self.scope),
                          builtins.get_type_by_name('<{}>'.format(i)))
         self.assertEqual(signatures.read_type(' ' + i + ' ', self.scope),
                          builtins.get_type_by_name('<{}>'.format(i)))
         self.assertEqual(signatures.read_type(' ' + i, self.scope),
                          builtins.get_type_by_name('<{}>'.format(i)))
示例#2
0
 def testReadVeryComplexType(self):
     self.assertEqual(
         signatures.read_type('(int, {int | float}, [int | str])',
                              self.scope),
         compound.InferredTuple(self.int,
                                compound.InferredSet(self.int, self.float),
                                compound.InferredList(self.int, self.str)))
示例#3
0
 def testReadBadNesting(self):
     with self.assertRaises(AttributeError):
         signatures.read_type('([int)]', self.scope)
示例#4
0
 def testReadComplexDict(self):
     self.assertEqual(
         signatures.read_type('{(int):{float}}', self.scope),
         compound.InferredDict([compound.InferredTuple(self.int)],
                               [compound.InferredSet(self.float)]))
示例#5
0
 def testReadDict(self):
     self.assertEqual(signatures.read_type('{int:float}', self.scope),
                      compound.InferredDict([self.int], [self.float]))
示例#6
0
 def testReadComplexTuple(self):
     self.assertEqual(signatures.read_type('(int, float)', self.scope),
                      compound.InferredTuple(self.int, self.float))
     self.assertNotEqual(signatures.read_type('(float, int)', self.scope),
                         compound.InferredTuple(self.int, self.float))
示例#7
0
 def testReadTuple(self):
     self.assertEqual(signatures.read_type('(int)', self.scope),
                      compound.InferredTuple(self.int))
示例#8
0
 def testReadNestedList(self):
     self.assertEqual(
         signatures.read_type('[[int] | float]', self.scope),
         compound.InferredList(compound.InferredList(self.int), self.float))
示例#9
0
 def testReadComplexList(self):
     self.assertEqual(signatures.read_type('[int | float]', self.scope),
                      compound.InferredList(self.int, self.float))
示例#10
0
 def testReadTypeSet(self):
     self.assertEqual(signatures.read_type('int | str | float', self.scope),
                      basics.TypeSet(self.int, self.str, self.float))
     self.assertEqual(signatures.read_type('int|str|float', self.scope),
                      basics.TypeSet(self.int, self.str, self.float))
示例#11
0
 def testReadTypeBad(self):
     with self.assertRaises(AttributeError):
         signatures.read_type('plib', self.scope)