From 14fffc1b49b0ff00042850e79e68222536cf933d Mon Sep 17 00:00:00 2001 From: Abhas Bhattacharya Date: Thu, 7 Jan 2016 22:31:33 +0530 Subject: [PATCH] Use s in test_gui + put it in utils + rename utils in gui --- pytest_gui_status/status_gui/gui_backend.py | 5 ++-- .../status_gui/{utils.py => utils_gui.py} | 0 pytest_gui_status/status_plugin/plugin.py | 29 +------------------ pytest_gui_status/utils.py | 27 +++++++++++++++++ tests/test_plugin/test_gui.py | 2 +- 5 files changed, 32 insertions(+), 31 deletions(-) rename pytest_gui_status/status_gui/{utils.py => utils_gui.py} (100%) create mode 100644 pytest_gui_status/utils.py diff --git a/pytest_gui_status/status_gui/gui_backend.py b/pytest_gui_status/status_gui/gui_backend.py index d8c11b3..85cf90a 100644 --- a/pytest_gui_status/status_gui/gui_backend.py +++ b/pytest_gui_status/status_gui/gui_backend.py @@ -1,11 +1,12 @@ import htmlPy -from .utils import render_template +from .utils_gui import render_template import os import redis import dateutil.parser from datetime import datetime import humanfriendly import os.path +from ..utils import s env_redis_port = os.environ.get("PYTEST_STATUS_PORT") @@ -49,7 +50,7 @@ class Controller(htmlPy.Object): try: # make sure that this is correct redis db - assert redis_db.get("PYTEST_STATUS_DB") == "1" + assert s(redis_db.get("PYTEST_STATUS_DB")) == "1" except AssertionError: self.app_gui.stop() raise redis.exceptions.ConnectionError("Redis is running on this port, but it is not related to pytest status\n" diff --git a/pytest_gui_status/status_gui/utils.py b/pytest_gui_status/status_gui/utils_gui.py similarity index 100% rename from pytest_gui_status/status_gui/utils.py rename to pytest_gui_status/status_gui/utils_gui.py diff --git a/pytest_gui_status/status_plugin/plugin.py b/pytest_gui_status/status_plugin/plugin.py index 285888e..5483d02 100644 --- a/pytest_gui_status/status_plugin/plugin.py +++ b/pytest_gui_status/status_plugin/plugin.py @@ -6,6 +6,7 @@ import redis import os import psutil import datetime +from ..utils import s env_redis_port = os.environ.get("PYTEST_STATUS_PORT") @@ -39,34 +40,6 @@ command_status_gui_gen = "pytest_gui_status \"{norm_dir_name}\"" # make bulk changes with pipeline -def s(input_): - ''' Convert str or uncode or bytes to str. - If list, do it for all of them. - If others, return as is. ''' - - import sys - PY3 = sys.version_info > (3,) - - if isinstance(input_, list): - return [s(ele) for ele in input_] - - try: - if PY3: - assert(type(input_) in [str, bytes]) - else: - assert(type(input_) in [str, unicode, bytes]) - except AssertionError: - return input_ - - if PY3: - if type(input_) == bytes: - str_ = bytes.decode(input_) - return str_ - - # either str or unicode - str_ = str(input_) - return str_ - class Helpers(object): diff --git a/pytest_gui_status/utils.py b/pytest_gui_status/utils.py new file mode 100644 index 0000000..e5cfefb --- /dev/null +++ b/pytest_gui_status/utils.py @@ -0,0 +1,27 @@ +def s(input_): + ''' Convert str or uncode or bytes to str. + If list, do it for all of them. + If others, return as is. ''' + + import sys + PY3 = sys.version_info > (3,) + + if isinstance(input_, list): + return [s(ele) for ele in input_] + + try: + if PY3: + assert(type(input_) in [str, bytes]) + else: + assert(type(input_) in [str, unicode, bytes]) + except AssertionError: + return input_ + + if PY3: + if type(input_) == bytes: + str_ = bytes.decode(input_) + return str_ + + # either str or unicode + str_ = str(input_) + return str_ diff --git a/tests/test_plugin/test_gui.py b/tests/test_plugin/test_gui.py index c54c792..9d9ca22 100644 --- a/tests/test_plugin/test_gui.py +++ b/tests/test_plugin/test_gui.py @@ -4,7 +4,7 @@ from mock import patch, MagicMock import redis import pytest -from ..utils_test import create_temp_case, reload_2_3 +from ..utils_test import reload_2_3 REDIS_TEST_PORT = status_plugin.REDIS_PORT + 1