diff options
author | Florian Bruhin <me@the-compiler.org> | 2021-03-23 11:05:57 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2021-03-23 12:53:23 +0100 |
commit | d9caaffa14d00fd09bd4ada11283ccedc523b680 (patch) | |
tree | 0cb20f151bdf6e69887d73d6eb0f8e07bed61897 /tests/unit/completion/test_models.py | |
parent | bc020e06ee457cc00b68d2bbafbd0279ad478a22 (diff) | |
download | qutebrowser-d9caaffa14d00fd09bd4ada11283ccedc523b680.tar.gz qutebrowser-d9caaffa14d00fd09bd4ada11283ccedc523b680.zip |
Add a test for :process completion
Diffstat (limited to 'tests/unit/completion/test_models.py')
-rw-r--r-- | tests/unit/completion/test_models.py | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index 12e623517..c60741c4c 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.py @@ -31,7 +31,7 @@ from unittest import mock import hypothesis import hypothesis.strategies as hst import pytest -from PyQt5.QtCore import QUrl, QDateTime +from PyQt5.QtCore import QUrl, QDateTime, QProcess try: from PyQt5.QtWebEngineWidgets import ( QWebEngineHistory, QWebEngineHistoryItem @@ -39,7 +39,7 @@ try: except ImportError: pass -from qutebrowser.misc import objects +from qutebrowser.misc import objects, guiprocess from qutebrowser.completion import completer from qutebrowser.completion.models import ( configmodel, listcategory, miscmodels, urlmodel, filepathcategory) @@ -1447,6 +1447,52 @@ def undo_completion_retains_sort_order(tabbed_browser_stubs, info): _check_completions(model, {"Closed tabs": expected}) +def test_process_completion(monkeypatch, stubs, info): + monkeypatch.setattr(guiprocess, 'QProcess', stubs.FakeProcess) + p1 = guiprocess.GUIProcess('testprocess') + p2 = guiprocess.GUIProcess('testprocess') + p3 = guiprocess.GUIProcess('editor') + + p1.pid = 1001 + p1.cmd = 'cmd1' + p1.args = [] + p1.outcome.running = False + p1.outcome.status = QProcess.NormalExit + p1.outcome.code = 0 + + p2.pid = 1002 + p2.cmd = 'cmd2' + p2.args = [] + p2.outcome.running = True + + p3.pid = 1003 + p3.cmd = 'cmd3' + p3.args = [] + p3.outcome.running = False + p3.outcome.status = QProcess.NormalExit + p3.outcome.code = 1 + + monkeypatch.setattr(guiprocess, 'all_processes', { + 1001: p1, + 1002: p2, + 1003: p3, + }) + + model = miscmodels.process(info=info) + model.set_pattern('') + + expected = { + 'Testprocess': [ + ('1001', 'successful', 'cmd1'), + ('1002', 'running', 'cmd2'), + ], + 'Editor': [ + ('1003', 'unsuccessful', 'cmd3'), + ], + } + _check_completions(model, expected) + + @hypothesis.given(text=hst.text()) def test_listcategory_hypothesis(text): """Make sure we can't produce invalid patterns.""" |