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

test: Updated asserts in test_io #1496

Merged
merged 4 commits into from
Oct 21, 2019
Merged

Conversation

frgfm
Copy link
Contributor

@frgfm frgfm commented Oct 18, 2019

This PR updates all raw assert to the corresponding unittest.TestCase assert method for tests related to torchvision.io as suggested by #1483.
The specific test was run locally with success, any feedback is welcome!

Updated all raw asserts to corresponding unittest.TestCase.assert. See pytorch#1483
Copy link
Member

@fmassa fmassa left a 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")
Copy link
Member

@fmassa fmassa Oct 18, 2019

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 .

Copy link
Contributor Author

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):
Copy link
Member

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(...)

Copy link
Contributor Author

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 or ValueError?
  • was it for error clarity that both verifications are not performed at once?

Copy link
Member

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-io
Copy link

codecov-io commented Oct 19, 2019

Codecov Report

Merging #1496 into master will increase coverage by 0.03%.
The diff coverage is n/a.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
torchvision/transforms/functional_tensor.py 57.14% <0%> (-2.86%) ⬇️
torchvision/models/detection/transform.py 66.92% <0%> (ø) ⬆️
torchvision/models/detection/roi_heads.py 56.14% <0%> (+0.37%) ⬆️
torchvision/ops/boxes.py 100% <0%> (+5.55%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6101f2d...8c2d2de. Read the comment docs.

Copy link
Member

@fmassa fmassa left a 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!

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

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

Thanks!

@fmassa fmassa merged commit 371f6c8 into pytorch:master Oct 21, 2019
@frgfm frgfm deleted the test-io-assert branch October 22, 2019 09:42
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.

3 participants