Skip to content

Commit

Permalink
fix assert_run_python_script on Windows (#7346)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmeier authored Feb 27, 2023
1 parent af04819 commit 120e7af
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
17 changes: 10 additions & 7 deletions test/common_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,17 +844,20 @@ def get_closeness_kwargs(self, test_id, *, dtype, device):

def assert_run_python_script(source_code):
"""Utility to check assertions in an independent Python subprocess.
The script provided in the source code should return 0 and not print
anything on stderr or stdout. Taken from scikit-learn test utils.
source_code (str): The Python source code to execute.
anything on stderr or stdout. Modified from scikit-learn test utils.
Args:
source_code (str): The Python source code to execute.
"""
with tempfile.NamedTemporaryFile(mode="wb") as f:
f.write(source_code.encode())
f.flush()
with get_tmp_dir() as root:
path = pathlib.Path(root) / "main.py"
with open(path, "w") as file:
file.write(source_code)

cmd = [sys.executable, f.name]
try:
out = check_output(cmd, stderr=STDOUT)
out = check_output([sys.executable, str(path)], stderr=STDOUT)
except CalledProcessError as e:
raise RuntimeError(f"script errored with output:\n{e.output.decode()}")
if out != b"":
Expand Down
5 changes: 0 additions & 5 deletions test/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import random
import re
import sys
import textwrap
import warnings
from functools import partial
Expand Down Expand Up @@ -2279,10 +2278,6 @@ def test_random_grayscale_with_grayscale_input():
),
)
@pytest.mark.parametrize("from_private", (True, False))
@pytest.mark.skipif(
sys.platform in ("win32", "cygwin"),
reason="assert_run_python_script is broken on Windows. Possible fix in https://github.com/pytorch/vision/pull/7346",
)
def test_functional_deprecation_warning(import_statement, from_private):
if from_private:
import_statement = import_statement.replace("functional", "_functional")
Expand Down
9 changes: 0 additions & 9 deletions test/test_transforms_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import pathlib
import random
import re
import sys
import textwrap
import warnings
from collections import defaultdict
Expand Down Expand Up @@ -2102,10 +2101,6 @@ def test_sanitize_bounding_boxes_errors():
),
)
@pytest.mark.parametrize("call_disable_warning", (True, False))
@pytest.mark.skipif(
sys.platform in ("win32", "cygwin"),
reason="assert_run_python_script is broken on Windows. Possible fix in https://github.com/pytorch/vision/pull/7346",
)
def test_warnings_v2_namespaces(import_statement, call_disable_warning):
if call_disable_warning:
source = f"""
Expand All @@ -2125,10 +2120,6 @@ def test_warnings_v2_namespaces(import_statement, call_disable_warning):
assert_run_python_script(textwrap.dedent(source))


@pytest.mark.skipif(
sys.platform in ("win32", "cygwin"),
reason="assert_run_python_script is broken on Windows. Possible fix in https://github.com/pytorch/vision/pull/7346",
)
def test_no_warnings_v1_namespace():
source = """
import warnings
Expand Down

0 comments on commit 120e7af

Please sign in to comment.