Skip to content

Conversation

@vmoens
Copy link
Contributor

@vmoens vmoens commented Jul 30, 2021

I also removed the common_utils.py/TestCase class which -- as far as i can tell - wasn't used anywhere. This is probably the most contentious point of this PR and needs proper reviewing!

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 for the PR @vmoens ! I made a few minor comments, but this looks good!

Also there are a few linting issue, which you can find by looking at the ci/circleci: python_lint job below.

You did well getting rid of TestCase, I'm glad we're finally done with it :)

if __name__ == "__main__":
unittest.main()
if __name__ == '__main__':
pytest.main([__file__])
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this is missing a blank line at the end of the file

vtimebase[0].item(), vtimebase[1].item()
)
self.assertAlmostEqual(video_duration, config.duration, delta=0.5)
assert abs(video_duration-config.duration)<=0.5
Copy link
Member

Choose a reason for hiding this comment

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

have you tried using pytest.approx here? https://docs.pytest.org/en/6.2.x/reference.html#pytest-approx

I think we should be able to use it everywhere assertAlmostEqual was used

def test_probe_video_from_memory_script(self):
scripted_fun = torch.jit.script(io._probe_video_from_memory)
self.assertIsNotNone(scripted_fun)
assert scripted_fun
Copy link
Member

Choose a reason for hiding this comment

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

in order to be slightly more explicit about what we don't want scripted_fun to be, let's use assert scripted_fun is not None

full_path, start_offset, end_offset, pts_unit='pts')
self.assertGreaterEqual(audio.shape[0], 1)
self.assertGreaterEqual(audio.shape[1], 1)
assert all(audio.shape[:2])
Copy link
Member

Choose a reason for hiding this comment

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

here as well it will probably be more obvious to include the >= 1 part in the assertion

full_path, start_offset, end_offset, pts_unit='sec')
self.assertGreaterEqual(audio.shape[0], 1)
self.assertGreaterEqual(audio.shape[1], 1)
assert all(audio.shape[:2])
Copy link
Member

Choose a reason for hiding this comment

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

same here

if __name__ == "__main__":
unittest.main()
if __name__ == '__main__':
pytest.main([__file__])
Copy link
Member

Choose a reason for hiding this comment

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

needs a new line here as well :)


self.assertTrue(middle_num_frames < num_frames)
self.assertAlmostEqual(middle_num_frames, num_frames // 2, delta=1)
assert (middle_num_frames < num_frames)
Copy link
Member

Choose a reason for hiding this comment

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

Here and in various places, we don't need the surrounding parenthesis. It's a nit though, feel free not to address!

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 a lot @vmoens !

I made 2 minor comments but LGTM, feel free to self merge once addressed


scripted_fun = torch.jit.script(io._read_video_from_memory)
self.assertIsNotNone(scripted_fun)
assert scripted_fun
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert scripted_fun
assert scripted_fun is not None

lb = duration / 2 - 1 / md[stream]["fps"][0]
ub = duration / 2 + 1 / md[stream]["fps"][0]
self.assertTrue((lb <= frame["pts"]) & (ub >= frame["pts"]))
assert (lb <= frame["pts"]) & (ub >= frame["pts"])
Copy link
Member

Choose a reason for hiding this comment

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

It's not originally from this PR, but should this be and instead of &?

@vmoens vmoens closed this Aug 2, 2021
@vmoens vmoens reopened this Aug 2, 2021
@vmoens vmoens merged commit 16b9a40 into pytorch:master Aug 2, 2021
@github-actions
Copy link

github-actions bot commented Aug 2, 2021

Hey @vmoens!

You merged this PR, but no labels were added.

facebook-github-bot pushed a commit that referenced this pull request Aug 3, 2021
Summary:
* test_video_reader pytest refactoring

* pytest refactoring of test_videoapi.py

* test_video_reader pytest refactoring

* pytest refactoring of test_videoapi.py

* using pytest.approx for test_video_reader.py

* using pytest.approx for test_videoapi.py

* Fixing minor comments

* linting fixes

* minor comments

Reviewed By: NicolasHug

Differential Revision: D30069951

fbshipit-source-id: 26ef4fe4c8373231c764cf8d557b770447563edc

Co-authored-by: Vincent Moens <[email protected]>
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