Exemple #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)))
Exemple #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)))
Exemple #3
0
 def testReadBadNesting(self):
     with self.assertRaises(AttributeError):
         signatures.read_type('([int)]', self.scope)
Exemple #4
0
 def testReadComplexDict(self):
     self.assertEqual(
         signatures.read_type('{(int):{float}}', self.scope),
         compound.InferredDict([compound.InferredTuple(self.int)],
                               [compound.InferredSet(self.float)]))
Exemple #5
0
 def testReadDict(self):
     self.assertEqual(signatures.read_type('{int:float}', self.scope),
                      compound.InferredDict([self.int], [self.float]))
Exemple #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))
Exemple #7
0
 def testReadTuple(self):
     self.assertEqual(signatures.read_type('(int)', self.scope),
                      compound.InferredTuple(self.int))
Exemple #8
0
 def testReadNestedList(self):
     self.assertEqual(
         signatures.read_type('[[int] | float]', self.scope),
         compound.InferredList(compound.InferredList(self.int), self.float))
Exemple #9
0
 def testReadComplexList(self):
     self.assertEqual(signatures.read_type('[int | float]', self.scope),
                      compound.InferredList(self.int, self.float))
Exemple #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))
Exemple #11
0
 def testReadTypeBad(self):
     with self.assertRaises(AttributeError):
         signatures.read_type('plib', self.scope)