Failing test test_badopt
Closed this issue · 6 comments
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
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?
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 ----------"
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
?
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
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
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