class A():
        def m(self):
            pass

        w = Callable(m)
        assert w.is_barefunction is False
        assert w.is_descriptor is False
        assert w.is_membermethod is True
        assert w.is_classmethod is False

        @classmethod
        def c(cls):
            pass

        w = Callable(c)
        assert w.is_barefunction is False
        assert w.is_descriptor is True
        assert w.is_membermethod is False
        assert w.is_classmethod is True

        @staticmethod
        def s():
            pass

        w = Callable(s)
        assert w.is_barefunction is False
        assert w.is_descriptor is True
        assert w.is_membermethod is False
        assert w.is_classmethod is False
Exemple #2
0
def test_code():
    def f(a):
        pass  # noqa

    assert Callable(f).code.co_name == 'f'

    h = asyncio.coroutine(f)
    assert Callable(h).code.co_name == 'f'
Exemple #3
0
def test_annotations():
    def f(a: int, b: str, *c, d: Any = 10, **e) -> Optional[float]:
        pass

    c = Callable(f)
    assert c.annotations == {
        'a': int,
        'b': str,
        'd': Any,
        'return': Optional[float]
    }
def test_empty_annotations():
    c = Callable(lambda a, *b, **c: None)
    assert c.annotations == {}
def test_kwargify_exc(f, args, kwargs, exc):
    with pytest.raises(exc):
        Callable(f).kwargify(args, kwargs)
def test_kwargify(f, args, kwargs, merged):
    kwargified = Callable(f).kwargify(args, kwargs)
    print(kwargified)
    print(merged)
    assert kwargified == merged
Exemple #7
0
def test_make_labels_exc(f, pargs, exc):
    with pytest.raises(exc):
        pargs.labels(Callable(f))
Exemple #8
0
def test_make_labels(f, pargs, merged):
    kwargified = pargs.labels(Callable(f))
    assert kwargified == merged