From 6ecf3e41b6924a68ff2ab77f0679f215e26e6435 Mon Sep 17 00:00:00 2001 From: edisonyan Date: Thu, 12 Apr 2018 16:49:13 +0800 Subject: [PATCH] compatible with python 3.6 --- Tests/locustfile.py | 9 ++-- Tests/run_locust.py | 11 +++-- Tests/test_Selenium.py | 17 +++---- Tests/test_baiduSearch.py | 32 +++++++++---- Tests/test_demo.py | 68 ++++++++++++++++----------- Tests/test_doubanSearch.py | 40 ++++++++-------- Util/DBTool/__init__.py | 2 +- Util/DBTool/dbUtil.py | 12 +++-- Util/DBTool/mysqlUtil.py | 8 ++-- Util/DBTool/sqlserverUtil.py | 10 ++-- Util/OATool/__init__.py | 1 - Util/__init__.py | 11 ----- Util/checkTool/__init__.py | 2 - Util/checkTool/checkUtil.py | 8 ++-- Util/checkTool/resultCheck.py | 6 +-- Util/commonTool/__init__.py | 1 - Util/commonTool/configUtil.py | 8 ++-- Util/hessianTool/__init__.py | 1 - Util/hessianTool/hessianUtil.py | 30 ++++++++---- Util/httpTool/__init__.py | 3 +- Util/httpTool/httpUtil.py | 24 +++++----- Util/redisTool/__init__.py | 1 - Util/redisTool/redisUtil.py | 6 +-- Util/securityTool/__init__.py | 3 +- Util/seleniumTool/__init__.py | 4 +- Util/seleniumTool/basePageUtil.py | 6 +-- Util/seleniumTool/loginPageUtil.py | 6 +-- Util/webserviceTool/__init__.py | 1 - Util/webserviceTool/webServiceUtil.py | 6 +-- requirements.txt | 6 +-- 30 files changed, 186 insertions(+), 157 deletions(-) diff --git a/Tests/locustfile.py b/Tests/locustfile.py index 33e562b..0a5174b 100644 --- a/Tests/locustfile.py +++ b/Tests/locustfile.py @@ -2,9 +2,12 @@ from locust import Locust, TaskSet, events, task import sys import os -sys.path.append(os.path.abspath(os.path.dirname(__file__))) -sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) -from test_demo import test_demo + +from Tests.test_demo import test_demo + +#sys.path.append(os.path.abspath(os.path.dirname(__file__))) +#sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) + class HttpClient(object): diff --git a/Tests/run_locust.py b/Tests/run_locust.py index 6bb2c95..090eec3 100644 --- a/Tests/run_locust.py +++ b/Tests/run_locust.py @@ -1,13 +1,16 @@ # coding:utf-8 import sys import os + +from Util.locustTool.locustUtil import locustUtil + sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) from Util import * import multiprocessing def start_slave(locust_file, master_port): - print 'start slave pid:\t{0}'.format(os.getpid()) + print ('start slave pid:\t{0}'.format(os.getpid())) os.system('locust -f {0} --slave --master-port {1}'.format(locust_file, master_port)) @@ -30,12 +33,12 @@ def start_slave(locust_file, master_port): process.start() record.append(process) - print 'start master pid:\t{0}'.format(os.getpid()) + print ('start master pid:\t{0}'.format(os.getpid())) cmd = 'locust -f {0} {1}'.format(locust_file, locust_command) - print 'cmd:\t{0}'.format(cmd) + print ('cmd:\t{0}'.format(cmd)) os.system(cmd) else: # 单例模式 cmd = 'locust -f {0} {1}'.format(locust_file, locust_command) - print 'cmd:\t{0}'.format(cmd) + print ('cmd:\t{0}'.format(cmd)) os.system(cmd) diff --git a/Tests/test_Selenium.py b/Tests/test_Selenium.py index d433bf9..8a9509b 100644 --- a/Tests/test_Selenium.py +++ b/Tests/test_Selenium.py @@ -2,14 +2,15 @@ import sys import os -reload(sys) -sys.setdefaultencoding("utf-8") -sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) - -from Util import * +#reload(sys) +#sys.setdefaultencoding("utf-8") +#sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) +from Util.commonTool.configUtil import ConfigUtil from selenium import webdriver import time +from Util.seleniumTool.loginPageUtil import loginPage + selenium_yml = '/config/selenium.yml' @@ -36,7 +37,7 @@ def tearDownClass(cls): @staticmethod def login(self, user, passwd, tips=''): # 定义通用login方法 - print 'Login user: %s ,passwd: %s' % (user, passwd) + print ('Login user: %s ,passwd: %s' % (user, passwd)) # 声明loginPage对象 login_page = loginPage(self.driver, self.url, self.title) # 打开页面 @@ -56,7 +57,7 @@ def login(self, user, passwd, tips=''): if tips: # 登陆失败校验提示信息 fail_tips = login_page.show_span() - print 'Login Failed: %s' % fail_tips + print ('Login Failed: %s' % fail_tips) assert tips == fail_tips, 'Check Login Error Tips Failed!' else: # 登陆成功校验UserID @@ -65,7 +66,7 @@ def login(self, user, passwd, tips=''): login_page.click_logout() time.sleep(1) - print 'Login UserID: %s' % login_userID + print ('Login UserID: %s' % login_userID) assert user + self.suffix == login_userID, 'Check UserID Failed!' def test_BVT(self): diff --git a/Tests/test_baiduSearch.py b/Tests/test_baiduSearch.py index aa72480..ec28117 100644 --- a/Tests/test_baiduSearch.py +++ b/Tests/test_baiduSearch.py @@ -1,9 +1,11 @@ # encoding: utf-8 +import nose import requests import re from nose.tools import * from functools import partial + class check_response(): @staticmethod def check_title(response, key): @@ -11,24 +13,35 @@ def check_title(response, key): expect_title = key + u'_百度搜索' re_title = re.compile('(.*)') # 搜索页面title正则表达式 title = re.search(re_title, response).groups()[0] - print 'Search Result Title:%s' % title - eq_(title, expect_title, 'Title Check Error!%s != %s' % (title, expect_title)) + print('Search Result Title:%s' % title) + eq_(title, expect_title, 'Title Check Error!%s != %s' % + (title, expect_title)) @staticmethod def check_results(response, key): # 校验key是否匹配搜索结果的名称或者URL re_name = re.compile('>(.*)') # 搜索结果name正则表达式 - re_url = re.compile('style="text-decoration:none;">(.*)(.*)', '').replace('', '') - url = url.replace('', '').replace('', '').replace(' ', '').replace('...', '') - print 'Search Results Name:%s\tURL:%s' % (name, url) + url = url.replace( + '', + '').replace( + '', + '').replace( + ' ', + '').replace( + '...', + '') + print('Search Results Name:%s\tURL:%s' % (name, url)) if key.lower() not in (name + url).lower(): - assert False, 'Search Results Check Error!%s not in %s' % (key, name + url) + assert False, 'Search Results Check Error!%s not in %s' % ( + key, name + url) return True @@ -52,8 +65,9 @@ def search(wd): def test_BVT(self): # 校验输入不同类型的wd时,百度是否均可正常搜索返回结果 # wd分类:中文,英文,数字 - wd_list = [u'lovesoo', u'自动化测试', u'12345'] + wd_list = ['lovesoo', '自动化测试','12345'] for wd in wd_list: f = partial(test_baiduSearch.search, wd) - f.description = wd.encode('utf-8') - yield (f,) \ No newline at end of file + f.description = wd +# f.description = wd.encode('utf-8') + yield (f,) diff --git a/Tests/test_demo.py b/Tests/test_demo.py index 86d856b..a746fc7 100644 --- a/Tests/test_demo.py +++ b/Tests/test_demo.py @@ -2,12 +2,24 @@ import sys import os -reload(sys) -sys.setdefaultencoding("utf-8") -sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) +#reload(sys) +#sys.setdefaultencoding("utf-8") +#sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) +from nose.tools import nottest +from collections import OrderedDict from Util import * from functools import partial - +from pyhessian import protocol + +from Util.DBTool.dbUtil import DBUtil +from Util.OATool.OAT import OAT +from Util.checkTool.resultCheck import * +from Util.hessianTool.hessianUtil import HessianUtil +from Util.httpTool.httpParam import * +from Util.httpTool.httpUtil import * +from Util.redisTool.redisUtil import RedisUtil +from Util.webserviceTool.webServiceUtil import WebServiceUtil +from Util.securityTool.securityUtil import Security class test_demo(object): """接口测试demo""" @@ -69,8 +81,8 @@ def test_webservice(self): @nottest def test_db(self): # 数据库操作demo - print DBUtil.execute('select * from user_info;') - print DBUtil.execute('select * from user_info;', confSection='Sqlserver') + print (DBUtil.execute('select * from user_info;')) + print (DBUtil.execute('select * from user_info;', confSection='Sqlserver')) @nottest def test_OA(self): @@ -96,37 +108,37 @@ def test_OA(self): ('B', ['B1']), ('C', ['C1'])]) - print json.dumps(oat.genSets(case1)) - print json.dumps(oat.genSets(case2)) - print json.dumps(oat.genSets(case3)) - print json.dumps(oat.genSets(case4)) - print json.dumps(oat.genSets(case4, 1, 0)) - print json.dumps(oat.genSets(case4, 1, 1)) - print json.dumps(oat.genSets(case4, 1, 2)) - print json.dumps(oat.genSets(case4, 1, 3)) + print (json.dumps(oat.genSets(case1))) + print (json.dumps(oat.genSets(case2))) + print (json.dumps(oat.genSets(case3))) + print (json.dumps(oat.genSets(case4))) + print (json.dumps(oat.genSets(case4, 1, 0))) + print (json.dumps(oat.genSets(case4, 1, 1))) + print (json.dumps(oat.genSets(case4, 1, 2))) + print (json.dumps(oat.genSets(case4, 1, 3))) @nottest def test_redis(self): # redis/redis cluster操作 demo - print RedisUtil.execute('hexists', 'Search:HotWord', u'刘德华') - print RedisUtil.execute("get", "userSession:%s", "12345", confSection='Redis_Cluster') + print (RedisUtil.execute('hexists', 'Search:HotWord', u'刘德华')) + print (RedisUtil.execute("get", "userSession:%s", "12345", confSection='Redis_Cluster')) @nottest def test_security(self): # 加密方法使用demo import string sec = Security() - key_8 = string.lowercase[:8] - key_16 = string.lowercase[:16] + key_8 = str.lower() + key_16 = str.lower() data = 'Taffy is a Test Automation Framework based on nosetests.' - print 'DES:', sec.getDES(key_8, data).encode('hex') # des - print 'Decode DES:', sec.decodeDES(key_8, sec.getDES(key_8, data)) # decode des - print 'DES3:', sec.getDES3(key_16, data).encode('hex') # desc3 - print 'Decode DES3:', sec.decodeDES3(key_16, sec.getDES3(key_16, data)) # decode desc3 - print 'HMAC_SHA1:', sec.getHMAC_SHA1(key_8, data) # sha1 - print 'SHA:', sec.getSHA(data) # sha - print 'MD5:', sec.getMD5(data) # md5 - print 'AES:', sec.getAES(key_16, data).encode('hex') # aes - print'Base64:', sec.getBase64(data) # base64 - print'Decode Base64:', sec.decodeBase64(sec.getBase64(data)) # decode base64 + print ('DES:', sec.getDES(key_8, data).encode('hex') ) # des + print ('Decode DES:', sec.decodeDES(key_8, sec.getDES(key_8, data))) # decode des + print ('DES3:', sec.getDES3(key_16, data).encode('hex')) # desc3 + print ('Decode DES3:', sec.decodeDES3(key_16, sec.getDES3(key_16, data))) # decode desc3 + print ('HMAC_SHA1:', sec.getHMAC_SHA1(key_8, data)) # sha1 + print ('SHA:', sec.getSHA(data)) # sha + print ('MD5:', sec.getMD5(data)) # md5 + print ('AES:', sec.getAES(key_16, data).encode('hex')) # aes + print('Base64:', sec.getBase64(data)) # base64 + print('Decode Base64:', sec.decodeBase64(sec.getBase64(data))) # decode base64 diff --git a/Tests/test_doubanSearch.py b/Tests/test_doubanSearch.py index a26c08c..34782fa 100644 --- a/Tests/test_doubanSearch.py +++ b/Tests/test_doubanSearch.py @@ -2,8 +2,8 @@ import sys import os -reload(sys) -sys.setdefaultencoding("utf-8") +#reload(sys) +#sys.setdefaultencoding("utf-8") import requests import json from datetime import datetime as dt @@ -42,7 +42,7 @@ def send_mail(): # 退出 s.quit() except Exception as e: - print "Exceptioin ", e + print ("Exceptioin ", e) class check_response(): @@ -101,10 +101,10 @@ class test_doubanSearch(object): def search(params, expectNum=None): url = 'https://api.douban.com/v2/movie/search' r = requests.get(url, params=params) - print 'Search Params:\n', json.dumps(params, ensure_ascii=False) - print 'Search Response:\n', json.dumps(r.json(), ensure_ascii=False, indent=4) - code = r.json().get('code') - if code > 0: + print ('Search Params:\n', json.dumps(params, ensure_ascii=False)) + print ('Search Response:\n', json.dumps(r.json(), ensure_ascii=False, indent=4)) + code = r.status_code + if code != 200: assert False, 'Invoke Error.Code:\t{0}'.format(code) else: if params.get('start') is not None or params.get('count') is not None: @@ -120,7 +120,7 @@ def test_q(self): for q in qs: params = dict(q=q) f = partial(test_doubanSearch.search, params) - f.description = json.dumps(params, ensure_ascii=False).encode('utf-8') + f.description = json.dumps(params, ensure_ascii=False) yield (f,) def test_tag(self): @@ -129,7 +129,7 @@ def test_tag(self): for tag in tags: params = dict(tag=tag) f = partial(test_doubanSearch.search, params) - f.description = json.dumps(params, ensure_ascii=False).encode('utf-8') + f.description = json.dumps(params, ensure_ascii=False) yield (f,) def test_param_combination(self): @@ -141,10 +141,10 @@ def test_param_combination(self): for params in params_list: if isinstance(params, tuple): f = partial(test_doubanSearch.search, params[0], params[1]) - f.description = json.dumps(params[0], ensure_ascii=False).encode('utf-8') + f.description = json.dumps(params[0], ensure_ascii=False) else: f = partial(test_doubanSearch.search, params) - f.description = json.dumps(params, ensure_ascii=False).encode('utf-8') + f.description = json.dumps(params, ensure_ascii=False) yield (f,) def test_page(self): @@ -155,7 +155,7 @@ def test_page(self): start = page * count params = dict(q=q, start=start, count=count) f = partial(test_doubanSearch.search, params) - f.description = json.dumps(params, ensure_ascii=False).encode('utf-8') + f.description = json.dumps(params, ensure_ascii=False) yield (f,) def test_param_q(self): @@ -165,11 +165,11 @@ def test_param_q(self): if isinstance(q, tuple): params = dict(q=q[0]) f = partial(test_doubanSearch.search, params, q[1]) - f.description = json.dumps(params, ensure_ascii=False).encode('utf-8') + f.description = json.dumps(params, ensure_ascii=False) else: params = dict(q=q) f = partial(test_doubanSearch.search, params) - f.description = json.dumps(params, ensure_ascii=False).encode('utf-8') + f.description = json.dumps(params, ensure_ascii=False) yield (f,) def test_param_tag(self): @@ -179,11 +179,11 @@ def test_param_tag(self): if isinstance(tag, tuple): params = dict(tag=tag[0]) f = partial(test_doubanSearch.search, params, tag[1]) - f.description = json.dumps(params, ensure_ascii=False).encode('utf-8') + f.description = json.dumps(params, ensure_ascii=False) else: params = dict(tag=tag) f = partial(test_doubanSearch.search, params) - f.description = json.dumps(params, ensure_ascii=False).encode('utf-8') + f.description = json.dumps(params, ensure_ascii=False) yield (f,) def test_param_start(self): @@ -192,7 +192,7 @@ def test_param_start(self): for start in start_list: params = dict(q=q, start=start) f = partial(test_doubanSearch.search, params) - f.description = json.dumps(params, ensure_ascii=False).encode('utf-8') + f.description = json.dumps(params, ensure_ascii=False) yield (f,) def test_param_count(self): @@ -201,7 +201,7 @@ def test_param_count(self): for count in count_list: params = dict(tag=tag, count=count) f = partial(test_doubanSearch.search, params) - f.description = json.dumps(params, ensure_ascii=False).encode('utf-8') + f.description = json.dumps(params, ensure_ascii=False) yield (f,) @@ -220,9 +220,9 @@ def test_param_count(self): report_file = 'TestReport.html' # 运行nosetests进行自动化测试并生成测试报告 - print 'Run Nosetests Now...' + print ('Run Nosetests Now...') os.system('nosetests -v test_doubanSearch.py:test_doubanSearch --with-html --html-file={0}'.format(report_file)) # 发送测试报告邮件 - print 'Send Test Report Mail Now...' + print ('Send Test Report Mail Now...') send_mail() diff --git a/Util/DBTool/__init__.py b/Util/DBTool/__init__.py index 57c4c57..87062c3 100644 --- a/Util/DBTool/__init__.py +++ b/Util/DBTool/__init__.py @@ -1,3 +1,3 @@ # coding=utf-8 -from dbUtil import * + diff --git a/Util/DBTool/dbUtil.py b/Util/DBTool/dbUtil.py index b7cb7a6..e763a69 100644 --- a/Util/DBTool/dbUtil.py +++ b/Util/DBTool/dbUtil.py @@ -1,12 +1,14 @@ # coding=utf-8 import sys import os -import MySQLdb -import pymssql +#import pymssql +import pymysql from DBUtils import PooledDB -from mysqlUtil import * -from sqlserverUtil import * +from .mysqlUtil import * +from .sqlserverUtil import * + +from Util.commonTool.configUtil import ConfigUtil from ..commonTool import * @@ -90,7 +92,7 @@ def execute(cls, sql, params=(),confSection='Mysql', confFile='/config/test.yml' data = instance.execute(sql, params) except Exception as e: - print e + print(e) finally: instance.close() diff --git a/Util/DBTool/mysqlUtil.py b/Util/DBTool/mysqlUtil.py index 7f7a5b8..3253c72 100644 --- a/Util/DBTool/mysqlUtil.py +++ b/Util/DBTool/mysqlUtil.py @@ -1,9 +1,9 @@ # coding=utf-8 import sys import os -import MySQLdb +import pymysql -from baseUtil import * +from .baseUtil import * class MysqlUtil(BaseUtil): @@ -12,7 +12,7 @@ class MysqlUtil(BaseUtil): def __init__(self, connection): """Constructor""" super(MysqlUtil, self).__init__(connection) - self.cursor = self.connection.cursor(cursorclass=MySQLdb.cursors.DictCursor) + self.cursor = self.connection.cursor(cursorclass=pymysql.cursors.DictCursor) def executeQuery(self, sql, params=()): @@ -30,7 +30,7 @@ def executeNonQuery(self, sql, params=()): except Exception as e: if self.connection: self.connection.rollback() - print e + print (e) finally: if result: lastid = self.cursor.lastrowid diff --git a/Util/DBTool/sqlserverUtil.py b/Util/DBTool/sqlserverUtil.py index ac5659d..ecc9c9c 100644 --- a/Util/DBTool/sqlserverUtil.py +++ b/Util/DBTool/sqlserverUtil.py @@ -1,9 +1,9 @@ # coding=utf-8 import sys import os -import pymssql +#import pymssql -from baseUtil import * +from Util.DBTool.baseUtil import * class SqlserverUtil(BaseUtil): @@ -22,9 +22,9 @@ def executeQuery(self, sql, params=()): for row in data: if isinstance(row, dict): for key in row: - if isinstance(row[key], unicode): + if isinstance(row[key], bytes): try: - row[key] = row[key].encode('iso8859-1').decode('gbk') + row[key] = row[key].decode('iso8859-1').encode('gbk') except UnicodeError: pass return data @@ -38,6 +38,6 @@ def executeNonQuery(self, sql, params=()): except Exception as e: if self.connection: self.connection.rollback() - print e + print (e) finally: return result diff --git a/Util/OATool/__init__.py b/Util/OATool/__init__.py index fbe0692..d21438c 100644 --- a/Util/OATool/__init__.py +++ b/Util/OATool/__init__.py @@ -1,3 +1,2 @@ # coding=utf-8 -from OAT import * \ No newline at end of file diff --git a/Util/__init__.py b/Util/__init__.py index 8992601..e69de29 100644 --- a/Util/__init__.py +++ b/Util/__init__.py @@ -1,11 +0,0 @@ -from checkTool import * -from commonTool import * -from DBTool import * -from hessianTool import * -from httpTool import * -from OATool import * -from redisTool import * -from securityTool import * -from seleniumTool import * -from webserviceTool import * -from locustTool import * \ No newline at end of file diff --git a/Util/checkTool/__init__.py b/Util/checkTool/__init__.py index a0b0465..d21438c 100644 --- a/Util/checkTool/__init__.py +++ b/Util/checkTool/__init__.py @@ -1,4 +1,2 @@ # coding=utf-8 -from checkUtil import * -from resultCheck import * diff --git a/Util/checkTool/checkUtil.py b/Util/checkTool/checkUtil.py index 64d0f94..712fe42 100644 --- a/Util/checkTool/checkUtil.py +++ b/Util/checkTool/checkUtil.py @@ -93,10 +93,10 @@ def check_dict(data, jsondata, columns=None, keymaps=None): return True else: - if isinstance(jsondata, unicode): - jsondata = jsondata.encode('utf-8') - if isinstance(data, unicode): - data = data.encode('utf-8') + if isinstance(jsondata, bytes): + jsondata = jsondata.decode('utf-8') + if isinstance(data, bytes): + data = data.decode('utf-8') try: assert data == jsondata, '%s != %s' % (data, jsondata) return data == jsondata diff --git a/Util/checkTool/resultCheck.py b/Util/checkTool/resultCheck.py index 9092984..f01fc66 100644 --- a/Util/checkTool/resultCheck.py +++ b/Util/checkTool/resultCheck.py @@ -1,5 +1,5 @@ # coding=utf-8 -from checkUtil import * +from Util.checkTool.checkUtil import * import re @@ -10,7 +10,7 @@ def check_title(response, key): expect_title = key + u'_百度搜索' re_title = re.compile('(.*)') # 搜索页面title正则表达式 title = re.search(re_title, response).groups()[0] - print 'Search Result Title:%s' % title + print ('Search Result Title:%s' % title) eq_(title, expect_title, 'Title Check Error!%s != %s' % (title, expect_title)) @staticmethod @@ -25,7 +25,7 @@ def check_results(response, key): # name,url简单处理,去除特殊符号 name = name.replace('', '').replace('', '') url = url.replace('', '').replace('', '').replace(' ', '').replace('...', '') - print 'Search Results Name:%s\tURL:%s' % (name, url) + print ('Search Results Name:%s\tURL:%s' % (name, url)) if key.lower() not in (name + url).lower(): assert False, 'Search Results Check Error!%s not in %s' % (key, name + url) return True diff --git a/Util/commonTool/__init__.py b/Util/commonTool/__init__.py index 014c884..e69de29 100644 --- a/Util/commonTool/__init__.py +++ b/Util/commonTool/__init__.py @@ -1 +0,0 @@ -from configUtil import * \ No newline at end of file diff --git a/Util/commonTool/configUtil.py b/Util/commonTool/configUtil.py index 70ccfa1..195ce4d 100644 --- a/Util/commonTool/configUtil.py +++ b/Util/commonTool/configUtil.py @@ -22,25 +22,25 @@ class ConfigUtil(object): def getall(cls, path='/config/test.yml'): """获取配置文件中的配置,返回string""" filepath = ROOT + path - return yaml.load(file(filepath, 'r')) + return yaml.load(open(filepath, 'r')) @classmethod def get(cls, section, option='', path='/config/test.yml'): """获取配置文件中的配置,返回string""" filepath = ROOT + path - config = yaml.load(file(filepath, 'r')) + config = yaml.load(open(filepath, encoding='utf-8',mode='r')) if option: result = config[section][option] else: result = config[section] - return str(result) if isinstance(result, (str, unicode, int)) else result + return str(result) if isinstance(result, (str, int)) else result @classmethod def getint(cls, section, option='', path='/config/test.yml'): """获取配置文件中的配置,返回int""" filepath = ROOT + path - config = yaml.load(file(filepath, 'r')) + config = yaml.load(open(filepath, 'r')) if option: return int(config[section][option]) else: diff --git a/Util/hessianTool/__init__.py b/Util/hessianTool/__init__.py index ef593ed..17b3794 100644 --- a/Util/hessianTool/__init__.py +++ b/Util/hessianTool/__init__.py @@ -1,3 +1,2 @@ # -*- coding:utf-8 -*- -from hessianUtil import * \ No newline at end of file diff --git a/Util/hessianTool/hessianUtil.py b/Util/hessianTool/hessianUtil.py index ffe1dc1..394651d 100644 --- a/Util/hessianTool/hessianUtil.py +++ b/Util/hessianTool/hessianUtil.py @@ -5,6 +5,8 @@ import json import time import datetime + +from Util.commonTool.configUtil import ConfigUtil from ..commonTool import * @@ -35,7 +37,7 @@ def FormatObject(obj): return obj except Exception as e: - print e + print(e) def benchmark(func): @@ -44,7 +46,7 @@ def benchmark(func): def wrapper(*args, **kwargs): t = time.clock() res = func(*args, **kwargs) - print "Cost:\t%ss\r\n" % (time.clock() - t) + print("Cost:\t%ss\r\n" % (time.clock() - t)) return res return wrapper @@ -72,12 +74,24 @@ def date_handler(obj): return ( interface = ConfigUtil.get(confSection, 'Interface', confFile) url = host + ':' + port + '/' + service + '.' + interface - print '\r\nInvoke Hessian Interface:\r\nURL:\t', url - print 'Method:\t', method - res = FormatObject(getattr(HessianProxy(url, timeout=60), method)(*req)) - print 'Req:\t', [FormatObject(i) for i in req] - print 'Res:\t', json.dumps(res, default=date_handler, ensure_ascii=False) + print('\r\nInvoke Hessian Interface:\r\nURL:\t', url) + print('Method:\t', method) + res = FormatObject( + getattr( + HessianProxy( + url, + timeout=60), + method)( + * + req)) + print('Req:\t', [FormatObject(i) for i in req]) + print( + 'Res:\t', + json.dumps( + res, + default=date_handler, + ensure_ascii=False)) return res except Exception as e: - print e + print(e) diff --git a/Util/httpTool/__init__.py b/Util/httpTool/__init__.py index aad1135..87062c3 100644 --- a/Util/httpTool/__init__.py +++ b/Util/httpTool/__init__.py @@ -1,4 +1,3 @@ # coding=utf-8 -from httpParam import * -from httpUtil import * + diff --git a/Util/httpTool/httpUtil.py b/Util/httpTool/httpUtil.py index 5ab39c5..fcc0c05 100644 --- a/Util/httpTool/httpUtil.py +++ b/Util/httpTool/httpUtil.py @@ -2,14 +2,16 @@ import json import requests + +from Util.commonTool.configUtil import ConfigUtil from ..commonTool import * def _decode_list(data): rv = [] for item in data: - if isinstance(item, unicode): - item = item.encode('utf-8') + if isinstance(item, bytes): + item = item.decode('utf-8') elif isinstance(item, list): item = _decode_list(item) elif isinstance(item, dict): @@ -21,9 +23,9 @@ def _decode_list(data): def _decode_dict(data): rv = {} for key, value in data.iteritems(): - if isinstance(key, unicode): - key = key.encode('utf-8') - value = value.encode('utf-8') + if isinstance(key, bytes): + key = key.decode('utf-8') + value = value.decode('utf-8') elif isinstance(value, list): value = _decode_list(value) elif isinstance(value, dict): @@ -89,9 +91,9 @@ def __init__(self, ): @classmethod def get(cls, name, srequest): params = srequest.GetDict() - print 'Request:\t', json.dumps(params, ensure_ascii=False) + print ('Request:\t', json.dumps(params, ensure_ascii=False)) response = HttpUtil.get(name, params=params) - print 'Response:\t', response + print ('Response:\t', response) return response.text @@ -105,15 +107,15 @@ def __init__(self, ): @classmethod def get(cls, name, srequest): params = srequest.GetDict() - print 'Request:\t', json.dumps(params, ensure_ascii=False) + print ('Request:\t', json.dumps(params, ensure_ascii=False)) response = HttpUtil.get(name, cls.confSection, params=params) - print 'Response:\t', response.text + print ('Response:\t', response.text) return response.json() @classmethod def post(cls, name, srequest): params = srequest.GetDict() - print 'Request:\t', json.dumps(params, ensure_ascii=False) + print ('Request:\t', json.dumps(params, ensure_ascii=False)) response = HttpUtil.post(name, cls.confSection, data=params) - print 'Response:\t', response.text + print ('Response:\t', response.text) return response.json() diff --git a/Util/redisTool/__init__.py b/Util/redisTool/__init__.py index 68de054..d21438c 100644 --- a/Util/redisTool/__init__.py +++ b/Util/redisTool/__init__.py @@ -1,3 +1,2 @@ # coding=utf-8 -from redisUtil import * \ No newline at end of file diff --git a/Util/redisTool/redisUtil.py b/Util/redisTool/redisUtil.py index 1a0f15b..782be52 100644 --- a/Util/redisTool/redisUtil.py +++ b/Util/redisTool/redisUtil.py @@ -1,5 +1,5 @@ # coding=utf-8 - +from Util.commonTool.configUtil import ConfigUtil from ..commonTool import * import redis from rediscluster import StrictRedisCluster @@ -41,7 +41,7 @@ def getCon(cls, confSection, confFile='/config/test.yml'): r = StrictRedisCluster(connection_pool=pool, decode_responses=True) return r except Exception as e: - print e + print(e) @classmethod def execute(cls, command, key, *args, **kwargs): @@ -79,4 +79,4 @@ def execute(cls, command, key, *args, **kwargs): return getattr(r, command)(key, *args, **kwargs) except Exception as e: - print e + print(e) diff --git a/Util/securityTool/__init__.py b/Util/securityTool/__init__.py index 9053a45..3ed6590 100644 --- a/Util/securityTool/__init__.py +++ b/Util/securityTool/__init__.py @@ -1,2 +1 @@ -#coding=utf-8 -from securityUtil import * \ No newline at end of file +#coding=utf-8 \ No newline at end of file diff --git a/Util/seleniumTool/__init__.py b/Util/seleniumTool/__init__.py index 04d0f61..8b13789 100644 --- a/Util/seleniumTool/__init__.py +++ b/Util/seleniumTool/__init__.py @@ -1,3 +1 @@ -# coding=utf-8 -from basePageUtil import * -from loginPageUtil import * + diff --git a/Util/seleniumTool/basePageUtil.py b/Util/seleniumTool/basePageUtil.py index 3fbabbf..680b7cf 100644 --- a/Util/seleniumTool/basePageUtil.py +++ b/Util/seleniumTool/basePageUtil.py @@ -39,7 +39,7 @@ def _open(self, url, pagetitle='',pageurl=''): # 使用get打开访问链接地址 self.driver.get(url) self.driver.maximize_window() - print self.driver.title,self.driver.current_url + print (self.driver.title,self.driver.current_url) if pagetitle: # 使用assert进行校验,打开的窗口title是否与配置的title一致。调用on_page()方法 assert self.on_page(pagetitle), "Check Page Error:\t%s" % url @@ -66,7 +66,7 @@ def find_elements(self, loc): # 等待元素可见 return WebDriverWait(self.driver, 5).until(EC.visibility_of_any_elements_located(loc)) except BaseException: - print 'page {0} does not have locator {1}'.format(self, loc) + print ('page {0} does not have locator {1}'.format(self, loc)) # 重写switch_frame方法 def switch_frame(self, loc): @@ -90,7 +90,7 @@ def send_keys(self, loc, vaule, clear_first=True, click_first=True): self.find_element(loc).send_keys(vaule) except AttributeError: - print '%s page does not have "%s" locator' % (self, loc) + print ('%s page does not have "%s" locator' % (self, loc)) # 重写鼠标悬停方法 def move_to_element(self, element='', loc=''): diff --git a/Util/seleniumTool/loginPageUtil.py b/Util/seleniumTool/loginPageUtil.py index 9ba0c27..0f25a5b 100644 --- a/Util/seleniumTool/loginPageUtil.py +++ b/Util/seleniumTool/loginPageUtil.py @@ -4,9 +4,9 @@ 页面基本操作方法,如open,input_username,input_password,click_submit """ +from Util.commonTool.configUtil import ConfigUtil +from Util.seleniumTool.basePageUtil import basePage from selenium.webdriver.common.by import By -from basePageUtil import basePage -from Util import * selenium_yml = '/config/selenium.yml' @@ -53,7 +53,7 @@ def show_span(self): else: return None except Exception as e: - print e + print (e) # 切换登录模式为动态密码登录(IE下有效) def swich_DynPw(self): diff --git a/Util/webserviceTool/__init__.py b/Util/webserviceTool/__init__.py index 4b16d55..e69de29 100644 --- a/Util/webserviceTool/__init__.py +++ b/Util/webserviceTool/__init__.py @@ -1 +0,0 @@ -from webServiceUtil import * \ No newline at end of file diff --git a/Util/webserviceTool/webServiceUtil.py b/Util/webserviceTool/webServiceUtil.py index 9e19176..e4bb45d 100644 --- a/Util/webserviceTool/webServiceUtil.py +++ b/Util/webserviceTool/webServiceUtil.py @@ -24,10 +24,10 @@ def Invoke(cls, url, method, *args): :type args: 随便传,列表形式的 """ try: - print 'Request: \t', [json.dumps(i, ensure_ascii=False, indent=4) for i in args] + print ('Request: \t', [json.dumps(i, ensure_ascii=False, indent=4) for i in args]) client = suds.client.Client(url) response = getattr(client.service, method)(*args) - print 'Response: \t', response + print ('Response: \t', response) return response except Exception as e: - print e + print (e) diff --git a/requirements.txt b/requirements.txt index ee3f79b..d358abb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,12 +4,12 @@ redis_py_cluster==1.3.4 requests==2.18.4 pycrypto==2.6.1 DBUtils==1.2 -suds==0.4 +suds-py3==1.3.3.0 six==1.11.0 selenium==3.5.0 locust==0.8 locustio==0.8.1 PyYAML==3.12 python-hessian==1.0.2 -pymssql==2.1.1 -MySQL-python==1.2.3 \ No newline at end of file +pymssql==2.1.3 +PyMySQL==0.8.0 \ No newline at end of file