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

Failing test test_badopt #32

Closed
mdeweerd opened this issue May 7, 2022 · 6 comments · Fixed by #33
Closed

Failing test test_badopt #32

mdeweerd opened this issue May 7, 2022 · 6 comments · Fixed by #33

Comments

@mdeweerd
Copy link
Contributor

mdeweerd commented May 7, 2022

While updating PRs as per request, I now have this new error during tests.

I a checking on how to fix that, just registering this as an issue to explain why the future change is there.
This breaks commit because of more stringent pre-commit target (all tests must pass).

________________________________________ test_badopt[a/b] _________________________________________

arg = 'a/b'

    @pytest.mark.parametrize(('arg'), ('', 'a.b', 'a/b'))
    def test_badopt(arg):
        with pytest.raises(FileNotFoundError):
>           remove_crlf([arg])

tests/remove_crlf_test.py:26:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pre_commit_hooks/remove_crlf.py:24: in main
    text_files = [f for f in args.filenames if is_textfile(f)]
pre_commit_hooks/remove_crlf.py:24: in <listcomp>
    text_files = [f for f in args.filenames if is_textfile(f)]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

filename = 'a/b', blocksize = 512

    def is_textfile(filename, blocksize=512):
        if any(filename.endswith(ext) for ext in KNOWN_BINARY_FILE_EXTS):
            return False
>       with open(filename, 'rb') as text_file:
E       NotADirectoryError: [Errno 20] Not a directory: 'a/b'

pre_commit_hooks/utils.py:8: NotADirectoryError
@Lucas-C
Copy link
Owner

Lucas-C commented May 9, 2022

Could you clarify when you get this error?

The unit tests suite currently passes without any error on my computer and in GitHub Actions.

Is this error caused by PR #33?

@mdeweerd
Copy link
Contributor Author

mdeweerd commented May 9, 2022

It's not change related - the master branch fails the same way.

Could be platform related:
"---------- coverage: platform cygwin, python 3.8.12-final-0 ----------"

@Lucas-C
Copy link
Owner

Lucas-C commented May 10, 2022

OK, so it only happened in your development environment so far.

Could you indicate on what repository did you get this error? Is it a public GitHub One?
Was it during a git commit?

@mdeweerd
Copy link
Contributor Author

I got it during a git commit (pre-commit) because 'py.test' is effectively executing the tests. I did not get this prior to the first PR as far as I remember.

This just required a small update in test case considering that NotADirectoryError is a suitable exception when trying to open "a/b".

However, I now just think of the following: I often use just 1 letter for temporary files and I created a file name "a' at the root.
After renaming that file the path 'a/b' no longer results in that error type.

I updated a test case to that it trys to access 'README.md/dummy'.
https://github.com/mdeweerd/pre-commit-hooks/blob/9beba6505bc04f9c8015905276efdbf8a46001bb/tests/remove_crlf_test.py#L23 .
The CI is nto running because the pre-commit-config.yaml has not been updated in that branch. But running 'pytest -sv' locally results in:

tests/remove_crlf_test.py:26:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pre_commit_hooks/remove_crlf.py:24: in main
    text_files = [f for f in args.filenames if is_textfile(f)]
pre_commit_hooks/remove_crlf.py:24: in <listcomp>
    text_files = [f for f in args.filenames if is_textfile(f)]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

filename = 'README.md/dummy', blocksize = 512

    def is_textfile(filename, blocksize=512):
        if any(filename.endswith(ext) for ext in KNOWN_BINARY_FILE_EXTS):
            return False
>       with open(filename, 'rb') as text_file:
E       NotADirectoryError: [Errno 20] Not a directory: 'README.md/dummy'

pre_commit_hooks/utils.py:8: NotADirectoryError

@mdeweerd
Copy link
Contributor Author

Just though of another type of error: when the file is a directory.
So I added "tests" to the list which provokes a IsADirectoryError (see https://github.com/mdeweerd/pre-commit-hooks/blob/9955842742b90dfb3098b2798cf119f6749f94eb/tests/remove_crlf_test.py#L23 ).

tests/remove_crlf_test.py:26:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pre_commit_hooks/remove_crlf.py:24: in main
    text_files = [f for f in args.filenames if is_textfile(f)]
pre_commit_hooks/remove_crlf.py:24: in <listcomp>
    text_files = [f for f in args.filenames if is_textfile(f)]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

filename = 'tests', blocksize = 512

    def is_textfile(filename, blocksize=512):
        if any(filename.endswith(ext) for ext in KNOWN_BINARY_FILE_EXTS):
            return False
>       with open(filename, 'rb') as text_file:
E       IsADirectoryError: [Errno 21] Is a directory: 'tests'

pre_commit_hooks/utils.py:8: IsADirectoryError

@mdeweerd
Copy link
Contributor Author

I merge from the master branch where you just integrated the changes from #33.
So the CI essentially runs but fails with IsADirectroyError because of 'tests':

https://github.com/mdeweerd/pre-commit-hooks/runs/6366531305?check_suite_focus=true

@mdeweerd mdeweerd mentioned this issue May 10, 2022
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 a pull request may close this issue.

2 participants