-
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
Properly fix dataset test that passes by accident #3434
Conversation
torchvision/datasets/coco.py
Outdated
try: | ||
self.coco = COCO(annFile) | ||
except FileNotFoundError as error: | ||
raise RuntimeError(f"The file {annFile} does not exist or is corrupt.") from error |
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'm not sure we should be changing the call-sites so that the current test infra works. Plus, FileNotFoundError
is a meaningful type of error to be raised in here. Would your plan be to change all locations in the code to always raise RuntimeError
?
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'm not sure we should be changing the call-sites so that the current test infra works.
IMO every dataset should handle corrupted or non-existent files properly. I wouldn't do that to satisfy our tests, but rather because it can make the life of the user easier with a descriptive error message. Plus, this is what you agreed to
Lines 398 to 401 in 67681a7
def test_not_found(self): | |
with self.assertRaises(RuntimeError): | |
with self.create_dataset(inject_fake_data=False): | |
pass |
Plus,
FileNotFoundError
is a meaningful type of error to be raised in here.
I agree. I'll update the test infrastructure.
Would your plan be to change all locations in the code to always raise
RuntimeError
?
That was the original plan, yes. Maybe we can differentiate between RuntimeError
for corrupted and FileNotFoundError
for non-existent files. If we want to make sure we could also opt to create an FileCorruptedError(Exception)
and check for that instead of a more general RuntimeError
.
Codecov Report
@@ Coverage Diff @@
## master #3434 +/- ##
==========================================
+ Coverage 76.00% 76.11% +0.11%
==========================================
Files 105 105
Lines 9697 9697
Branches 1556 1556
==========================================
+ Hits 7370 7381 +11
+ Misses 1841 1836 -5
+ Partials 486 480 -6
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.
Looks good, thanks!
Let's leave for a follow-up discussion if we want to change the implementation of the datasets to raise different error types, as this would be a BC-breaking change of sorts
Summary: * make UsageError an Exception rather than RuntimeError * separate fake data injection and dataset args handling * adapt tests for Coco * fix Coco implementation * add documentation * fix VideoDatasetTestCase * adapt UCF101 tests * cleanup * allow FileNotFoundError for test without fake data * Revert "fix Coco implementation" This reverts commit e2b6938. * lint * fix UCF101 tests Reviewed By: fmassa Differential Revision: D26756278 fbshipit-source-id: d2b3a7258e6dcf63595c5c4388453d2821746d79
Fixes #3427