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

Move inline tests to a dedicated testing module #174

Merged
merged 1 commit into from
Jan 22, 2024

Conversation

pieleric
Copy link
Contributor

As discussed in the review of PR #173, it's better to have the test cases in the dedicated test file, because that allows to run them automatically in CI.

This PR does just that. I've dropped the possibility to run some of the test cases on different tiff files, as it's now focused to be run with pytest. The hard-coded filenames work fine on Linux, but I'm not sure they will do as well on Windows. The CI results should help to find out...

@pieleric pieleric force-pushed the ctypes-move-test-cases-to-ci branch 2 times, most recently from e877316 to 554fcd2 Compare January 16, 2024 23:30
@djhoese
Copy link
Collaborator

djhoese commented Jan 17, 2024

Flake8 is mad at the code:

libtiff/tests/test_libtiff_ctypes.py:158:47: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:165:75: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:184:47: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:189:44: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:212:47: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:217:47: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:221:75: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:240:47: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:245:47: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:249:75: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:270:47: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:275:47: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:279:75: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:359:39: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:472:9: B007 Loop control variable 'image' not used within the loop body. If this is intended, start the name with an underscore.

@djhoese djhoese changed the title ctypes: move test cases to the dedicated testing file Move inline tests to a dedicated testing module Jan 17, 2024
djhoese
djhoese previously approved these changes Jan 17, 2024
Copy link
Collaborator

@djhoese djhoese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. I tried changing the title to match what I would expect in a changelog (I don't remember if we auto-generate changelogs for pylibtiff but still). Not sure "inline" is the right word. Once flake8 issues are resolved we'll see how tests go.

@pieleric
Copy link
Contributor Author

Flake8 is mad at the code:

libtiff/tests/test_libtiff_ctypes.py:158:47: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:165:75: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:184:47: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:189:44: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:212:47: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:217:47: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:221:75: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:240:47: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:245:47: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:249:75: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:270:47: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:275:47: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:279:75: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:359:39: E231 missing whitespace after ','
libtiff/tests/test_libtiff_ctypes.py:472:9: B007 Loop control variable 'image' not used within the loop body. If this is intended, start the name with an underscore.

Yes... I also saw that. I'm a bit confused why there are so many errors while it used to pass in the original file. I just copy-pasted that code!
Anyway, I'll fix these issues, and then we can see how it fare on the rest of the CI.

@pearu
Copy link
Owner

pearu commented Jan 17, 2024

The hard-coded filenames work fine on Linux, but I'm not sure they will do as well on Windows. The CI results should help to find out...

Try using tempfile.NamedTemporaryFile(..., delete_on_close=False).

@djhoese
Copy link
Collaborator

djhoese commented Jan 17, 2024

About flake8 ignoring the old code, I wonder if it skipped over the functions because they started with _...but that seems unlikely.

@pieleric
Copy link
Contributor Author

About flake8 ignoring the old code, I wonder if it skipped over the functions because they started with _...but that seems unlikely.

I've investigated it a little bit. It turns out flake8 is entirely disabled on that file. That's "thanks" to this line:

# flake8: noqa for F821

flake8 doesn't allow disabling a specific error for an entire file. So it just reads it as noqa and skips the whole file.

@coveralls
Copy link

coveralls commented Jan 17, 2024

Pull Request Test Coverage Report for Build 7576518304

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+15.3%) to 54.664%

Totals Coverage Status
Change from base Build 7543614569: 15.3%
Covered Lines: 2350
Relevant Lines: 4299

💛 - Coveralls

@djhoese
Copy link
Collaborator

djhoese commented Jan 18, 2024

You can definitely do single rule ignores for a file: https://flake8.pycqa.org/en/latest/user/options.html#cmdoption-flake8-per-file-ignores

Just not the way it was done there.

Instead of keeping the test cases at the end of libtiff_ctypes.py,
place them in test_libtiff_ctypes.py. The main advantage is that they
should be called automatically during CI.
It also reduces the actual library code, which avoids unnecessarily loading
this code every time the library is used.
Copy link
Owner

@pearu pearu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks, @pieleric!

Copy link
Collaborator

@djhoese djhoese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. It is definitely better than it was so thanks a ton for doing this work. I think in the long run it'd be nice to separate out those test file creation steps into a dedicated helper function that is used by the write test(s) and the read test(s). It could even return the actual filename/path of the file(s) it just wrote. Right now there is still some "I know to read this filename because of prior knowledge about the function I just called to write it" magic going on...but that's fine. Like I said, still way better than before. Thanks.

@djhoese djhoese merged commit 0e0bc3b into pearu:master Jan 22, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants