Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed errant sys.argv to args parameter passed in. #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

akfreed
Copy link

@akfreed akfreed commented May 18, 2022

Fix for #46

In some use cases, the args param given to the Command constructor was an (purposely) stripped version of sys.argv. Command.get_added_files() was reading directly from sys.argv, circumventing this filtering.

In some use cases, the args param given to the Command constructor
was a filtered version of sys.argv. Command.get_added_files() was
reading directly from sys.argv, circumventing this filtering.
@akfreed akfreed marked this pull request as ready for review May 18, 2022 06:20
@akfreed
Copy link
Author

akfreed commented May 18, 2022

The Mac ci tests are failing due to the ls command failing... I tried taking it out and the test continued. However it failed later on. It looks like the test is failing because if an error in a config file? I checked and confirmed the failure is not due to my changes.

failure: https://github.com/akfreed/pocc-pre-commit-hooks/runs/6483498426?check_suite_focus=true

Run python3 -m pytest -x -vvv
  python3 -m pytest -x -vvv
  shell: /bin/bash -e {0}
============================= test session starts ==============================
platform darwin -- Python 3.9.12, pytest-7.1.2, pluggy-1.0.0 -- /usr/local/opt/[email protected]/bin/python3.9
cachedir: .pytest_cache
rootdir: /Users/runner/work/pocc-pre-commit-hooks/pocc-pre-commit-hooks, configfile: pytest.ini
collecting ... collected 124 items

tests/test_dashp.py::TestHDashp::test_clang_tidy_dashp_present[ClangTidyCmd] PASSED [  0%]
tests/test_dashp.py::TestHDashp::test_clang_tidy_dashp_present[OCLintCmd] PASSED [  1%]
tests/test_hooks.py::TestHooks::test_run[run_shell_cmd clang-format /Users/runner/work/pocc-pre-commit-hooks/pocc-pre-commit-hooks/tests/test_repo/err.c /Users/runner/work/pocc-pre-commit-hooks/pocc-pre-commit-hooks/tests/test_repo/err.cpp --style=google --no-diff] PASSED [  2%]
tests/test_hooks.py::TestHooks::test_run[run_shell_cmd uncrustify /Users/runner/work/pocc-pre-commit-hooks/pocc-pre-commit-hooks/tests/test_repo/err.c /Users/runner/work/pocc-pre-commit-hooks/pocc-pre-commit-hooks/tests/test_repo/err.cpp -c /Users/runner/work/pocc-pre-commit-hooks/pocc-pre-commit-hooks/tests/uncrustify_defaults.cfg --no-diff] FAILED [  3%]

=================================== FAILURES ===================================
_ TestHooks.test_run[run_shell_cmd uncrustify /Users/runner/work/pocc-pre-commit-hooks/pocc-pre-commit-hooks/tests/test_repo/err.c /Users/runner/work/pocc-pre-commit-hooks/pocc-pre-commit-hooks/tests/test_repo/err.cpp -c /Users/runner/work/pocc-pre-commit-hooks/pocc-pre-commit-hooks/tests/uncrustify_defaults.cfg --no-diff] _

self = <tests.test_hooks.TestHooks object at 0x102707e20>
test_type = <function TestHooks.run_shell_cmd at 0x102792670>
cmd_name = 'uncrustify'
args = ['-c', '/Users/runner/work/pocc-pre-commit-hooks/pocc-pre-commit-hooks/tests/uncrustify_defaults.cfg', '--no-diff']
files = ['/Users/runner/work/pocc-pre-commit-hooks/pocc-pre-commit-hooks/tests/test_repo/err.c', '/Users/runner/work/pocc-pre-commit-hooks/pocc-pre-commit-hooks/tests/test_repo/err.cpp']
test_dir = '', expd_output = b'', expd_retcode = 1

    def test_run(self, test_type, cmd_name, args, files, test_dir, expd_output, expd_retcode):
        """Test each command's class from its python file
        and the command for each generated by setup.py."""
        fix_in_place = self.determine_edit_in_place(cmd_name, args)
        has_err_file = any(["err.c" in f for f in files])
        will_fix_in_place = fix_in_place and has_err_file
>       test_type(cmd_name, files, args, test_dir, expd_output, expd_retcode)

tests/test_hooks.py:390: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/test_hooks.py:447: in run_shell_cmd
    utils.assert_equal(target_output, actual)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

expected = b''
actual = b"Problem with uncrustify: Unexpected Stderr/return code received when analyzing /Users/runner/work/pocc-pre-commit-ho...oks/pocc-pre-commit-hooks/tests/uncrustify_defaults.cfg:23: Expected number , for 'indent_bool_paren'; got 'false'\n\n"

    def assert_equal(expected: bytes, actual: bytes):
        """Stand in for Python's assert which is annoying to work with."""
        actual = actual.replace(b"\r", b"")  # ignore windows file ending differences
        if expected != actual:
            print(f"\n\nExpected:`{expected}`")
            print(f"\n\nActual__:`{actual}`")
            if isinstance(expected, bytes) and isinstance(actual, bytes):
                expected_str = expected.decode()
                actual_str = actual.decode()
                print("String comparison:", expected_str == actual_str)
                diff_lines_gen = difflib.context_diff(expected_str, actual_str, "Expected", "Actual")
                diff_lines = "".join(list(diff_lines_gen))
                print(f"\n\nDifference:\n{diff_lines}")
            else:
                print(f"Expected is type {type(expected)}\nActual is type {type(actual)}")
>           pytest.fail("Test failed!")
E           Failed: Test failed!

tests/test_utils.py:34: Failed
----------------------------- Captured stdout call -----------------------------


Expected:`b''`


Actual__:`b"Problem with uncrustify: Unexpected Stderr/return code received when analyzing /Users/runner/work/pocc-pre-commit-hooks/pocc-pre-commit-hooks/tests/test_repo/err.c.\nArgs: ['uncrustify', '-c', '/Users/runner/work/pocc-pre-commit-hooks/pocc-pre-commit-hooks/tests/uncrustify_defaults.cfg', '-q', '-f', '/Users/runner/work/pocc-pre-commit-hooks/pocc-pre-commit-hooks/tests/test_repo/err.c']\n#include <stdio.h>\nint main() {\n  int i;\n  return;\n}Option<NUM>: at /Users/runner/work/pocc-pre-commit-hooks/pocc-pre-commit-hooks/tests/uncrustify_defaults.cfg:22: Expected number , for 'indent_comma_paren'; got 'false'\nOption<NUM>: at /Users/runner/work/pocc-pre-commit-hooks/pocc-pre-commit-hooks/tests/uncrustify_defaults.cfg:23: Expected number , for 'indent_bool_paren'; got 'false'\n\n"`
String comparison: False


Difference:
*** Expected
--- Actual
***************
*** 0 ****
--- 1,778 ----
+ P+ r+ o+ b+ l+ e+ m+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d+ e+ f+ a+ u+ l+ t+ s+ .+ c+ f+ g+ :+ 2+ 3+ :+  + E+ x+ p+ e+ c+ t+ e+ d+  + n+ u+ m+ b+ e+ r+  + ,+  + f+ o+ r+  + '+ i+ n+ d+ e+ n+ t+ _+ b+ o+ o+ l+ _+ p+ a+ r+ e+ n+ '+ ;+  + g+ o+ t+  + '+ f+ a+ l+ s+ e+ '+ 
+ 

=========================== short test summary info ============================
FAILED tests/test_hooks.py::TestHooks::test_run[run_shell_cmd uncrustify /Users/runner/work/pocc-pre-commit-hooks/pocc-pre-commit-hooks/tests/test_repo/err.c /Users/runner/work/pocc-pre-commit-hooks/pocc-pre-commit-hooks/tests/test_repo/err.cpp -c /Users/runner/work/pocc-pre-commit-hooks/pocc-pre-commit-hooks/tests/uncrustify_defaults.cfg --no-diff]
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
========================= 1 failed, 3 passed in 1.73s ==========================

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant