Beispiel #1
0
 def test_works_with_Type_function(self):
     from typecheck import Type, Function
     
     def foo(*vargs):
         return vargs
     
     assert isinstance(Type(foo), Function)
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #8
0
    def test_Type_uses_it(self):
        from typecheck import Type

        t = Type(set([int, float]))
        assert isinstance(t, Set)
Beispiel #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]
Beispiel #10
0
 def __init__(self, val):
     self._type = Type(val)
     self.type = self
Beispiel #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)