diff --git a/pytest_gui_status/status_gui/gui_backend.py b/pytest_gui_status/status_gui/gui_backend.py index 379b220..db885b6 100644 --- a/pytest_gui_status/status_gui/gui_backend.py +++ b/pytest_gui_status/status_gui/gui_backend.py @@ -8,6 +8,7 @@ import humanfriendly import os.path from ..utils import s from ..utils import REDIS_PORT +from PyQt4.QtGui import QApplication class Controller(htmlPy.Object): @@ -19,12 +20,30 @@ class Controller(htmlPy.Object): "end": "Finished Tests" } + dict_tmpl = { + "default": "index.html", + "minimal": "minimal.html", + } + + dict_tmpl_size = { + "default": (150, 80), + "minimal": (50, 50) + } + def __init__(self, app_gui): super(Controller, self).__init__() self.i = 0 self.app_gui = app_gui self.last_state = None - # Initialize the class here, if required. + + self.tmpl_name_full = self.dict_tmpl.get(self.app_gui.tmpl_name) + if self.tmpl_name_full is None: + raise TypeError("template name must be valid, one of these: {allowed_tmpl_names}".format( + allowed_tmpl_names=(", ".join(self.dict_tmpl.keys())))) + + # set correct width, height + # self.app_gui.window.minimumWidth, self.app_gui.window.minimumHeight = (0, 0) + self.app_gui.width, self.app_gui.height = self.dict_tmpl_size.get(self.app_gui.tmpl_name) @htmlPy.Slot() def redraw(self): @@ -78,6 +97,8 @@ class Controller(htmlPy.Object): dict_state["skip"] = s(redis_db.lrange("{hash_a}_skip".format(hash_a=hash_dir_name), 0, -1)) if (not self.last_state) or (self.last_state != dict_state): - self.app_gui.html = render_template(self.app_gui, "index.html", dict_state) + self.app_gui.title = u"{dir_name_topfolder} - Test Status".format( + dir_name_topfolder=dict_state["dir_name_topfolder"]) + self.app_gui.html = render_template(self.app_gui, self.tmpl_name_full, dict_state) self.last_state = dict_state diff --git a/pytest_gui_status/status_gui/gui_frontend.py b/pytest_gui_status/status_gui/gui_frontend.py index add12fa..ed3f189 100644 --- a/pytest_gui_status/status_gui/gui_frontend.py +++ b/pytest_gui_status/status_gui/gui_frontend.py @@ -1,24 +1,38 @@ import htmlPy import os -import sys -from PyQt4.QtGui import QApplication + import PyQt4.QtCore as QtCore +from PyQt4.QtGui import QApplication +import argparse # Import back-end functionalities from gui_backend import Controller def main(): - if len(sys.argv) > 1: - dir_name_raw = sys.argv[1] - else: + arg_parser = argparse.ArgumentParser() + arg_parser.add_argument("--dir_name", help="root directory where py.test was executed") + arg_parser.add_argument("--minimal", help="use minimal template", action="store_true") + parsed_args = arg_parser.parse_args() + + dir_name_raw = parsed_args.dir_name + if dir_name_raw is None: dir_name_raw = "." dir_name = os.path.abspath(dir_name_raw) + if parsed_args.minimal: + app_tmpl = "minimal" + else: + app_tmpl = "default" + # GUI initializations - app = htmlPy.AppGUI(title=u"{dir_name} - Test Status".format(dir_name=dir_name), - developer_mode=True, width=150, height=80) - app.window.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) + app = htmlPy.AppGUI(title=u"to_be_set_later", + developer_mode=True, width=1, height=1) + + app.window.setWindowFlags(QtCore.Qt.WindowTitleHint) + # app.window.setWindowFlags(app.window.windowFlags() & ~QtCore.Qt.WindowMaximizeButtonHint) + app.window.setWindowFlags(app.window.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) + screen_geo = QApplication.desktop().availableGeometry() screen_topright = screen_geo.topRight() app.x_pos = (screen_topright.x() - 20) - app.width @@ -29,8 +43,10 @@ def main(): app.static_path = os.path.join(BASE_DIR, "static/") app.template_path = os.path.join(BASE_DIR, "tmpl/") app.dir_name = dir_name + app.tmpl_name = app_tmpl # Register back-end functionalities + # allow minimal tmpl with sys.arg app_backend = Controller(app) app.bind(app_backend) diff --git a/readme.md b/readme.md index 6d731bd..b34f39e 100644 --- a/readme.md +++ b/readme.md @@ -71,7 +71,7 @@ Set ENV variable `PYTEST_STATUS_PORT` ### Contribution 1. Todo are currently tracked in todo.txt - I will probably move over some of it to gh issues, but it is invaluable for offline usage for me. I couldn't find a good service out there that allows file-based issue tracking with gh issue sync, but I certainly hope there is one. -2. Python 3.x tests seem to have an odd problem with Appveyor - py.test exits, but the tests machine doesn't shutdown as it apparently doesn't get the exit code, so it times out and fails. Whats interesting is that I thought after moving over to Tox this problem would be gone for good, but it didnt. Because it happens only in 3.x versions of python, it is probably because of something I have written and not their own bug. Maybe the db service is still running? But in my local windows machine, it doesn't + why only in 3.x versions of python? Can you help me with it? +2. Python 2.x tests seem to have an odd problem with Appveyor - py.test exits, but the tests machine doesn't shutdown as it apparently doesn't get the exit code, so it times out and fails. Whats interesting is that I thought after moving over to Tox this problem would be gone for good, but it didnt. Because it happens only in 2.x versions of python, it is probably because of something I have written and not their own bug. Maybe the db service is still running? But in my local windows machine, it doesn't + why only in 2.x versions of python? Can you help me with it? 3. Publishing to pypi is still a local and manual process - I would like to move that over to one of the CI servers with build and push triggered by a git tag. Also, it should build to as many pip formats as possible including zip, egg, (exe for win32 and win64). Duggan/pontoon has this mechanism, can you do the same for this? diff --git a/tests/test_gui/test_gui.py b/tests/test_gui/test_gui.py index f8d1967..e1a519b 100644 --- a/tests/test_gui/test_gui.py +++ b/tests/test_gui/test_gui.py @@ -73,6 +73,7 @@ class TestRedisFail(object): # mock Controller requirements and app_gui.stop fake_app_gui = MagicMock() + fake_app_gui.tmpl_name = "default" with pytest.raises(redis.exceptions.ConnectionError) as error_info: gui_backend.Controller(fake_app_gui).redraw() @@ -97,6 +98,7 @@ class TestRedisFail(object): # mock Controller requirements and app_gui.stop fake_app_gui = MagicMock() + fake_app_gui.tmpl_name = "default" with pytest.raises(redis.exceptions.ConnectionError) as error_info: gui_backend.Controller(fake_app_gui).redraw() @@ -123,6 +125,7 @@ class TestRedisFail(object): # mock Controller requirements and app_gui.stop fake_app_gui = MagicMock() + fake_app_gui.tmpl_name = "default" with pytest.raises(redis.exceptions.ConnectionError) as error_info: gui_backend.Controller(fake_app_gui).redraw() @@ -149,6 +152,7 @@ class TestRedisFail(object): # mock Controller requirements and app_gui.stop # provide invalid path fake_app_gui = MagicMock() + fake_app_gui.tmpl_name = "default" fake_app_gui.dir_name = r"Invalid/Path" with pytest.raises(redis.exceptions.ConnectionError) as error_info: @@ -185,6 +189,7 @@ class TestBackendState(object): # mock app_gui with path fake_app_gui = MagicMock() + fake_app_gui.tmpl_name = "default" fake_app_gui.dir_name = tmpdir.strpath tmp_controller = gui_backend.Controller(fake_app_gui) @@ -224,6 +229,7 @@ class TestBackendState(object): # mock app_gui with path fake_app_gui = MagicMock() + fake_app_gui.tmpl_name = "default" fake_app_gui.dir_name = tmpdir.strpath tmp_controller = gui_backend.Controller(fake_app_gui)