def test_wrong_variable_usage( assert_errors, parse_ast_tree, bad_name, code, default_options, ): """Testing that any variable cannot be used if it is marked as unused.""" tree = parse_ast_tree(code.format(bad_name)) visitor = WrongVariableUsageVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [UnusedVariableIsUsedViolation])
def test_used_variable_tuple_definition( assert_errors, parse_ast_tree, context, indentation, bad_name, forbidden_tuple_unused_template, default_options, ): """Testing that any variable can be used if it is marked as unused.""" tree = parse_ast_tree( context.format( indent( forbidden_tuple_unused_template.format(bad_name), ' ' * indentation, ), ), ) visitor = WrongVariableUsageVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_raw_unused_variable_definition( assert_errors, parse_ast_tree, context, indentation, bad_name, forbidden_raw_unused_template, default_options, ): """Testing that any variable can be used in some cases.""" tree = parse_ast_tree( context.format( indent( forbidden_raw_unused_template.format(bad_name), ' ' * indentation, ), ), ) visitor = WrongVariableUsageVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [UnusedVariableIsDefinedViolation])