Exemplo n.º 1
0
def test_descriptor():
    class T:
        r = RevealAccess(10, 'var ' r'')

        def __init__(self):
            self.d = D()

        @property
        def p(self):
            'this is p'
            return 1

        @p.setter
        def p(self):
            pass

        @p.deleter
        def p(self):
            pass

    t = T()
    pattrs = pdir(t).pattrs
    for pattr in pattrs:
        if pattr.name == 'd':
            assert category_match(pattr.category, AttrCategory.DESCRIPTOR)
            assert pattr.doc == ('class D with getter, setter, deleter, '
                                 'this is D')
        if pattr.name == 'r':
            assert category_match(pattr.category, AttrCategory.DESCRIPTOR)
            assert pattr.doc == ('class RevealAccess with getter, setter, '
                                 'deleter, this is R')
        if pattr.name == 'p':
            assert category_match(pattr.category, AttrCategory.DESCRIPTOR)
            assert pattr.doc == ('@property with getter, setter, '
                                 'deleter, this is p')
Exemplo n.º 2
0
def test_set_derive():
    c_types = [DeriveSlotBaseNo, DeriveSlotBaseEmpty, DeriveSlotBaseSlot]
    for c_type in c_types:
        instance = c_type()
        instance.derive = 'foo'
        for attr in pdir(instance).pattrs:
            if attr.name == DERIVE:
                assert category_match(attr.category, AttrCategory.DESCRIPTOR)
                assert category_match(attr.category, AttrCategory.SLOT)
                break
        else:
            # No derive attribute found
            assert False
Exemplo n.º 3
0
def test_dataframe():
    from pandas import DataFrame

    result = pdir(DataFrame)
    for attr in result.pattrs:
        if attr.name in ('columns', 'index'):
            assert category_match(attr.category, AttrCategory.PROPERTY)
Exemplo n.º 4
0
def test_dataframe():
    pandas = pytest.importorskip("pandas")

    result = pdir(pandas.DataFrame)
    for attr in result.pattrs:
        if attr.name in ('columns', 'index'):
            assert category_match(attr.category, AttrCategory.PROPERTY)
Exemplo n.º 5
0
def test_not_set():
    expected_res = [  # class type    empty slot attr num
        (DeriveNoSlotBaseEmpty, 0),
        (DeriveNoSlotBaseSlot, 1),
        (DeriveEmptySlotBaseNo, 0),
        (DeriveEmptySlotBaseEmpty, 0),
        (DeriveEmptySlotBaseSlot, 1),
        (DeriveSlotBaseNo, 1),
        (DeriveSlotBaseEmpty, 1),
        (DeriveSlotBaseSlot, 2),
    ]
    for c_type, attr_num in expected_res:
        attr_count = 0
        for attr in pdir(c_type()).pattrs:
            if attr.name in [BASE, DERIVE]:
                attr_count += 1
                assert category_match(attr.category, AttrCategory.DESCRIPTOR)
                assert category_match(attr.category, AttrCategory.SLOT)
        assert attr_count == attr_num
Exemplo n.º 6
0
def test_list():
    result = pdir(list)
    for attr in result.pattrs:
        if attr.name == 'append':
            assert category_match(attr.category, AttrCategory.FUNCTION)
            return
Exemplo n.º 7
0
def test_type():
    result = pdir(type)
    for attr in result.pattrs:
        if attr.name == '__abstractmethods__':
            assert category_match(attr.category, AttrCategory.ABSTRACT_CLASS)
            return