Skip to content

Commit

Permalink
Reduce test execution time
Browse files Browse the repository at this point in the history
  • Loading branch information
andfoy committed Jul 28, 2017
1 parent 9519d87 commit 940e12d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion spyder_terminal/server/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function scrollTerm(delta) {
}

function isAlive() {
return alive
return alive;
}

function runRealTerminal() {
Expand Down
2 changes: 2 additions & 0 deletions spyder_terminal/terminalplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class TerminalPlugin(SpyderPluginWidget):
URL_ISSUES = ' https://github.com/spyder-ide/spyder-terminal/issues'
CONF_SECTION = 'terminal'
focus_changed = Signal()
server_is_ready = Signal()
MAX_SERVER_CONTACT_RETRIES = 40

def __init__(self, parent):
Expand Down Expand Up @@ -158,6 +159,7 @@ def __wait_server_to_start(self):
self.server_retries += 1
QTimer.singleShot(250, self.__wait_server_to_start)
elif code == 200:
self.server_is_ready.emit()
self.create_new_term(give_focus=False)

# ------ SpyderPluginMixin API --------------------------------
Expand Down
27 changes: 16 additions & 11 deletions spyder_terminal/tests/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def setup_terminal(qtbot):
def test_terminal_font(qtbot):
"""Test if terminal loads a custom font."""
terminal = setup_terminal(qtbot)
qtbot.wait(TERM_UP)
blocker = qtbot.waitSignal(terminal.server_is_ready, timeout=TERM_UP)
blocker.wait()
qtbot.wait(2000)

term = terminal.get_current_term()
port = terminal.port
Expand All @@ -81,7 +83,9 @@ def test_terminal_font(qtbot):
def test_terminal_tab_title(qtbot):
"""Test if terminal tab titles are numbered sequentially."""
terminal = setup_terminal(qtbot)
qtbot.wait(TERM_UP)
blocker = qtbot.waitSignal(terminal.server_is_ready, timeout=TERM_UP)
blocker.wait()
qtbot.wait(2000)
terminal.create_new_term()
terminal.create_new_term()
num_1 = int(terminal.tabwidget.tabText(1)[-1])
Expand All @@ -94,7 +98,9 @@ def test_new_terminal(qtbot):
"""Test if a new terminal is added."""
# Setup widget
terminal = setup_terminal(qtbot)
qtbot.wait(TERM_UP)
blocker = qtbot.waitSignal(terminal.server_is_ready, timeout=TERM_UP)
blocker.wait()
qtbot.wait(2000)

# Test if server is running
port = terminal.port
Expand Down Expand Up @@ -137,22 +143,21 @@ def test_output_redirection(qtbot):


def test_close_terminal_manually(qtbot):
"""Test if terminal tab is closed after process was finished manually."""
# Setup widget
terminal = setup_terminal(qtbot)
qtbot.wait(TERM_UP)

# Test if server is running
port = terminal.port
status_code = requests.get('http://127.0.0.1:{}'.format(port)).status_code
assert status_code == 200
blocker = qtbot.waitSignal(terminal.server_is_ready, timeout=TERM_UP)
blocker.wait()
qtbot.wait(2000)

terminal.create_new_term()
initial_num = terminal.tabwidget.count()
initial_num = len(terminal.get_terms())
term = terminal.get_current_term()
qtbot.wait(1000)

term.exec_cmd(EXIT)
qtbot.wait(5000)
qtbot.wait(1000)

final_num = terminal.tabwidget.count()
final_num = len(terminal.get_terms())
assert final_num == initial_num - 1
16 changes: 11 additions & 5 deletions spyder_terminal/widgets/terminalgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

class TerminalWidget(QFrame):
"""Terminal widget."""

terminal_closed = Signal()
terminal_ready = Signal()

def __init__(self, parent, port, path='~', font=None):
"""Frame main constructor."""
Expand All @@ -44,7 +46,7 @@ def __init__(self, parent, port, path='~', font=None):
self.body = self.view.document

self.view.page().loadFinished.connect(self.setup_term)
QTimer.singleShot(250, self.is_alive)
QTimer.singleShot(250, self.__alive_loopback)

@Slot(bool)
def setup_term(self, finished):
Expand Down Expand Up @@ -76,13 +78,17 @@ def exec_cmd(self, cmd):
"""Execute a command inside the terminal."""
self.eval_javascript('exec("{0}")'.format(cmd))

def is_alive(self):
"""Check if terminal process is alive."""
alive = self.eval_javascript('isAlive()')
def __alive_loopback(self):
alive = self.is_alive()
if not alive:
self.terminal_closed.emit()
else:
QTimer.singleShot(250, self.is_alive)
QTimer.singleShot(250, self.__alive_loopback)

def is_alive(self):
"""Check if terminal process is alive."""
alive = self.eval_javascript('isAlive()')
return alive


class TermView(WebView):
Expand Down

0 comments on commit 940e12d

Please sign in to comment.