def __init__(self,str_data,type="excel"): # print('__case init__') self.str_data=str_data self.logger=SkiLogger("BearSki.DataTable") self.logger.warn("bear.base 中的方法将被废弃通过 bear.core 替代,建议将 from BearSki.base 修改为 from BearSki.core") self.basedata=SkiGlobalData().get_datatable_config() self.type=type
def __init__(self): # print('__case init__') self.logger = SkiLogger("BearSki.base") self.logger.warn( "bear.base 中的方法将被废弃,相关功能通过 bear.core 替代,建议将 from BearSki.base 修改为 from BearSki.core" ) scd = SkiGlobalData()
class case(): def __init__(self): # print('__case init__') self.logger=SkiLogger("BearSki.base") self.logger.warn("bear.base 中的方法将被废弃,相关功能通过 bear.core 替代,建议将 from BearSki.base 修改为 from BearSki.core") scd=SkiGlobalData() def __call__(self,func): def __deco(self,*arg,**kws): # print("before %s called [%s],[%s]." % (func.__name__, arg,kws)) result=func(self,*arg,**kws) # print(" after %s called [%s],[%s]." % (func.__name__, arg,kws)) return result return __deco
class DT(object): #改写DataTable 函数,修改成支持多种数据源方法类。 logger=SkiLogger("BearSki.DataTable") basedata=SkiGlobalData().get_datatable_config() @classmethod def excel(self,str_data,type="json"): if type=='list': return self._excel_list(self,str_data) else: return self._excel_json(self,str_data) @classmethod def json(self,filename,tgb=False,cgb=True): revalue=getJsonData(filename,self.basedata["db_json_path"]) return revalue @classmethod def DB(self,str_data,linkname=""): pass @classmethod def cloud(self,str_data,severs_path=""): pass def _excel_list(self,str_data): title,rowdata=getRowData(str_data, self.basedata["db_excel_path"]) res=generate_data(title,rowdata) self.logger.debug(u"依据索引[{0}]获取测试数据为:{1},数据源为:{2}".format(str_data,res, self.basedata["db_excel_path"])) return res def _excel_json(self,str_data): title,rowdata=getRowData(str_data, self.basedata["db_excel_path"]) res=generate_json_data(title,rowdata) self.logger.debug(u"依据索引[{0}]获取测试数据为:{1},数据源为:{2}".format(str_data,res, self.basedata["db_excel_path"])) return res
class TD: ### 替换 DT类和SkiGlobalData SkiGlobalData:类名过长。与测试执行相关数据统一在TD类下处理。TD:db 当前实现简单版本 logger = SkiLogger("BearSki.core") @classmethod def get_Data(cls, dataid, type='json'): database_parms = SkiGlobalData().get_database_parms() database_engine = cls._getDatabaseEngine(cls, database_parms) database_engine.connect() return database_engine.get_data(dataid, type, database_parms) def _getDatabaseEngine(self, engine_parms): engine_name = engine_parms['ENGINE'] namelist = engine_name.split('.') module = ".".join(namelist[:-1]) clsobj = namelist[-1:] obj = __import__(module, fromlist=True) if hasattr(obj, clsobj[0]): func = getattr(obj, clsobj[0]) clo = func(engine_parms) return clo else: raise DataBaseError(Exception, "无法创建数据引擎") @staticmethod def get_global_all_data(): return SkiGlobalData().get_global_all_data() @staticmethod def get_global_data(value): return SkiGlobalData().get_global_data(value) @staticmethod def add_global_data(data): SkiGlobalData().add_global_data(data)
class atest_api_users(unittest.TestCase, Ski): def setUp(self): self.logger = SkiLogger("atest_api_users") def tearDown(self): pass @Ski.case() def case_api_users(self): model_name = "api_users" self.logger.info("in case_api_users") mjstr = DT.json(model_name + '_model.json') res = self.step("requestFromModel", mjstr) jstr = DT.json(model_name + "_res.json") self.assertEqual(jstr['status'], res.result.status_code) self.logger.info("login res {0}".format(res))
class DT(object): def __init__(self, str_data): # print('__case init__') self.str_data = str_data self.logger = SkiLogger("BearSki.DataTable") self.basedata = SkiGlobalData().get_datatable_config() def list(self): title, rowdata = getRowData(self.str_data, self.basedata["db_path"]) res = generate_data(title, rowdata) self.logger.debug(u"依据索引[{0}]获取测试数据为:{1},数据源为:{2}".format( self.str_data, res, self.basedata["db_path"])) return res def json(self): title, rowdata = getRowData(self.str_data, self.basedata["db_path"]) res = generate_json_data(title, rowdata) self.logger.debug(u"依据索引[{0}]获取测试数据为:{1},数据源为:{2}".format( self.str_data, res, self.basedata["db_path"])) return res pass
class DT(object): def __init__(self, str_data, type="excel"): # print('__case init__') self.str_data = str_data self.logger = SkiLogger("BearSki.DataTable") self.logger.warn( "bear.base 中的方法将被废弃通过 bear.core 替代,建议将 from BearSki.base 修改为 from BearSki.core" ) self.basedata = SkiGlobalData().get_datatable_config() self.type = type def list(self): if self.type == 'excel': return self._excel_list() def json(self): if self.type == 'excel': return self._excel_list() else: return self._json_json() def _excel_list(self): title, rowdata = getRowData(self.str_data, self.basedata["db_path"]) res = generate_data(title, rowdata) self.logger.debug(u"依据索引[{0}]获取测试数据为:{1},数据源为:{2}".format( self.str_data, res, self.basedata["db_path"])) return res def _excel_json(self): title, rowdata = getRowData(self.str_data, self.basedata["db_path"]) res = generate_json_data(title, rowdata) self.logger.debug(u"依据索引[{0}]获取测试数据为:{1},数据源为:{2}".format( self.str_data, res, self.basedata["db_path"])) return res
class TestSendMessage(unittest.TestCase, Ski): def setUp(self): self.logger = SkiLogger('TestSendMessage') def tearDown(self): pass @Ski.case() def test_send(self): self.logger.info("I'm in test_two test_send") # print(self.ski_step_result) self.assertTrue(True) res = self.step("userkw_sendmsg", "get", "http://www.baidu.com") self.logger.info(res.result) self.assertEqual(200, res.result.status_code) @Ski.case() def test_send_use_robotframework_requestlibary(self): self.logger.info("I'm in test_two test_send") # print(self.ski_step_result) # self.assertTrue(True) self.step("Create Session", "baidu", "http://www.baidu.com") res = self.step("Get Request", "baidu", "/") self.assertEqual(200, res.result.status_code)
import os import shutil import sys from BearSki.testproject_template import BasicTestProject from BearSki.utils.logger import SkiLogger logger = SkiLogger("Manager") def creat_test_project(projectname): BasicTestProject.create_testproject(projectname)
def setUp(self): self.logger = SkiLogger("atest_api_users")
@Time : 2020/01/30 23:29:00 @Author : chenjiusi ''' # coding=utf-8 import time import unittest from BearSki import * import json import subprocess from unittest import mock from BearSki.utils.logger import SkiLogger import os import multiprocessing logger = SkiLogger("test") class test_BearSki(unittest.TestCase): ASSREQ = "/auth/login/" ASSRES = { "_transferSize": 419, "bodySize": 234, "content": { "compression": 0, "mimeType": "application/json", "size":
def __init__(self, keyword, *arg, **kws): self.logger = SkiLogger("BearSki.step") scd = SkiGlobalData() conf = scd.get_setting_data() full_modules = conf[keyword] self.result = self.__run(full_modules, *arg, **kws)
class step(): def __init__(self, keyword, *arg, **kws): self.logger = SkiLogger("BearSki.step") scd = SkiGlobalData() conf = scd.get_setting_data() full_modules = conf[keyword] self.result = self.__run(full_modules, *arg, **kws) # self.logger.debug(self.result) def __run(self, kw_path, *arg, **kws): try: modules = self.__getModules(kw_path) except Exception: self.logger.error( "error,does not find modules [{0}]".format(kw_path)) return None fun_list = kw_path[len(modules) + 1:].split('.') return self.__getObject(modules, fun_list)(*arg, **kws) def __getObject(self, modules, fun_list): obj = import_module(modules) child_obj = getattr(obj, fun_list[0]) temp_cls_name = fun_list[0] for key in fun_list[1:]: if inspect.isclass(child_obj): # print("this is a class") temp_cls = SkiGlobalData().get_step_class_instance( temp_cls_name) if temp_cls is None: child_obj = child_obj() SkiGlobalData().set_step_class_instance( temp_cls_name, child_obj) else: child_obj = temp_cls child_obj = getattr(child_obj, key) temp_cls_name = key return child_obj def __getModules(self, kw_path): # print(kw_path) if kw_path.find('.') == -1: if self.__ismodule(kw_path): return kw_path # 需要测试 else: raise Exception( "all error,does not find modules [{0}]".format( kw_path)) kw = kw_path.split('.')[-1] modules = kw_path[0:kw_path.rindex(kw) - 1] #rindex 为了应对报名重名 从后向前计算 flag = self.__ismodule(modules) # print(flag) if flag: # print(modules) return modules else: # print(modules) return self.__getModules(modules) def __ismodule(self, module_name): # print("++++++ is module ++++") # print(module_name) # print("====== is module =====") module_spec = None try: module_spec = importlib.util.find_spec(module_name) except Exception as error: # print(error) self.logger.error("error", error) return False if module_spec is None: # print("Module :{} not found".format(module_name)) # print("false") return False else: # print("Module:{} can be imported!".format(module_name)) # print("true") return True
def __init__(self): # print('__case init__') self.logger = SkiLogger("BearSki.base") scd = SkiGlobalData()
def __init__(self): # print('__case init__') self.logger = SkiLogger("BearSki.init")
def __init__(self, str_data): # print('__case init__') self.str_data = str_data self.logger = SkiLogger("BearSki.DataTable") self.basedata = SkiGlobalData().get_datatable_config()
def setUp(self): self.logger = SkiLogger('TestSendMessage')
import unittest from BearSki.RunUnittest import HTMLTestRunner import BearSki.RunUnittest as rut from BearSki.utils.logger import SkiLogger import time import sys logger = SkiLogger('runtest') def get_test_cases(dirpath, name="test_"): test_cases = unittest.TestSuite() # 测试用例使用"ski_"开头命名 suites = unittest.defaultTestLoader.discover(dirpath, name + '*.py', top_level_dir=dirpath) for suite in suites: test_cases.addTests(suite) return test_cases if __name__ == '__main__': report_type = input("report mode(h or t):") casepath = input("input case file pash(defult is ./utest/testcase):") casename = input("input case name (defult is test_*.py):") cases = get_test_cases('./utest/testcase' + casepath, casename) now = time.strftime("%Y-%m-%d %H_%M_%S") # 报告生成时间 test_reports_address = '../utest/report' # 测试报告存放位置 filename = './utest/report/' + now + 'report.html' # 设置报告文件名 if (report_type == 't'):
from driver import d_requests from BearSki.utils.logger import SkiLogger logger = SkiLogger('keywords.send') def askbaidu(mod, data): logger.info('in ask baidu!') print(mod) r = d_requests.get(url=data) # 最基本的GET请求 return r