How to use the hunter.util.safe_repr function in hunter

To help you get started, we’ve selected a few hunter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ionelmc / python-hunter / tests / test_util.py View on Github external
def test_safe_repr():
    data = {
        'a': [set('b')],
        ('c',): deque(['d']),
        'e': _socket.socket(),
        1: array('d', [1, 2]),
        frozenset('f'): socket(),
        'g': Dict({
            'a': List('123'),
            'b': Set([Decimal('1.0')]),
            'c': Stuff(1, 2),
            'd': Exception(1, 2, {
                'a': safe_repr,
                'b': Foobar,
                'c': Bad2(),
                'ct': Bad2,
            })
        }),
        'od': OrderedDict({'a': 'b'}),
        'nt': MyTuple(1, 2),
        'bad1': Bad1().method,
        'bad2': Bad2().method
    }
    print(safe_repr(data))
    print(safe_repr([data]))
    print(safe_repr([[data]]))
    print(safe_repr([[[data]]]))
    print(safe_repr([[[[data]]]]))
    print(safe_repr([[[[[data]]]]]))
github ionelmc / python-hunter / tests / test_util.py View on Github external
'ct': Bad2,
            })
        }),
        'od': OrderedDict({'a': 'b'}),
        'nt': MyTuple(1, 2),
        'bad1': Bad1().method,
        'bad2': Bad2().method
    }
    print(safe_repr(data))
    print(safe_repr([data]))
    print(safe_repr([[data]]))
    print(safe_repr([[[data]]]))
    print(safe_repr([[[[data]]]]))
    print(safe_repr([[[[[data]]]]]))

    assert safe_repr(py.io).startswith('
github ionelmc / python-hunter / tests / test_util.py View on Github external
'a': List('123'),
            'b': Set([Decimal('1.0')]),
            'c': Stuff(1, 2),
            'd': Exception(1, 2, {
                'a': safe_repr,
                'b': Foobar,
                'c': Bad2(),
                'ct': Bad2,
            })
        }),
        'od': OrderedDict({'a': 'b'}),
        'nt': MyTuple(1, 2),
        'bad1': Bad1().method,
        'bad2': Bad2().method
    }
    print(safe_repr(data))
    print(safe_repr([data]))
    print(safe_repr([[data]]))
    print(safe_repr([[[data]]]))
    print(safe_repr([[[[data]]]]))
    print(safe_repr([[[[[data]]]]]))

    assert safe_repr(py.io).startswith('
github ionelmc / python-hunter / tests / test_util.py View on Github external
'b': Foobar,
                'c': Bad2(),
                'ct': Bad2,
            })
        }),
        'od': OrderedDict({'a': 'b'}),
        'nt': MyTuple(1, 2),
        'bad1': Bad1().method,
        'bad2': Bad2().method
    }
    print(safe_repr(data))
    print(safe_repr([data]))
    print(safe_repr([[data]]))
    print(safe_repr([[[data]]]))
    print(safe_repr([[[[data]]]]))
    print(safe_repr([[[[[data]]]]]))

    assert safe_repr(py.io).startswith('
github ionelmc / python-hunter / tests / test_util.py View on Github external
issubclass(Plain, type(type(Foobar)))
    assert side_effects == ['Meta.__class__', 'MetaMeta.__class__', 'Meta.__subclasscheck__', 'MetaMeta.__subclasscheck__']

    del side_effects[:]

    issubclass(getattr_static(SubFoobar(), '__class__'), Foobar)
    assert side_effects[-1] == 'Meta.__subclasscheck__'

    del side_effects[:]

    getattr_static(type(SubFoobar()), '__instancecheck__')
    getattr_static(type(SubFoobar()), '__subclasscheck__')
    assert not side_effects

    safe_repr(Foobar())
    safe_repr(Foobar)
    assert not side_effects
github ionelmc / python-hunter / tests / test_util.py View on Github external
issubclass(Plain, type(Foobar))
    issubclass(Plain, type(type(Foobar)))
    assert side_effects == ['Meta.__class__', 'MetaMeta.__class__', 'Meta.__subclasscheck__', 'MetaMeta.__subclasscheck__']

    del side_effects[:]

    issubclass(getattr_static(SubFoobar(), '__class__'), Foobar)
    assert side_effects[-1] == 'Meta.__subclasscheck__'

    del side_effects[:]

    getattr_static(type(SubFoobar()), '__instancecheck__')
    getattr_static(type(SubFoobar()), '__subclasscheck__')
    assert not side_effects

    safe_repr(Foobar())
    safe_repr(Foobar)
    assert not side_effects