# Path: mu/virtual_environment.py
# ENCODING = sys.stdout.encoding if hasattr(sys.stdout, "encoding") else "utf-8"
# class VirtualEnvironmentError(Exception):
# class VirtualEnvironmentEnsureError(VirtualEnvironmentError):
# class VirtualEnvironmentCreateError(VirtualEnvironmentError):
# class Process(QObject):
# class Pip(object):
# class SplashLogHandler(logging.NullHandler):
# class VirtualEnvironment(object):
#     def __init__(self, message):
# def compact(text):
#     def __init__(self):
#     def _set_up_run(self, **envvars):
#     def run_blocking(self, command, args, wait_for_s=30.0, **envvars):
#     def run(self, command, args, **envvars):
#     def wait(self, wait_for_s=30):
#     def data(self):
#     def _started(self):
#     def _readyRead(self):
#     def _finished(self):
#     def __init__(self, pip_executable):
#     def run(
#         self, command, *args, wait_for_s=120.0, slots=Process.Slots(), **kwargs
#     ):
#     def install(self, packages, slots=Process.Slots(), **kwargs):
#     def uninstall(self, packages, slots=Process.Slots(), **kwargs):
#     def freeze(self):
#     def list(self):
#     def installed(self):
#     def __init__(self, emitter):
#     def emit(self, record):
#     def handle(self, record):
#     def __init__(self, dirpath=None):
#     def __str__(self):
#     def _generate_dirpath():
#     def run_subprocess(self, *args, **kwargs):
#     def reset_pip(self):
#     def relocate(self, dirpath):
#     def run_python(self, *args, slots=Process.Slots()):
#     def _directory_is_venv(self):
#     def quarantine_venv(self, reason="FAILED"):
#     def recreate(self):
#     def ensure_and_create(self, emitter=None):
#     def ensure(self):
#     def ensure_path(self):
#     def ensure_interpreter(self):
#     def ensure_interpreter_version(self):
#     def ensure_key_modules(self):
#     def ensure_pip(self):
#     def create(self):
#     def create_venv(self):
#     def install_jupyter_kernel(self):
#     def install_from_zipped_wheels(self, zipped_wheels_filepath):
#     def install_baseline_packages(self):
#     def register_baseline_packages(self):
#     def baseline_packages(self):
#     def install_user_packages(self, packages, slots=Process.Slots()):
#     def remove_user_packages(self, packages, slots=Process.Slots()):
#     def installed_packages(self):


import os
import pytest
import mu.interface.dialogs
from PyQt5.QtWidgets import QDialog, QWidget, QDialogButtonBox
from unittest import mock
from mu import virtual_environment
from mu.modes import (
    PythonMode,
    CircuitPythonMode,
    MicrobitMode,
    DebugMode,
    ESPMode,
)
from PyQt5.QtCore import QProcess
    """
    Ensure the expected package to be installed is done so via the expected
    correct call to "pip" in a new process (as per the recommended way to
    us "pip").
    """
    pd = mu.interface.dialogs.PackageDialog()
    venv = virtual_environment.VirtualEnvironment(".")
    mock_process = mock.MagicMock()
    with mock.patch("mu.interface.dialogs.QProcess", mock_process):
        pd.setup({}, {"foo"})
        pd.process.readyRead.connect.assert_called_once_with(pd.read_process)
        pd.process.finished.connect.assert_called_once_with(pd.finished)
        args = [
            "-m",  # run the module
            "pip",  # called pip
            "install",  # to install
            "foo",  # a package called "foo"
        ]
        pd.process.start.assert_called_once_with(venv.interpreter, args)


@pytest.mark.skip(reason="Superseded probably by virtual environment work")
def test_PackageDialog_finished_with_more_to_remove():
    """
    When the pip process is finished, check if there are more packages to
    install and run again.
    """
    pd = mu.interface.dialogs.PackageDialog()
    pd.run_pip = mock.MagicMock()
    pd.process = mock.MagicMock()

# Path: mu/virtual_environment.py
# ENCODING = sys.stdout.encoding if hasattr(sys.stdout, "encoding") else "utf-8"
# class VirtualEnvironmentError(Exception):
# class VirtualEnvironmentEnsureError(VirtualEnvironmentError):
# class VirtualEnvironmentCreateError(VirtualEnvironmentError):
# class Process(QObject):
# class Pip(object):
# class SplashLogHandler(logging.NullHandler):
# class VirtualEnvironment(object):
#     def __init__(self, message):
# def compact(text):
#     def __init__(self):
#     def _set_up_run(self, **envvars):
#     def run_blocking(self, command, args, wait_for_s=30.0, **envvars):
#     def run(self, command, args, **envvars):
#     def wait(self, wait_for_s=30):
#     def data(self):
#     def _started(self):
#     def _readyRead(self):
#     def _finished(self):
#     def __init__(self, pip_executable):
#     def run(
#         self, command, *args, wait_for_s=120.0, slots=Process.Slots(), **kwargs
#     ):
#     def install(self, packages, slots=Process.Slots(), **kwargs):
#     def uninstall(self, packages, slots=Process.Slots(), **kwargs):
#     def freeze(self):
#     def list(self):
#     def installed(self):
#     def __init__(self, emitter):
#     def emit(self, record):
#     def handle(self, record):
#     def __init__(self, dirpath=None):
#     def __str__(self):
#     def _generate_dirpath():
#     def run_subprocess(self, *args, **kwargs):
#     def reset_pip(self):
#     def relocate(self, dirpath):
#     def run_python(self, *args, slots=Process.Slots()):
#     def _directory_is_venv(self):
#     def quarantine_venv(self, reason="FAILED"):
#     def recreate(self):
#     def ensure_and_create(self, emitter=None):
#     def ensure(self):
#     def ensure_path(self):
#     def ensure_interpreter(self):
#     def ensure_interpreter_version(self):
#     def ensure_key_modules(self):
#     def ensure_pip(self):
#     def create(self):
#     def create_venv(self):
#     def install_jupyter_kernel(self):
#     def install_from_zipped_wheels(self, zipped_wheels_filepath):
#     def install_baseline_packages(self):
#     def register_baseline_packages(self):
#     def baseline_packages(self):
#     def install_user_packages(self, packages, slots=Process.Slots()):
#     def remove_user_packages(self, packages, slots=Process.Slots()):
#     def installed_packages(self):


# Path: tests/interface/test_dialogs.py
import os
import pytest
import mu.interface.dialogs
from PyQt5.QtWidgets import QDialog, QWidget, QDialogButtonBox
from unittest import mock
from mu import virtual_environment
from mu.modes import (
    PythonMode,
    CircuitPythonMode,
    MicrobitMode,
    DebugMode,
    ESPMode,
)
from PyQt5.QtCore import QProcess

    """
    Ensure the expected package to be installed is done so via the expected
    correct call to "pip" in a new process (as per the recommended way to
    us "pip").
    """
    pd = mu.interface.dialogs.PackageDialog()
    venv = virtual_environment.VirtualEnvironment(".")
    mock_process = mock.MagicMock()
    with mock.patch("mu.interface.dialogs.QProcess", mock_process):
        pd.setup({}, {"foo"})
        pd.process.readyRead.connect.assert_called_once_with(pd.read_process)
        pd.process.finished.connect.assert_called_once_with(pd.finished)
        args = [
            "-m",  # run the module
            "pip",  # called pip
            "install",  # to install
            "foo",  # a package called "foo"
        ]
        pd.process.start.assert_called_once_with(venv.interpreter, args)


@pytest.mark.skip(reason="Superseded probably by virtual environment work")
def test_PackageDialog_finished_with_more_to_remove():
    """
    When the pip process is finished, check if there are more packages to
    install and run again.
    """
    pd = mu.interface.dialogs.PackageDialog()
    pd.run_pip = mock.MagicMock()
    pd.process = mock.MagicMock()

    venv = virtual_environment.VirtualEnvironment(".")