How to use vulture - 10 common examples

To help you get started, we’ve selected a few vulture 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 jendrikseipp / vulture / tests / test_conditions.py View on Github external
('foo or False', False, False),
        ('foo and True', False, False),
        ('foo or True', False, True),
        ('False and foo', True, False),
        ('False and 1', True, False),
        ('not False', False, True),
        ('not True', True, False),
        ('not foo', False, False),
        ('foo and (False or [])', True, False),
        ('(foo and bar) or {"a": 1}', False, True),
    ]
    for condition, always_false, always_true in conditions:
        condition = ast.parse(condition, mode='eval').body
        assert not (always_false and always_true)
        assert utils.condition_is_always_false(condition) == always_false
        assert utils.condition_is_always_true(condition) == always_true
github jendrikseipp / vulture / tests / test_utils.py View on Github external
def visit_FunctionDef(node):
        for decorator in node.decorator_list:
            decorator_names.append(utils.get_decorator_name(decorator))
github jendrikseipp / vulture / tests / test_conditions.py View on Github external
def check_condition(code, result):
    condition = ast.parse(code, mode='eval').body
    if result:
        assert utils.condition_is_always_true(condition)
    else:
        assert utils.condition_is_always_false(condition)
github jendrikseipp / vulture / tests / test_unsatisfiable.py View on Github external
def check_condition(code, unsatisfiable=True):
    condition = ast.parse(code, mode='eval')
    assert utils.condition_is_unsatisfiable(condition) == unsatisfiable
github jendrikseipp / vulture / tests / test_conditions.py View on Github external
def test_errors():
    conditions = [
        'foo',
        '__name__ == "__main__"',
        'chr(-1)',
        'getattr(True, "foo")',
        'hasattr(str, "foo")',
        'isinstance(True, True)',
        'globals()',
        'locals()',
        '().__class__',
    ]
    for condition in conditions:
        condition = ast.parse(condition, mode='eval').body
        assert not utils.condition_is_always_false(condition)
        assert not utils.condition_is_always_true(condition)
github jendrikseipp / vulture / tests / test_conditions.py View on Github external
('foo and False', True, False),
        ('foo or False', False, False),
        ('foo and True', False, False),
        ('foo or True', False, True),
        ('False and foo', True, False),
        ('False and 1', True, False),
        ('not False', False, True),
        ('not True', True, False),
        ('not foo', False, False),
        ('foo and (False or [])', True, False),
        ('(foo and bar) or {"a": 1}', False, True),
    ]
    for condition, always_false, always_true in conditions:
        condition = ast.parse(condition, mode='eval').body
        assert not (always_false and always_true)
        assert utils.condition_is_always_false(condition) == always_false
        assert utils.condition_is_always_true(condition) == always_true
github jendrikseipp / vulture / tests / test_conditions.py View on Github external
def check_condition(code, result):
    condition = ast.parse(code, mode='eval').body
    if result:
        assert utils.condition_is_always_true(condition)
    else:
        assert utils.condition_is_always_false(condition)
github jendrikseipp / vulture / tests / test_conditions.py View on Github external
def test_errors():
    conditions = [
        'foo',
        '__name__ == "__main__"',
        'chr(-1)',
        'getattr(True, "foo")',
        'hasattr(str, "foo")',
        'isinstance(True, True)',
        'globals()',
        'locals()',
        '().__class__',
    ]
    for condition in conditions:
        condition = ast.parse(condition, mode='eval').body
        assert not utils.condition_is_always_false(condition)
        assert not utils.condition_is_always_true(condition)
github jendrikseipp / vulture / tests / test_confidence.py View on Github external
def check_min_confidence(code, min_confidence, expected):
    v = core.Vulture(verbose=True)
    v.scan(code)
    detected = {
        item.name: item.confidence
        for item in v.get_unused_code(min_confidence=min_confidence)}
    assert detected == expected
github jendrikseipp / vulture / tests / __init__.py View on Github external
def v():
    return core.Vulture(verbose=True)