def test_trigger_update_debug(for_py_version, session_app_data, tmp_path, mocker, monkeypatch): monkeypatch.setenv(str("_VIRTUALENV_PERIODIC_UPDATE_INLINE"), str("1")) current = get_embed_wheel("pip", for_py_version) process = mocker.MagicMock() process.communicate.return_value = None, None Popen = mocker.patch("virtualenv.seed.wheels.periodic_update.Popen", return_value=process) trigger_update("pip", for_py_version, current, [tmp_path / "a", tmp_path / "b"], session_app_data, os.environ, False) assert Popen.call_count == 1 args, kwargs = Popen.call_args cmd = (dedent( """ from virtualenv.report import setup_report, MAX_LEVEL from virtualenv.seed.wheels.periodic_update import do_update setup_report(MAX_LEVEL, show_pid=True) do_update({!r}, {!r}, {!r}, {!r}, {!r}, {!r}) """, ).strip().format( "pip", for_py_version, str(current.path), str(session_app_data), [str(tmp_path / "a"), str(tmp_path / "b")], False, )) assert args == ([sys.executable, "-c", cmd], ) expected = {"stdout": None, "stderr": None} assert kwargs == expected assert process.communicate.call_count == 1
def test_trigger_update_no_debug(for_py_version, session_app_data, tmp_path, mocker, monkeypatch): monkeypatch.delenv(str("_VIRTUALENV_PERIODIC_UPDATE_INLINE"), raising=False) current = get_embed_wheel("setuptools", for_py_version) process = mocker.MagicMock() process.communicate.return_value = None, None Popen = mocker.patch("virtualenv.seed.wheels.periodic_update.Popen", return_value=process) trigger_update("setuptools", for_py_version, current, [tmp_path / "a", tmp_path / "b"], session_app_data, True) assert Popen.call_count == 1 args, kwargs = Popen.call_args cmd = ( dedent( """ from virtualenv.report import setup_report, MAX_LEVEL from virtualenv.seed.wheels.periodic_update import do_update setup_report(MAX_LEVEL, show_pid=True) do_update({!r}, {!r}, {!r}, {!r}, {!r}, {!r}) """, ) .strip() .format( "setuptools", for_py_version, str(current.path), str(session_app_data), [str(tmp_path / "a"), str(tmp_path / "b")], True, ) ) assert args == ([sys.executable, "-c", cmd],) expected = {"stdout": subprocess.PIPE, "stderr": subprocess.PIPE} if sys.platform == "win32": expected["creationflags"] = DETACHED_PROCESS assert kwargs == expected assert process.communicate.call_count == 0