Skip to content

Remove Python 2 virtualenv tests #10846

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 10 additions & 20 deletions mypy/test/testpep561.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
from subprocess import PIPE
import sys
import tempfile
from typing import Tuple, List, Generator
from typing import Tuple, List, Iterator

import mypy.api
from mypy.test.config import package_path
from mypy.util import try_find_python2_interpreter
from mypy.test.data import DataDrivenTestCase, DataSuite
from mypy.test.config import test_temp_dir
from mypy.test.helpers import assert_string_arrays_equal
Expand Down Expand Up @@ -44,23 +43,19 @@ def run_case(self, test_case: DataDrivenTestCase) -> None:


@contextmanager
def virtualenv(
python_executable: str = sys.executable
) -> Generator[Tuple[str, str], None, None]:
def virtualenv(python_executable: str = sys.executable) -> Iterator[Tuple[str, str]]:
"""Context manager that creates a virtualenv in a temporary directory

returns the path to the created Python executable"""
# Sadly, we need virtualenv, as the Python 3 venv module does not support creating a venv
# for Python 2, and Python 2 does not have its own venv.
Returns the path to the created Python executable
"""
with tempfile.TemporaryDirectory() as venv_dir:
proc = subprocess.run([sys.executable,
'-m',
'virtualenv',
'-p{}'.format(python_executable),
venv_dir], cwd=os.getcwd(), stdout=PIPE, stderr=PIPE)
proc = subprocess.run(
[python_executable, '-m', 'venv', venv_dir],
cwd=os.getcwd(), stdout=PIPE, stderr=PIPE
)
if proc.returncode != 0:
err = proc.stdout.decode('utf-8') + proc.stderr.decode('utf-8')
raise Exception("Failed to create venv. Do you have virtualenv installed?\n" + err)
raise Exception("Failed to create venv.\n" + err)
if sys.platform == 'win32':
yield venv_dir, os.path.abspath(os.path.join(venv_dir, 'Scripts', 'python'))
else:
Expand Down Expand Up @@ -96,12 +91,7 @@ def test_pep561(testcase: DataDrivenTestCase) -> None:
sys.base_prefix != sys.prefix):
pytest.skip()
assert testcase.old_cwd is not None, "test was not properly set up"
if 'python2' in testcase.name.lower():
python = try_find_python2_interpreter()
if python is None:
pytest.skip()
else:
python = sys.executable
python = sys.executable
assert python is not None, "Should be impossible"
pkgs, pip_args = parse_pkgs(testcase.input[0])
mypy_args = parse_mypy_args(testcase.input[1])
Expand Down
18 changes: 9 additions & 9 deletions mypyc/test-data/run-imports.test
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ def test_import_as_submodule_within_function() -> None:
# assert 'nob' not in globals()

def test_import_module_without_stub_in_function() -> None:
# 'virtualenv' must not have a stub in typeshed for this test case
import virtualenv # type: ignore
# 'psutil' must not have a stub in typeshed for this test case
import psutil # type: ignore
# TODO: We shouldn't add local imports to globals()
# assert 'virtualenv' not in globals()
assert isinstance(virtualenv.__name__, str)
# assert 'psutil' not in globals()
assert isinstance(psutil.__name__, str)

def test_import_as_module_without_stub_in_function() -> None:
# 'virtualenv' must not have a stub in typeshed for this test case
import virtualenv as vv # type: ignore
assert 'virtualenv' not in globals()
# 'psutil' must not have a stub in typeshed for this test case
import psutil as pp # type: ignore
assert 'psutil' not in globals()
# TODO: We shouldn't add local imports to globals()
# assert 'vv' not in globals()
assert isinstance(vv.__name__, str)
# assert 'pp' not in globals()
assert isinstance(pp.__name__, str)

[file testmodule.py]
def factorial(x: int) -> int:
Expand Down
19 changes: 0 additions & 19 deletions test-data/unit/pep561.test
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,6 @@ reveal_type(a)
[out]
testStubPrecedence.py:5: note: Revealed type is "builtins.list[builtins.str]"

[case testTypedPkgStubs_python2]
# pkgs: typedpkg-stubs
from typedpkg.sample import ex
from typedpkg import dne
a = ex([''])
reveal_type(a)
[out]
testTypedPkgStubs_python2.py:3: error: Module "typedpkg" has no attribute "dne"
testTypedPkgStubs_python2.py:5: note: Revealed type is "builtins.list[builtins.str]"

[case testTypedPkgSimple_python2]
# pkgs: typedpkg
from typedpkg.sample import ex
from typedpkg import dne
a = ex([''])
reveal_type(a)
[out]
testTypedPkgSimple_python2.py:5: note: Revealed type is "builtins.tuple[builtins.str]"

[case testTypedPkgSimpleEgg]
# pkgs: typedpkg; no-pip
from typedpkg.sample import ex
Expand Down
1 change: 0 additions & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ pytest-forked>=1.3.0,<2.0.0
pytest-cov>=2.10.0,<3.0.0
typing>=3.5.2; python_version < '3.5'
py>=1.5.2
virtualenv<20
setuptools!=50
importlib-metadata==0.20