def test_return_none_variation(): code = "def f():\n\treturn None if a < b else b" path = "test_path" parsed_ast = ast.parse(code, path) p = ParsedSourceFile(path, parsed_ast, code) plugin = ReturnNonePlugin() analysis_report = plugin.do_analysis([p]) assert len(analysis_report.problems) == 0
def test_condition_comparison_not_found(): code = "def f():\n\tif isSmaller(a,b):\n\t\treturn 5" path = "test_path" parsed_ast = ast.parse(code, path) p = ParsedSourceFile(path, parsed_ast, code) plugin = ConditionMethodCallPlugin() analysis_report = plugin.do_analysis([p]) assert len(analysis_report.problems) == 0
def test_condition_comparison_simple_and(): code = "def f():\n\tif a < 5 and b < 2:\n\t\treturn 5" path = "test_path" parsed_ast = ast.parse(code, path) p = ParsedSourceFile(path, parsed_ast, code) plugin = ConditionMethodCallPluginSimple() analysis_report = plugin.do_analysis([p]) assert len(analysis_report.problems) == 0
def test_return_none_found(): code = "def f():\n\treturn None" path = "test_path" parsed_ast = ast.parse(code, path) p = ParsedSourceFile(path, parsed_ast, code) plugin = ReturnNonePlugin() analysis_report = plugin.do_analysis([p]) assert len(analysis_report.problems) == 1 assert analysis_report.problems[0].name == "Returned None" assert analysis_report.problems[0].file_path == "test_path" assert analysis_report.problems[0].line_number == 2
def test_condition_comparison_simple_is_not(): code = "def f():\n\tif a is not 5:\n\t\treturn 5" path = "test_path" parsed_ast = ast.parse(code, path) p = ParsedSourceFile(path, parsed_ast, code) plugin = ConditionMethodCallPluginSimple() analysis_report = plugin.do_analysis([p]) assert len(analysis_report.problems) == 1 assert analysis_report.problems[0].name == "Explicit comparison in condition simple" assert analysis_report.problems[0].file_path == "test_path" assert analysis_report.problems[0].line_number == 2
def test_condition_comparison_nested_found(): code = "def f():\n\tif isSmaller(a,b) or isBigger(a,b) and not a <b:\n\t\treturn 5" path = "test_path" parsed_ast = ast.parse(code, path) p = ParsedSourceFile(path, parsed_ast, code) plugin = ConditionMethodCallPlugin() analysis_report = plugin.do_analysis([p]) assert len(analysis_report.problems) == 1 assert analysis_report.problems[ 0].name == "Explicit comparison in condition" assert analysis_report.problems[0].file_path == "test_path" assert analysis_report.problems[0].line_number == 2