From a56600ee4555f7a5603773eb7e78d6f4ed71e450 Mon Sep 17 00:00:00 2001 From: Abhas Bhattacharya Date: Mon, 11 Jan 2016 02:54:27 +0530 Subject: [PATCH] @nd redis_state test with pass/fail + empty collect fix in plugin --- pytest_gui_status/status_plugin/plugin.py | 3 +- tests/test_gui/test_gui.py | 46 +++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/pytest_gui_status/status_plugin/plugin.py b/pytest_gui_status/status_plugin/plugin.py index f9e01bf..193de1c 100644 --- a/pytest_gui_status/status_plugin/plugin.py +++ b/pytest_gui_status/status_plugin/plugin.py @@ -111,7 +111,8 @@ class Helpers(object): hash_dir_name = s(redis_db.hget("directories_to_hash", dir_name)) assert hash_dir_name is not None - redis_db.rpush("{hash_a}_collect".format(hash_a=hash_dir_name), *list_test_name) + if list_test_name: + redis_db.rpush("{hash_a}_collect".format(hash_a=hash_dir_name), *list_test_name) # set last updated Helpers.modify_last_updated(dir_name) diff --git a/tests/test_gui/test_gui.py b/tests/test_gui/test_gui.py index 7d71829..f8d1967 100644 --- a/tests/test_gui/test_gui.py +++ b/tests/test_gui/test_gui.py @@ -17,6 +17,13 @@ mock_htmlPy_module.Object = object mock_htmlPy_module.Slot.return_value = (lambda func: func) +class MockTestResult(object): + def __init__(self, nodeid, outcome): + assert outcome in ["passed", "failed", "skipped"] + self.nodeid = nodeid + self.outcome = outcome + + @pytest.fixture() def redis_master(request, auto_shutdown=True): import pytest_gui_status.status_plugin.plugin as status_plugin @@ -192,3 +199,42 @@ class TestBackendState(object): assert tmp_controller.last_state["pass"] == [] assert tmp_controller.last_state["fail"] == [] assert tmp_controller.last_state["skip"] == [] + + @patch("pytest_gui_status.status_gui.utils_gui.render_template", MagicMock()) + def test_backend_state_2(self, tmpdir, redis_master): + # load new redis port + import pytest_gui_status.status_gui.gui_backend as gui_backend + reload_2_3(pytest_gui_status.utils) + reload_2_3(gui_backend) + reload_2_3(status_plugin) + + # start Redis + redis_master.init(tmpdir.strpath) + + # setup state + status_plugin.Helpers.on_collectstart(tmpdir.strpath) + status_plugin.Helpers.on_collectend(tmpdir.strpath, []) + status_plugin.Helpers.on_test_eachstart(tmpdir.strpath) + status_plugin.Helpers.on_test_eachend(tmpdir.strpath, [ + MockTestResult("pass_1", "passed"), + MockTestResult("fail_1", "failed"), + MockTestResult("pass_2", "passed"), + MockTestResult("skip_1", "skipped"), + ]) + + # mock app_gui with path + fake_app_gui = MagicMock() + fake_app_gui.dir_name = tmpdir.strpath + + tmp_controller = gui_backend.Controller(fake_app_gui) + tmp_controller.redraw() + + assert tmp_controller.last_state["dir_name"] == tmpdir.strpath + assert tmp_controller.last_state["dir_name_topfolder"] ==\ + os.path.basename(tmpdir.strpath) + assert tmp_controller.last_state["state"] == "runtest" + assert tmp_controller.last_state["last_updated_obj"] <= datetime.datetime.now() + assert tmp_controller.last_state["collect"] == [] + assert sorted(tmp_controller.last_state["pass"]) == sorted(["pass_1", "pass_2"]) + assert tmp_controller.last_state["fail"] == ["fail_1"] + assert tmp_controller.last_state["skip"] == ["skip_1"]