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