-
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
Replace get_tmp_dir() with tmpdir fixture in pytest #4280
Conversation
Hi @ccongge! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
We can safely ignore the
|
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.
Thanks a lot @ccongge , this look great! I made a few comments below but this is in good shape already
test/test_datasets_samplers.py
Outdated
def test_random_clip_sampler(self): | ||
with get_list_of_videos(num_videos=3, sizes=[25, 25, 25]) as video_list: | ||
def test_random_clip_sampler(self, tmpdir): | ||
with get_list_of_videos(tmpdir, num_videos=3, sizes=[25, 25, 25]) as video_list: |
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 think that get_list_of_videos
was written as a context manager because it was relying on get_tmp_dir()
which was itself a context manager.
But now that we're getting rid of get_tmp_dir()
, I believe we should be able to convert get_list_of_videos()
into a simple function: we can remove the @contextlib.contextmanager
decorator and change yield
into a return
. And here, we could just do
video_list = get_list_of_videos(tmpdir, num_videos=3, sizes=[25, 25, 25])
and indent everything to the left
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.
Thanks, edited. :)
test/test_datasets_video_utils.py
Outdated
io.write_video(name, data, fps=f) | ||
|
||
yield names | ||
def get_list_of_videos(tmpdir, num_videos=5, sizes=None, fps=None): |
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.
Oh, I'm discovering now that this function is duplicated. Let's get rid of both context managers (in this file and the other one above) and instead put the function version that I suggested in common_utils.py
.
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.
Thanks, edited. :)
test/test_transforms_tensor.py
Outdated
@pytest.mark.parametrize('device', cpu_and_gpu()) | ||
class TestColorJitter: | ||
|
||
@pytest.mark.parametrize('brightness', [0.1, 0.5, 1.0, 1.34, (0.3, 0.7), [0.4, 0.5]]) | ||
def test_color_jitter_brightness(self, brightness, device): | ||
@pytest.fixture() |
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.
We should remove all the newly added @pytest.fixture()
decorators, as this transforms the test into a fixture, and the test doesn't get run
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.
Thanks, edited. :)
test/test_transforms_tensor.py
Outdated
@@ -85,13 +84,12 @@ def _test_class_op(method, device, meth_kwargs=None, test_exact_match=True, **ma | |||
batch_tensors = _create_data_batch(height=23, width=34, channels=3, num_samples=4, device=device) | |||
_test_transform_vs_scripted_on_batch(f, scripted_fn, batch_tensors) | |||
|
|||
with get_tmp_dir() as tmp_dir: | |||
scripted_fn.save(os.path.join(tmp_dir, f"t_{method.__name__}.pt")) | |||
scripted_fn.save(os.path.join(tmp_dir, f"t_{method.__name__}.pt")) |
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.
hm, the structure of the tests in this file is slightly awkward (for various historical reasons), and it makes it a bit cumbersome to pass the tmpdir
fixture from the actual test_...()
function all the way down to here.
So I would instead suggest to actually just rely on our custom get_tmp_dir()
function for this and revert those bits. I'll try to find a cleaner solution in the future, potentially refactoring further those tests. This means that we should put back get_tmp_dir()
in the common_utils.py
file (sorry for the extra work!)
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.
Yes. That is also what I was wondering. I moved get_tmp_dir() back to common_utils.py but still replaced other get_tmp_dir() with tmpdir fixsure except the one in _test_class_op().
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.
Thanks a lot @ccongge ! LGTM
Summary: * Replace in test_datasets* * Replace in test_image.py * Replace in test_transforms_tensor.py * Replace in test_internet.py and test_io.py * get_list_of_videos is util function still use get_tmp_dir * Fix get_list_of_videos siginiture * Add get_tmp_dir import * Modify test_datasets_video_utils.py for test to pass * Fix indentation * Replace get_tmp_dir in util functions in test_dataset_sampler.py * Replace get_tmp_dir in util functions in test_dataset_video_utils.py * Move get_tmp_dir() to datasets_utils.py and refactor * Fix pylint, indentation and imports * import shutil to common_util.py * Fix function signiture * Remove get_list_of_videos under context manager * Move get_list_of_videos to common_utils.py * Move get_tmp_dir() back to common_utils.py * Fix pylint and imports Reviewed By: NicolasHug Differential Revision: D30417192 fbshipit-source-id: fd5ae2ad7f21509dbe09f7df85f8d9006b9ed1ea Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
Per title.