-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Add warnings checks for v2 namespaces #7288
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
Changes from 3 commits
b19c3c9
24d3ff7
584f637
4972fb3
020e823
7840082
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,11 +4,12 @@ | |
| import pytest | ||
| import torch | ||
| import torchvision | ||
| from common_utils import CUDA_NOT_AVAILABLE_MSG, IN_FBCODE, IN_OSS_CI, IN_RE_WORKER, OSS_CI_GPU_NO_CUDA_MSG | ||
|
|
||
|
|
||
| torchvision.disable_beta_transforms_warning() | ||
|
|
||
| from common_utils import CUDA_NOT_AVAILABLE_MSG, IN_FBCODE, IN_OSS_CI, IN_RE_WORKER, OSS_CI_GPU_NO_CUDA_MSG | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you add this for #7265 or because we actually need it for these tests. I'm not against it, but want to make sure I understand correctly.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
|
|
||
| def pytest_configure(config): | ||
| # register an additional marker (see pytest_collection_modifyitems) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| import os | ||
| import random | ||
| import re | ||
| import textwrap | ||
| import warnings | ||
| from functools import partial | ||
|
|
||
|
|
@@ -24,7 +25,7 @@ | |
| except ImportError: | ||
| stats = None | ||
|
|
||
| from common_utils import assert_equal, cycle_over, float_dtypes, int_dtypes | ||
| from common_utils import assert_equal, assert_run_python_script, cycle_over, float_dtypes, int_dtypes | ||
|
|
||
|
|
||
| GRACE_HOPPER = get_file_path_2( | ||
|
|
@@ -2266,5 +2267,49 @@ def test_random_grayscale_with_grayscale_input(): | |
| torch.testing.assert_close(F.pil_to_tensor(output_pil), image_tensor) | ||
|
|
||
|
|
||
| def test_no_warnings_v1_namespace(): | ||
| source = """ | ||
| import warnings | ||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter("error") | ||
| import torchvision.transforms | ||
| from torchvision import transforms | ||
| import torchvision.transforms.functional | ||
| from torchvision.transforms import Resize | ||
| from torchvision.transforms.functional import resize | ||
| """ | ||
| assert_run_python_script(textwrap.dedent(source)) | ||
|
|
||
|
|
||
| # TODO: remove in 0.17 when we can delete functional_pil.py and functional_tensor.py | ||
| @pytest.mark.parametrize( | ||
| "import_statement", | ||
| ( | ||
| "from torchvision.transforms import functional_pil", | ||
| "from torchvision.transforms import functional_tensor", | ||
| "from torchvision.transforms.functional_tensor import resize", | ||
| "from torchvision.transforms.functional_pil import resize", | ||
| ), | ||
| ) | ||
| @pytest.mark.parametrize("from_private", (True, False)) | ||
| def test_functional_deprecation_warning(import_statement, from_private): | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realize this is slightly overkill, we don't need |
||
| if from_private: | ||
| import_statement = import_statement.replace("functional", "_functional") | ||
| prelude = """ | ||
| import warnings | ||
|
|
||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter("error") | ||
| """ | ||
| else: | ||
| prelude = """ | ||
| import pytest | ||
| with pytest.warns(UserWarning, match="removed in 0.17"): | ||
| """ | ||
|
|
||
| source = prelude + " " * 4 + import_statement | ||
| assert_run_python_script(textwrap.dedent(source)) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| pytest.main([__file__]) | ||
Uh oh!
There was an error while loading. Please reload this page.