Example #1
0
    def test_unknown(self):
        unknown = Unknown()
        self.assertEqual(str(unknown), 'Unknown')
        self.assertEqual(repr(unknown), 'Unknown()')

        self.assertEqual(unknown, Unknown())
        self.assertNotEqual(unknown, self.int)
Example #2
0
 def test_combine_special_cases(self):
     i = self.int
     f = self.float
     u = Unknown()
     def list_(x):
         return Generic('List', [x])
     # Simplify generic types.
     self.assert_combine(list_(i), list_(u), list_(i))
Example #3
0
    def test_combine_types(self):
        i = self.int
        f = self.float
        s = Instance(str)
        c = Instance(complex)

        class Foo:
            pass

        o = Instance(Foo)

        # Simple types
        self.assert_combine(i, i, i)
        self.assert_combine(s, s, s)
        self.assert_combine(i, s, Union((i, s)))
        self.assert_combine(i, None, Union((i, None)))
        # Unknowns
        self.assert_combine(i, Unknown(), i)
        self.assert_combine(Unknown(), Unknown(), Unknown())
        # Union types
        self.assert_combine(o, Union((f, s)), Union((o, f, s)))
        self.assert_combine(i, Union((i, s)), Union((i, s)))
        self.assert_combine(Union((o, f)), Union((o, s)), Union((o, f, s)))
        # Tuple types
        self.assert_combine(Tuple([i, i]), Tuple([i, i]), Tuple([i, i]))
        self.assert_combine(Tuple([i, i]), Tuple([o, s]),
                            Tuple([Union([o, i]), Union([s, i])]))
        # Numeric types
        self.assert_combine(i, f, f)
        self.assert_combine(i, c, c)
        self.assert_combine(c, f, c)
        # Unions with numerics
        self.assert_combine(i, Union((o, f)), Union((o, f)))
        self.assert_combine(Union((o, f)), i, Union((o, f)))
        self.assert_combine(Union((o, i)), f, Union((o, f)))
        # Tuples with numerics
        self.assert_combine(Tuple([i, i]), Tuple([f, i]), Tuple([f, i]))
        self.assert_combine(Tuple([i, i]), Tuple([f, o]),
                            Tuple([f, Union((i, o))]))
        self.assert_combine(Tuple([f, i]), Tuple([i, o]),
                            Tuple([f, Union((i, o))]))