# Path: spyder_notebook/utils/servermanager.py
# class ServerProcess():
#     """
#     Process executing a notebook server.
# 
#     This is a data class.
#     """
# 
#     def __init__(self, process, notebook_dir, interpreter, starttime=None,
#                  state=ServerState.STARTING, server_info=None, output=''):
#         """
#         Construct a ServerProcess.
# 
#         Parameters
#         ----------
#         process : QProcess
#             The process described by this instance.
#         notebook_dir : str
#             Directory from which the server can render notebooks.
#         interpreter : str
#             File name of Python interpreter used to render notebooks.
#         starttime : datetime or None, optional
#             Time at which the process was started. The default is None,
#             meaning that the current time should be used.
#         state : ServerState, optional
#             State of the server process. The default is ServerState.STARTING.
#         server_info : dict or None, optional
#             If set, this is a dict with information given by the server in
#             a JSON file in jupyter_runtime_dir(). It has keys like 'url' and
#             'token'. The default is None.
#         output : str
#             Output of the server process from stdout and stderr. The default
#             is ''.
#         """
#         self.process = process
#         self.notebook_dir = notebook_dir
#         self.interpreter = interpreter
#         self.starttime = starttime or datetime.datetime.now()
#         self.state = state
#         self.server_info = server_info
#         self.output = output
# 
# class ServerState(enum.Enum):
#     """State of a server process."""
# 
#     STARTING = 1
#     RUNNING = 2
#     FINISHED = 3
#     ERROR = 4
#     TIMED_OUT = 5
# 
# Path: spyder_notebook/widgets/serverinfo.py
# class ServerInfoDialog(BaseDialog):
#     """Dialog window showing information about notebook servers."""
# 
#     def __init__(self, server_info, parent=None):
#         """
#         Construct a RecoveryDialog.
# 
#         Parameters
#         ----------
#         servers : list of ServerProcess
#             Information to be displayed. This parameter is read only.
#         parent : QWidget, optional
#             Parent of the dialog window. The default is None.
#         """
#         super().__init__(parent)
#         self.servers = server_info
# 
#         self.setWindowTitle(_('Notebook server info'))
# 
#         self.layout = QVBoxLayout(self)
#         self.formlayout = QFormLayout()
#         self.layout.addLayout(self.formlayout)
# 
#         self.process_combo = QComboBox(self)
#         self.process_combo.currentIndexChanged.connect(self.select_process)
#         self.formlayout.addRow(_('Process ID:'), self.process_combo)
# 
#         self.dir_lineedit = QLineEdit(self)
#         self.dir_lineedit.setReadOnly(True)
#         self.formlayout.addRow(_('Notebook dir:'), self.dir_lineedit)
# 
#         self.interpreter_lineedit = QLineEdit(self)
#         self.interpreter_lineedit.setReadOnly(True)
#         self.formlayout.addRow(_('Python interpreter:'),
#                                self.interpreter_lineedit)
# 
#         self.state_lineedit = QLineEdit(self)
#         self.state_lineedit.setReadOnly(True)
#         self.formlayout.addRow(_('State:'), self.state_lineedit)
# 
#         self.log_textedit = QTextEdit(self)
#         self.log_textedit.setReadOnly(True)
#         self.layout.addWidget(self.log_textedit)
# 
#         self.buttonbox = QDialogButtonBox(QDialogButtonBox.Ok, self)
#         self.buttonbox.accepted.connect(self.accept)
#         self.refresh_button = QPushButton(_('Refresh'), self)
#         self.refresh_button.clicked.connect(self.refresh_data)
#         self.buttonbox.addButton(
#             self.refresh_button, QDialogButtonBox.ActionRole)
#         self.layout.addWidget(self.buttonbox)
# 
#         self.refresh_data()
# 
#     def refresh_data(self):
#         self.process_combo.clear()
#         for server in self.servers:
#             self.process_combo.addItem(str(server.process.processId()))
#         self.select_process(0)
# 
#     def select_process(self, index):
#         self.dir_lineedit.setText(self.servers[index].notebook_dir)
#         self.interpreter_lineedit.setText(self.servers[index].interpreter)
#         self.state_lineedit.setText(
#             SERVER_STATE_DESCRIPTIONS[self.servers[index].state])
#         self.log_textedit.setPlainText(self.servers[index].output)


import pytest
from spyder_notebook.utils.servermanager import ServerProcess, ServerState
from spyder_notebook.widgets.serverinfo import ServerInfoDialog
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
#

"""Tests for serverinfo.py."""

# Third party imports

# Local imports


class FakeProcess:
    """Fake for ServerProcess class."""

    def __init__(self, pid):
        self.pid = pid

    def processId(self):
        """Member function which needs to be faked."""
        return self.pid


@pytest.fixture
def dialog(qtbot):
    """Construct and return dialog window for testing."""
    servers = [ServerProcess(FakeProcess(42), '/my/home/dir',
                             interpreter='/ham/interpreter',
                             state=ServerState.RUNNING,
                             output='Nicely humming along...\n'),

# Path: spyder_notebook/utils/servermanager.py
# class ServerProcess():
#     """
#     Process executing a notebook server.
# 
#     This is a data class.
#     """
# 
#     def __init__(self, process, notebook_dir, interpreter, starttime=None,
#                  state=ServerState.STARTING, server_info=None, output=''):
#         """
#         Construct a ServerProcess.
# 
#         Parameters
#         ----------
#         process : QProcess
#             The process described by this instance.
#         notebook_dir : str
#             Directory from which the server can render notebooks.
#         interpreter : str
#             File name of Python interpreter used to render notebooks.
#         starttime : datetime or None, optional
#             Time at which the process was started. The default is None,
#             meaning that the current time should be used.
#         state : ServerState, optional
#             State of the server process. The default is ServerState.STARTING.
#         server_info : dict or None, optional
#             If set, this is a dict with information given by the server in
#             a JSON file in jupyter_runtime_dir(). It has keys like 'url' and
#             'token'. The default is None.
#         output : str
#             Output of the server process from stdout and stderr. The default
#             is ''.
#         """
#         self.process = process
#         self.notebook_dir = notebook_dir
#         self.interpreter = interpreter
#         self.starttime = starttime or datetime.datetime.now()
#         self.state = state
#         self.server_info = server_info
#         self.output = output
# 
# class ServerState(enum.Enum):
#     """State of a server process."""
# 
#     STARTING = 1
#     RUNNING = 2
#     FINISHED = 3
#     ERROR = 4
#     TIMED_OUT = 5
# 
# Path: spyder_notebook/widgets/serverinfo.py
# class ServerInfoDialog(BaseDialog):
#     """Dialog window showing information about notebook servers."""
# 
#     def __init__(self, server_info, parent=None):
#         """
#         Construct a RecoveryDialog.
# 
#         Parameters
#         ----------
#         servers : list of ServerProcess
#             Information to be displayed. This parameter is read only.
#         parent : QWidget, optional
#             Parent of the dialog window. The default is None.
#         """
#         super().__init__(parent)
#         self.servers = server_info
# 
#         self.setWindowTitle(_('Notebook server info'))
# 
#         self.layout = QVBoxLayout(self)
#         self.formlayout = QFormLayout()
#         self.layout.addLayout(self.formlayout)
# 
#         self.process_combo = QComboBox(self)
#         self.process_combo.currentIndexChanged.connect(self.select_process)
#         self.formlayout.addRow(_('Process ID:'), self.process_combo)
# 
#         self.dir_lineedit = QLineEdit(self)
#         self.dir_lineedit.setReadOnly(True)
#         self.formlayout.addRow(_('Notebook dir:'), self.dir_lineedit)
# 
#         self.interpreter_lineedit = QLineEdit(self)
#         self.interpreter_lineedit.setReadOnly(True)
#         self.formlayout.addRow(_('Python interpreter:'),
#                                self.interpreter_lineedit)
# 
#         self.state_lineedit = QLineEdit(self)
#         self.state_lineedit.setReadOnly(True)
#         self.formlayout.addRow(_('State:'), self.state_lineedit)
# 
#         self.log_textedit = QTextEdit(self)
#         self.log_textedit.setReadOnly(True)
#         self.layout.addWidget(self.log_textedit)
# 
#         self.buttonbox = QDialogButtonBox(QDialogButtonBox.Ok, self)
#         self.buttonbox.accepted.connect(self.accept)
#         self.refresh_button = QPushButton(_('Refresh'), self)
#         self.refresh_button.clicked.connect(self.refresh_data)
#         self.buttonbox.addButton(
#             self.refresh_button, QDialogButtonBox.ActionRole)
#         self.layout.addWidget(self.buttonbox)
# 
#         self.refresh_data()
# 
#     def refresh_data(self):
#         self.process_combo.clear()
#         for server in self.servers:
#             self.process_combo.addItem(str(server.process.processId()))
#         self.select_process(0)
# 
#     def select_process(self, index):
#         self.dir_lineedit.setText(self.servers[index].notebook_dir)
#         self.interpreter_lineedit.setText(self.servers[index].interpreter)
#         self.state_lineedit.setText(
#             SERVER_STATE_DESCRIPTIONS[self.servers[index].state])
#         self.log_textedit.setPlainText(self.servers[index].output)


# Path: spyder_notebook/widgets/tests/test_serverinfo.py
import pytest
from spyder_notebook.utils.servermanager import ServerProcess, ServerState
from spyder_notebook.widgets.serverinfo import ServerInfoDialog

#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
#

"""Tests for serverinfo.py."""

# Third party imports

# Local imports


class FakeProcess:
    """Fake for ServerProcess class."""

    def __init__(self, pid):
        self.pid = pid

    def processId(self):
        """Member function which needs to be faked."""
        return self.pid


@pytest.fixture
def dialog(qtbot):
    """Construct and return dialog window for testing."""
    servers = [ServerProcess(FakeProcess(42), '/my/home/dir',
                             interpreter='/ham/interpreter',
                             state=ServerState.RUNNING,
                             output='Nicely humming along...\n'),

               ServerProcess(FakeProcess(404), '/some/other/dir',