Esempio n. 1
0
 def test_works_with_Type_function(self):
     from typecheck import Type, Function
     
     def foo(*vargs):
         return vargs
     
     assert isinstance(Type(foo), Function)
Esempio n. 2
0
 def test_works_with_Type_instancemethod_classic(self):
     from typecheck import Type, Function
     
     class Foo:
         def foo(*vargs):
             return vargs
     
     assert isinstance(Type(Foo().foo), Function)
Esempio n. 3
0
 def test_works_with_Type_call_method_classic(self):
     from typecheck import Type, Function
     
     class Foo:
         def __call__(self, *vargs):
             return vargs
     
     assert isinstance(Type(Foo()), Function)
Esempio n. 4
0
    def test_works_with_Type_instancemethod_newstyle(self):
        from typecheck import Type, CheckerFunction

        class Foo(object):
            def foo(self, *vargs):
                return vargs

        assert isinstance(Type(Foo().foo), CheckerFunction)
Esempio n. 5
0
 def test_works_with_Type_staticmethod_newstyle(self):
     from typecheck import Type, Function
     
     class Foo(object):
         @staticmethod
         def foo(*vargs):
             return vargs
     
     assert isinstance(Type(Foo.foo), Function)
Esempio n. 6
0
    def test_works_with_Type_staticmethod_classic(self):
        from typecheck import Type, CheckerFunction

        class Foo:
            @staticmethod
            def foo(*vargs):
                return vargs

        assert isinstance(Type(Foo.foo), CheckerFunction)
Esempio n. 7
0
 def __init__(self, set_list):
     self.type = set(set_list)
     self._types = [Type(t) for t in self.type]
     
     # self._type is used to build _TC_TypeError
     if len(self._types) > 1:
         self._type = Or(*self.type)
     elif len(self._types) == 1:
         # XXX Is there an easier way to get this?
         t = self.type.pop()
         self._type = t
         self.type.add(t)
Esempio n. 8
0
    def test_Type_uses_it(self):
        from typecheck import Type

        t = Type(set([int, float]))
        assert isinstance(t, Set)
Esempio n. 9
0
 def __init__(self, *types):
     #import ipdb; ipdb.set_trace()
     if not types:
         raise TypeError("Must supply at least one type to __init__()")
     self._types = [Type(t) for t in types]
     self.type = [t.type for t in self._types]
Esempio n. 10
0
 def __init__(self, val):
     self._type = Type(val)
     self.type = self
Esempio n. 11
0
    def test_used_by_Type(self):
        from typecheck import Type
        from typecheck.mixins import _UnorderedIteratorMixin

        uim = Type(self.Iter(float, int))
        assert isinstance(uim, _UnorderedIteratorMixin)