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

Properly fix dataset test that passes by accident #3434

Merged
merged 17 commits into from
Feb 25, 2021

Conversation

pmeier
Copy link
Collaborator

@pmeier pmeier commented Feb 23, 2021

Fixes #3427

@pmeier pmeier requested a review from fmassa February 23, 2021 10:52
Comment on lines 33 to 36
try:
self.coco = COCO(annFile)
except FileNotFoundError as error:
raise RuntimeError(f"The file {annFile} does not exist or is corrupt.") from error
Copy link
Member

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?

Copy link
Collaborator Author

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

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

codecov bot commented Feb 24, 2021

Codecov Report

Merging #3434 (43136d3) into master (fc33c46) will increase coverage by 0.11%.
The diff coverage is n/a.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
torchvision/datasets/vision.py 70.68% <0.00%> (+1.72%) ⬆️
torchvision/datasets/voc.py 94.50% <0.00%> (+2.19%) ⬆️
torchvision/datasets/caltech.py 83.90% <0.00%> (+4.59%) ⬆️
torchvision/datasets/cifar.py 95.00% <0.00%> (+5.00%) ⬆️

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 fc33c46...43136d3. Read the comment docs.

@pmeier pmeier requested a review from fmassa February 25, 2021 06:57
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.

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

@fmassa fmassa merged commit 13c4470 into pytorch:master Feb 25, 2021
@pmeier pmeier deleted the fix-test-not-found branch February 25, 2021 09:48
facebook-github-bot pushed a commit that referenced this pull request Mar 4, 2021
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
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.

DatasetTestCase.test_not_found only works by accident
5 participants