def test_multiple_compare( assert_errors, parse_ast_tree, default_options, ): """Ensuring than multiple redundant compare returns a single violation.""" tree = parse_ast_tree('assert some == some == some') visitor = ComparisonSanityVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [RedundantComparisonViolation])
def test_literal_special_without_errors( assert_errors, parse_ast_tree, code, default_options, ): """Testing that special cases do work and do not raise warnings.""" tree = parse_ast_tree(code.format('first_name', 'second_name')) visitor = ComparisonSanityVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_redundant( assert_errors, parse_ast_tree, code, comparators, default_options, ): """Testing that violations are when comparing identical variable.""" tree = parse_ast_tree(create_variables.format(code.format(*comparators))) visitor = ComparisonSanityVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [RedundantComparisonViolation])
def test_not_redundant( assert_errors, parse_ast_tree, code, comparators, default_options, ): """Testing that comparisons work well.""" tree = parse_ast_tree(create_variables.format(code.format(*comparators))) visitor = ComparisonSanityVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_comparison_with_multiple_in( assert_errors, parse_ast_tree, code, comparators, default_options, ): """Comparisons raise for multiple ``in`` cases.""" tree = parse_ast_tree(code.format(*comparators)) visitor = ComparisonSanityVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [MultipleInComparisonViolation])
def test_comparison_with_in( assert_errors, parse_ast_tree, code, comparators, default_options, ): """Comparisons work well for single ``in``.""" tree = parse_ast_tree(code.format(*comparators)) visitor = ComparisonSanityVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_literal( assert_errors, parse_ast_tree, code, comparators, default_options, ): """Testing that violations are when using literal comparisons.""" tree = parse_ast_tree(code.format(*comparators)) visitor = ComparisonSanityVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [ConstantComparisonViolation])
def test_non_literal( assert_errors, parse_ast_tree, code, comparators, default_options, ): """Testing that comparisons work well.""" tree = parse_ast_tree(code.format(*comparators)) visitor = ComparisonSanityVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_literal_special2( assert_errors, parse_ast_tree, code, comparators, default_options, ): """Testing that special cases do work and raise warnings.""" tree = parse_ast_tree(code.format(*comparators)) visitor = ComparisonSanityVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [ConstantComparisonViolation])
def test_redundant_with_in( # TODO: join with `test_redundant` assert_errors, parse_ast_tree, in_conditions, comparators, default_options, ): """Testing that violations are when comparing identical variable.""" tree = parse_ast_tree( create_variables.format(in_conditions.format(*comparators)), ) visitor = ComparisonSanityVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [RedundantComparisonViolation])