-
Notifications
You must be signed in to change notification settings - Fork 7k
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
test: Updated asserts in test_io #1496
Conversation
Updated all raw asserts to corresponding unittest.TestCase.assert. See pytorch#1483
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, but I don't think this is correct, and I'm not sure how the tests could have passed locally.
test/test_io.py
Outdated
@@ -53,8 +53,8 @@ def _create_video_frames(num_frames, height, width): | |||
@contextlib.contextmanager | |||
def temp_video(num_frames, height, width, fps, lossless=False, video_codec=None, options=None): | |||
if lossless: | |||
assert video_codec is None, "video_codec can't be specified together with lossless" | |||
assert options is None, "options can't be specified together with lossless" | |||
self.assertIsInstance(video_codec, type(None), "video_codec can't be specified together with lossless") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not correct, temp_video
is not a class method but a free function, so it doesn't have a self
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I had the same issue in the first place but didn't commit the right version of it
In order to use unittest.TestCase for asserts in temp_video, the object has to be passed itself to temp_video.
test/test_io.py
Outdated
@@ -51,10 +51,10 @@ def _create_video_frames(num_frames, height, width): | |||
|
|||
|
|||
@contextlib.contextmanager | |||
def temp_video(num_frames, height, width, fps, lossless=False, video_codec=None, options=None): | |||
def temp_video(tester, num_frames, height, width, fps, lossless=False, video_codec=None, options=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a good idea. This is a function that is independent on the tester
, so I think it should stay free from it.
From my view, if you want to remove the assert
here (which is outside of the test btw), I'd do something like
if video_codec is not None:
raise ValueError(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, I'll update the PR. Two quick questions:
- would you prefer a
AssertionErrorr
orValueError
? - was it for error clarity that both verifications are not performed at once?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer ValueError
actually.
This is not a test case, but a helper function, which could be used outside of testing, so having a more precise error type would be helpful
Switched initial raw assert to AssertionError.
Codecov Report
@@ Coverage Diff @@
## master #1496 +/- ##
==========================================
+ Coverage 64.46% 64.49% +0.03%
==========================================
Files 83 83
Lines 6421 6428 +7
Branches 982 984 +2
==========================================
+ Hits 4139 4146 +7
Misses 1992 1992
Partials 290 290
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you maybe make it a ValueError
instead? I think it's better to avoid AssertionError
, as it is in fact equivalent to assert
.
After that this is good to merge, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This PR updates all raw
assert
to the correspondingunittest.TestCase
assert method for tests related totorchvision.io
as suggested by #1483.The specific test was run locally with success, any feedback is welcome!