Beispiel #1
0
def test_object_resolver_error():
    from _pydevd_bundle.pydevd_resolver import DefaultResolver
    default_resolver = DefaultResolver()

    class MyObject(object):
        def __init__(self):
            self.a = 10

        def __dir__(self):
            return ['a', 'b']

        def __getattribute__(self, attr_name):
            if attr_name == 'b':
                raise RuntimeError('unavailable')
            return object.__getattribute__(self, attr_name)

    obj = MyObject()
    dictionary = default_resolver.get_dictionary(obj)
    b_value = dictionary.pop('b')
    assert dictionary == {'a': 10}
    assert "raise RuntimeError('unavailable')" in b_value

    contents_debug_adapter_protocol = default_resolver.get_contents_debug_adapter_protocol(
        obj)
    b_value = contents_debug_adapter_protocol.pop(-1)
    assert contents_debug_adapter_protocol == [('a', 10, '.a')]
    assert b_value[0] == 'b'
    assert "raise RuntimeError('unavailable')" in b_value[1]
    assert b_value[2] == '.b'
Beispiel #2
0
def test_object_resolver__dict__non_strings():
    from _pydevd_bundle.pydevd_resolver import DefaultResolver
    default_resolver = DefaultResolver()

    class MyObject(object):
        def __init__(self):
            self.__dict__[(1, 2)] = (3, 4)

    obj = MyObject()
    dictionary = default_resolver.get_dictionary(obj)
    if IS_PY2:
        assert 'attribute name must be string' in dictionary.pop('(1, 2)')
        assert dictionary == {}
    else:
        assert dictionary == {'(1, 2)': (3, 4)}

    contents_debug_adapter_protocol = default_resolver.get_contents_debug_adapter_protocol(
        obj)
    if IS_PY2:
        assert len(contents_debug_adapter_protocol) == 1
        entry = contents_debug_adapter_protocol[0]
        assert entry[0] == '(1, 2)'
        assert 'attribute name must be string' in entry[1]
        assert entry[2] == '.(1, 2)'
    else:
        assert contents_debug_adapter_protocol == [('(1, 2)', (3, 4),
                                                    '.__dict__[(1, 2)]')]
def test_object_resolver__dict__non_strings():
    from _pydevd_bundle.pydevd_resolver import DefaultResolver
    default_resolver = DefaultResolver()

    class MyObject(object):

        def __init__(self):
            self.__dict__[(1, 2)] = (3, 4)

    obj = MyObject()
    dictionary = default_resolver.get_dictionary(obj)
    if IS_PY2:
        assert 'attribute name must be string' in dictionary.pop('(1, 2)')
        assert dictionary == {}
    else:
        assert dictionary == {'(1, 2)': (3, 4)}

    contents_debug_adapter_protocol = default_resolver.get_contents_debug_adapter_protocol(obj)
    if IS_PY2:
        assert len(contents_debug_adapter_protocol) == 1
        entry = contents_debug_adapter_protocol[0]
        assert entry[0] == '(1, 2)'
        assert 'attribute name must be string' in entry[1]
        assert entry[2] == '.(1, 2)'
    else:
        assert contents_debug_adapter_protocol == [('(1, 2)', (3, 4), '.__dict__[(1, 2)]')]
def test_object_resolver_error():
    from _pydevd_bundle.pydevd_resolver import DefaultResolver
    default_resolver = DefaultResolver()

    class MyObject(object):

        def __init__(self):
            self.a = 10

        def __dir__(self):
            return ['a', 'b']

        def __getattribute__(self, attr_name):
            if attr_name == 'b':
                raise RuntimeError('unavailable')
            return object.__getattribute__(self, attr_name)

    obj = MyObject()
    dictionary = default_resolver.get_dictionary(obj)
    b_value = dictionary.pop('b')
    assert dictionary == {'a': 10}
    assert "raise RuntimeError('unavailable')" in b_value

    contents_debug_adapter_protocol = default_resolver.get_contents_debug_adapter_protocol(obj)
    b_value = contents_debug_adapter_protocol.pop(-1)
    assert contents_debug_adapter_protocol == [('a', 10, '.a')]
    assert b_value[0] == 'b'
    assert "raise RuntimeError('unavailable')" in b_value[1]
    assert b_value[2] == '.b'
Beispiel #5
0
def test_object_resolver_hasattr_error():
    from _pydevd_bundle.pydevd_resolver import DefaultResolver
    from _pydevd_bundle.pydevd_xml import get_type
    default_resolver = DefaultResolver()

    class MyObject(object):
        def __getattribute__(self, attr_name):
            raise RuntimeError()

    obj = MyObject()
    dictionary = default_resolver.get_dictionary(obj)
    assert dictionary == {}

    _type_object, type_name, _resolver = get_type(obj)
    assert type_name == 'MyObject'
def test_object_resolver_simple():
    from _pydevd_bundle.pydevd_resolver import DefaultResolver
    default_resolver = DefaultResolver()

    class MyObject(object):

        def __init__(self):
            self.a = 10
            self.b = 20

    obj = MyObject()
    dictionary = default_resolver.get_dictionary(obj)
    assert dictionary == {'a': 10, 'b': 20}

    contents_debug_adapter_protocol = default_resolver.get_contents_debug_adapter_protocol(obj)
    assert contents_debug_adapter_protocol == [('a', 10, '.a'), ('b', 20, '.b')]
def test_object_resolver_simple():
    from _pydevd_bundle.pydevd_resolver import DefaultResolver
    default_resolver = DefaultResolver()

    class MyObject(object):

        def __init__(self):
            self.a = 10
            self.b = 20

    obj = MyObject()
    dictionary = default_resolver.get_dictionary(obj)
    assert dictionary == {'a': 10, 'b': 20}

    contents_debug_adapter_protocol = default_resolver.get_contents_debug_adapter_protocol(obj)
    assert contents_debug_adapter_protocol == [('a', 10, '.a'), ('b', 20, '.b')]