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

Port test_datasets_samplers.py to pytest #4037

Merged

Conversation

vivekkumar7089
Copy link
Contributor

This PR ports test_datasets_samplers.py to pytest as mentioned in #4033 .

def test_random_clip_sampler(self):
with get_list_of_videos(num_videos=3, sizes=[25, 25, 25]) as video_list:
video_clips = VideoClips(video_list, 5, 5)
sampler = RandomClipSampler(video_clips, 3)
self.assertEqual(len(sampler), 3 * 3)
assert_equal(len(sampler), 3 * 3)
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the PR @vivekkumar7089 !

Since we're just comparing numbers here (not tensors), we can just rely on a simple form:

Suggested change
assert_equal(len(sampler), 3 * 3)
assert len(sampler) == 3 * 3

Could you please update this one and all of the remaining ones below as well? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I will update.

Copy link
Member

Choose a reason for hiding this comment

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

@vivekkumar7089 Sorry for the confusion again but that comment above still stands: we should convert assertEqual into assert a == b, not into assert_equal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem, @NicolasHug , I have changed it back to assert a == b.

# remove elements of the first video, to simplify testing
indices.remove(0)
indices.remove(1)
indices = torch.tensor(indices) - 2
videos = torch.div(indices, 5, rounding_mode='floor')
v_idxs, count = torch.unique(videos, return_counts=True)
assert_equal(v_idxs, torch.tensor([0, 1]))
assert_equal(count, torch.tensor([3, 3]))
assert v_idxs == torch.tensor([0, 1])
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for the confusion: when comparing tensors, we should still use assert_equal.

In this file we don't want to change the existing instances of assert_equal.

We should just convert self.assertEqual into assert a == b (and maybe into assert_equal for iterables, but I doubt there are any instances of that)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@NicolasHug should I need to revert back all those last changes?

Copy link
Member

Choose a reason for hiding this comment

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

yes please, the existing assert_equal statements (as in master) should be left as-is

def test_random_clip_sampler(self):
with get_list_of_videos(num_videos=3, sizes=[25, 25, 25]) as video_list:
video_clips = VideoClips(video_list, 5, 5)
sampler = RandomClipSampler(video_clips, 3)
self.assertEqual(len(sampler), 3 * 3)
assert len(sampler) == 3 * 3
Copy link
Member

Choose a reason for hiding this comment

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

You did well here

Comment on lines 50 to 51
assert v_idxs == torch.tensor([0, 1, 2])
assert count == torch.tensor([3, 3, 3])
Copy link
Member

@NicolasHug NicolasHug Jun 10, 2021

Choose a reason for hiding this comment

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

Again, here and everywhere else, please do not change the existing assert_equal calls. You should only change the self.assertEqual calls into assert a == b

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I am sorry, @NicolasHug , for the inconvinience. Actually, I got confused. I will correct them.

Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

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

Thanks @vivekkumar7089 :) !
LGTM when green (the current failure in binary_linux_conda_py3.8_cu111 is unrelated)

@NicolasHug NicolasHug mentioned this pull request Jun 10, 2021
8 tasks
@NicolasHug NicolasHug merged commit 093757d into pytorch:master Jun 10, 2021
@github-actions
Copy link

Hey @NicolasHug!

You approved or merged this PR, but no labels were added.

@NicolasHug
Copy link
Member

Thanks @vivekkumar7089 !

@vivekkumar7089 vivekkumar7089 deleted the port-test_datasets_samplers-to-pytest branch June 10, 2021 18:10
facebook-github-bot pushed a commit that referenced this pull request Jun 14, 2021
Reviewed By: fmassa

Differential Revision: D29097735

fbshipit-source-id: efe35d35283981cca6274de580169e12a676e90f
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.

3 participants