Use s in test_gui + put it in utils + rename utils in gui

This commit is contained in:
2016-01-07 22:31:33 +05:30
parent 6ec3713a0d
commit 14fffc1b49
5 changed files with 32 additions and 31 deletions
+3 -2
View File
@@ -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"
+1 -28
View File
@@ -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):
+27
View File
@@ -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_
+1 -1
View File
@@ -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