diff --git a/ni_python_styleguide/_acknowledge_existing_errors/__init__.py b/ni_python_styleguide/_acknowledge_existing_errors/__init__.py index 7cb6c7c7..d7d6c152 100644 --- a/ni_python_styleguide/_acknowledge_existing_errors/__init__.py +++ b/ni_python_styleguide/_acknowledge_existing_errors/__init__.py @@ -89,7 +89,7 @@ def acknowledge_lint_errors( exclude=exclude, app_import_names=app_import_names, extend_ignore=extend_ignore, - file_or_dir=file_or_dir, + file_or_dir=[bad_file], excluded_errors=EXCLUDED_ERRORS, ) @@ -128,7 +128,7 @@ def _handle_emergent_violations(exclude, app_import_names, extend_ignore, file_o exclude=exclude, app_import_names=app_import_names, extend_ignore=extend_ignore, - file_or_dir=file_or_dir, + file_or_dir=[bad_file], excluded_errors=EXCLUDED_ERRORS, ) ) diff --git a/pyproject.toml b/pyproject.toml index f8dbaa9c..043e32bd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,11 +68,11 @@ line-length = 100 [tool.pytest.ini_options] addopts = "--doctest-modules" -norecursedirs = "*__snapshots" +norecursedirs = "*__snapshots tests/*/input/*" [tool.ni-python-styleguide] -extend_exclude = "*__snapshots/*/*input.py" +extend_exclude = "*__snapshots/*/*input.py,tests/*/input/*.py" [build-system] diff --git a/tests/test_cli/acknowledge_existing_errors_multiple_files/input/acknowledge_blank_file.py b/tests/test_cli/acknowledge_existing_errors_multiple_files/input/acknowledge_blank_file.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_cli/acknowledge_existing_errors_multiple_files/input/acknowledge_doc_lines.py b/tests/test_cli/acknowledge_existing_errors_multiple_files/input/acknowledge_doc_lines.py new file mode 100644 index 00000000..2735bdc1 --- /dev/null +++ b/tests/test_cli/acknowledge_existing_errors_multiple_files/input/acknowledge_doc_lines.py @@ -0,0 +1,34 @@ +def method1(): + return 7 + + +def method2(): + """Provide an examples of doc strings that are too long. + + Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. + """ + return 7 # Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. + + +class Foo: + def __init__(self): + pass + + def add(self, o): + """Provide an examples of doc strings that are too long. + + Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. + """ + return 7 # Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. + + +class _PrivateFoo: + def __init__(self): + pass + + def add(self, o): + """Provide an examples of doc strings that are too long. + + Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. + """ + return 7 # Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. diff --git a/tests/test_cli/acknowledge_existing_errors_multiple_files/input/acknowledge_function_signatures.py b/tests/test_cli/acknowledge_existing_errors_multiple_files/input/acknowledge_function_signatures.py new file mode 100644 index 00000000..f13ac3ed --- /dev/null +++ b/tests/test_cli/acknowledge_existing_errors_multiple_files/input/acknowledge_function_signatures.py @@ -0,0 +1,102 @@ +"""example of a python file with linter errors. +""" + +import os + +os.listdir() + + +def method_with_shadow_builtin(input): + """Shadow a builtin.""" + return input + + +def method_with_shadow_import(os): + """Shadow an import.""" + return os + + +def method_with_shadow_import_on_multiple_lines( + x, + y, + os, +): + """Shadow an import.""" + return os + + +def method_with_unused_param(unused_input): + """Provide and unused param.""" + return 5 + + +def method_with_parameters_on_multiple_lines(x, y): + """Provide parameters on multiple lines test case.""" + return x + y + + +def method_with_bad_names_on_single_line(myBadlyNamedParam, my_other_Bad_name): + """Provide parameters with bad names on single line.""" + return myBadlyNamedParam + my_other_Bad_name + + +def method_with_bad_names_on_multiple_lines_1( + myBadlyNamedParam, +): + """Provide parameters with bad names on multiple lines.""" + return myBadlyNamedParam + 5 + + +def method_with_bad_names_on_multiple_lines_2( + myBadlyNamedParam, + my_other_Bad_name, +): + """Provide parameters with bad names on multiple lines.""" + return myBadlyNamedParam + my_other_Bad_name + + +def method_withBadName_with_shadow(input): + """Shadow a builtin.""" + return input + + +def method_withBadName_with_unused_param(unused_input): + """Provide and unused param.""" + return 5 + + +def method_withBadName_with_parameters_on_multiple_lines(x, y): + """Provide parameters on multiple lines test case.""" + return x + y + + +def method_withBadName_with_bad_params_on_single_line(myBadlyNamedParam, my_other_Bad_name): + """Provide parameters with bad names on single line.""" + return myBadlyNamedParam + my_other_Bad_name + + +def method_withBadName_with_bad_params_on_multiple_lines_1( + myBadlyNamedParam, +): + """Provide parameters with bad names on multiple lines.""" + return myBadlyNamedParam + 5 + + +def method_withBadName_with_bad_params_on_multiple_lines_2( + myBadlyNamedParam, + my_other_Bad_name, +): + """Provide parameters with bad names on multiple lines.""" + return myBadlyNamedParam + my_other_Bad_name + + +def method_withBadName_andParams(my_normal_param, myBadlyNamedParam, my_other_Bad_param): + """Provide example where black will want to split out result.""" + return 5 + 7 + + +def method_withBadName_and_bad_param_with_long_name( + my_normal_param, myBadlyNamedParam, my_other_Bad_param +): + """Provide example where black will want to split out result even more""" + return 5 + 7 diff --git a/tests/test_cli/test_acknowledge_existing_errors.py b/tests/test_cli/test_acknowledge_existing_errors.py index 8473c17d..ca4daeed 100644 --- a/tests/test_cli/test_acknowledge_existing_errors.py +++ b/tests/test_cli/test_acknowledge_existing_errors.py @@ -5,9 +5,8 @@ import pytest -TEST_CASE_DIR = ( - pathlib.Path(__file__).parent.absolute() / "acknowledge_existing_errors_test_cases__snapshots" -) +MODULE_DIR = pathlib.Path(__file__).parent.absolute() +TEST_CASE_DIR = MODULE_DIR / "acknowledge_existing_errors_test_cases__snapshots" @pytest.mark.parametrize( @@ -73,3 +72,31 @@ def test_given_suppressed_file_linter_does_not_error( output = styleguide_command(command="lint", command_args=[test_file, *additional_args]) assert output.exit_code in (True, 0), f"Error in running:\n{output.output}\n\n" + + +@pytest.mark.parametrize("cmd_args", [[], ["--aggressive"]], ids=["normal", "aggressive"]) +def test_given_folder_with_multiple_files_linter_does_not_error( + cmd_args, tmp_path, styleguide_command, chdir +): + in_dir = MODULE_DIR / "acknowledge_existing_errors_multiple_files" / "input" + test_dir = tmp_path / "input" + shutil.copytree(in_dir, test_dir) + chdir(tmp_path) + + output = styleguide_command(command="acknowledge-existing-violations", command_args=cmd_args) + + assert output.exit_code in (True, 0), f"Error in running:\n{output}" + + +def test_given_folder_with_multiple_files_acknowledged__does_not_error( + tmp_path, styleguide_command, chdir +): + in_dir = MODULE_DIR / "acknowledge_existing_errors_multiple_files" / "input" + test_dir = tmp_path / "input" + shutil.copytree(in_dir, test_dir) + chdir(tmp_path) + styleguide_command(command="acknowledge-existing-violations", command_args=["--aggressive"]) + + output = styleguide_command(command="lint", command_args=[]) + + assert output.exit_code in (True, 0), f"Error in running:\n{output.output}\n\n"