<s> import os <EOL> import sys <EOL> from pyqode . core . api import CodeEdit <EOL> from pyqode . core . backend import NotRunning <EOL> from pyqode . qt import QtWidgets <EOL> import pytest <EOL> from pyqode . qt . QtTest import QTest <EOL> from pyqode . core import backend <EOL> from pyqode . core . managers . backend import BackendManager <EOL> from . . helpers import cwd_at , python2_path , server_path , wait_for_connected <EOL> from . . helpers import editor_open , ensure_connected <EOL> @ editor_open ( __file__ ) <EOL> @ ensure_connected <EOL> def test_exit_code ( editor ) : <EOL> assert editor . backend . running <EOL> assert editor . backend . exit_code is None <EOL> editor . backend . stop ( ) <EOL> assert not editor . backend . running <EOL> backend_manager = None <EOL> def _on_receive ( results ) : <EOL> """<STR_LIT>""" <EOL> assert results == '<STR_LIT>' <EOL> app = QtWidgets . QApplication . instance ( ) <EOL> app . exit ( <NUM_LIT:0> ) <EOL> def _send_request ( ) : <EOL> """<STR_LIT>""" <EOL> global backend_manager <EOL> backend_manager . send_request ( backend . echo_worker , '<STR_LIT>' , <EOL> on_receive = _on_receive ) <EOL> @ cwd_at ( '<STR_LIT:test>' ) <EOL> def test_client_server ( ) : <EOL> """<STR_LIT>""" <EOL> global backend_manager <EOL> win = QtWidgets . QMainWindow ( ) <EOL> backend_manager = BackendManager ( win ) <EOL> with pytest . raises ( NotRunning ) : <EOL> backend_manager . send_request ( <EOL> backend . echo_worker , '<STR_LIT>' , on_receive = _on_receive ) <EOL> backend_manager . start ( os . path . join ( os . getcwd ( ) , '<STR_LIT>' ) ) <EOL> backend_manager . _process . started . connect ( _send_request ) <EOL> QTest . qWait ( <NUM_LIT:1000> ) <EOL> backend_manager . stop ( ) <EOL> del backend_manager <EOL> del win <EOL> def test_client_server_py2 ( editor ) : <EOL> """<STR_LIT>""" <EOL> editor . backend . stop ( ) <EOL> with pytest . raises ( NotRunning ) : <EOL> editor . backend . send_request ( <EOL> backend . echo_worker , '<STR_LIT>' , on_receive = _on_receive ) <EOL> if os . path . exists ( python2_path ( ) ) : <EOL> editor . backend . start ( server_path ( ) , interpreter = python2_path ( ) ) <EOL> wait_for_connected ( editor ) <EOL> editor . backend . send_request ( <EOL> backend . echo_worker , '<STR_LIT>' , on_receive = _on_receive ) <EOL> QTest . qWait ( <NUM_LIT> ) <EOL> editor . backend . stop ( ) <EOL> editor . backend . start ( server_path ( ) ) <EOL> def test_frozen_server ( ) : <EOL> global backend_manager <EOL> win = QtWidgets . QMainWindow ( ) <EOL> backend_manager = BackendManager ( win ) <EOL> with pytest . raises ( NotRunning ) : <EOL> backend_manager . send_request ( <EOL> backend . echo_worker , '<STR_LIT>' , on_receive = _on_receive ) <EOL> backend_manager . start ( '<STR_LIT>' ) </s>
