Exemplo n.º 1
0
def test_snake(snake, number_of_games, board_size, max_moves, predictor: Network):

    Log("Testing performance on {} games...".format(number_of_games))

    snake_id = snake.get_id()
    generation = snake.get_generation()
    Log("Snake Id = {}".format(snake_id))
    Log("Generation = {}".format(generation))

    network.load(snake.get_chromosome())

    scores = []
    stats = []
    games = []

    for _ in range(number_of_games):
        game = SnakeGame.play(board_size, network, max_moves)
        games.append(game)
        scores.append(game.get_fitness())
        stats.append(game.get_statistics())
        
    best_indices = (np.array(scores)*-1).argsort()
    
    for i in best_indices:
        l,r,f,size = stats[i]
        fitness = scores[i]
        Log("Fitness: {} - L/R - Size : {}/{} - {}".format(fitness, l,r,size))
    
    Log("Average Fitness: {}".format(np.mean(scores)))

    best_game = games[best_indices[0]]
    worst_game = games[best_indices[-1]]

    return  best_game, worst_game
Exemplo n.º 2
0
    def race(self, top, games_per_snake):
        
        n = len(self.__snakes)
        Log("Racing {} snakes...".format(n))

        scores = []

        for i,s in enumerate(self.__snakes):
            
            self.__predictor.load(s.get_chromosome())
            total_score = 0

            for _ in range(games_per_snake):

                game = SnakeGame.play(self.__board_size, self.__predictor, self.__max_moves)
                total_score += game.get_fitness()

            avg_fitness = total_score/games_per_snake
            Log("Snake [{}] Fitness = {}".format(i, avg_fitness), end="\r")
            scores.append(avg_fitness)
        
        Log("                                                               ",end="\r")

        best_indices = (np.array(scores)*-1).argsort()[:top]
        top_snakes = [self.__snakes[i] for i in best_indices]
        top_scores = [scores[i] for i in best_indices]

        self.__snakes = top_snakes
        
        winners = [snake.get_epoch_entry(score) for snake,score in zip(top_snakes,top_scores)]
        self.__epoch_winners.append(winners)

        return top_snakes , top_scores
Exemplo n.º 3
0
class TestBasic(object):
    log = Log.MyLog()
    data = Basic()
    case_data = data.case_data
    request = Request.Request()
    test = Assert.Assertions()
    config = Config()
    noti = notify()

    # ids = [
    #     "测试:{}".
    #         format(case['test_name']) for case in case_data
    # ]
    @allure.feature('Home')
    @allure.severity('blocker')
    @allure.story('Basic')
    @allure.issue('https://baidu.com')
    @allure.testcase('https://baidu.com')
    @pytest.mark.flaky(reruns=3)
    # @pytest.mark.parametrize('case', case_data, ids=ids)
    @pytest.mark.parametrize('case', case_data)
    def test_login(self,case):
        """
        小程序登录
        """
        self.log.info('demo, utl={}, data={}, header={}'.format(case['url'], case['data'], case['header']))
        if case['method'] == 'post_request_urlencoded':
            result = self.request.post_request_urlencoded(case['url'], case['data'], case['header'])
            # 写入配置文件
            self.config.set_conf('parameter', 'token', result['data']['token'])
            assert self.test.assert_text(result['status'], 0)
            self.log.info('配置文件中token ={}'.format(self.config.get_conf('parameter', 'token')))
        allure.attach.file(BASE_PATH+'/Log/log.log', '附件内容是: ' + '老王调试日志', '我是附件名', allure.attachment_type.TEXT)
        Consts.RESULT_LIST.append('True')
Exemplo n.º 4
0
class TestProcess(object):
    config = Config()
    noti = notify()
    log = Log.MyLog()
    data = Process()
    case_data = data.case_data
    test = Assert.Assertions()
    # ids = [
    #     " 测试:{} ==>  预期结果:状态码={} ".
    #         format(case['test_name'], case['expected']) for case in case_data
    # ]
    @allure.feature('Home')
    @allure.severity('blocker')
    @allure.story('Process')
    @allure.issue(config.test04_unified_url)
    @allure.testcase(config.test04_unified_url)
    # @pytest.mark.flaky(reruns=3)
    # @pytest.mark.parametrize('case', case_data, ids=ids)
    @pytest.mark.parametrize('case', case_data)
    def test_process(self, case):
        TestProcess.test_process.__doc__ = case['test_name']
        self.log.info('demo, utl={}, data={}, header={}'.format(
            case['url'], case['data'], case['header']))
        # 判断请求方法
        result = self.noti.notify_result(case['mode'], case['url'],
                                         case['data'], case['header'])
        self.log.info('响应结果:%s' % result)
        print(result)
        parser(result, case['parser'], case['expected'])
        # self.test.assert_in_text(result,case['expected']),True)
        allure.attach.file((BASE_PATH + '/Log/log.log'), '附件内容是: ' + '老王调试日志',
                           '我是附件名', allure.attachment_type.TEXT)
        Consts.RESULT_LIST.append('True')
Exemplo n.º 5
0
 def __init__(self):
     self.config = Config()
     self.log = Log.MyLog()
     self.run_path = Config.path_dir
     self.USER_ID = str(get_value("xc手机号"))
     self.picture_verification_code = str(get_value("四位图片验证码"))
     self.login_verification_code = str(get_value("登录验证码"))
Exemplo n.º 6
0
    def __init__(self):
        """
        初始化
        """
        self.config = ConfigParser()
        self.log = Log.MyLog()
        self.conf_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'cfg.ini')
        self.xml_report_path = Config.path_dir+'/Report/xml'
        self.html_report_path = Config.path_dir+'/Report/html'

        if not os.path.exists(self.conf_path):
            raise FileNotFoundError("请确保配置文件存在!")

        self.config.read(self.conf_path, encoding='utf-8')

        self.tester = self.get_conf(Config.TITLE_ENV, Config.VALUE_TESTER)
        self.environment = self.get_conf(Config.TITLE_ENV, Config.VALUE_ENVIRONMENT)
        self.versionCode = self.get_conf(Config.TITLE_ENV, Config.VALUE_VERSION_CODE)
        self.host = self.get_conf(Config.TITLE_ENV, Config.VALUE_HOST)
        self.loginInfo = self.get_conf(Config.TITLE_ENV, Config.VALUE_LOGIN_INFO)

        self.smtpserver = self.get_conf(Config.TITLE_EMAIL, Config.VALUE_SMTP_SERVER)
        self.sender = self.get_conf(Config.TITLE_EMAIL, Config.VALUE_SENDER)
        self.receiver = self.get_conf(Config.TITLE_EMAIL, Config.VALUE_RECEIVER)
        self.username = self.get_conf(Config.TITLE_EMAIL, Config.VALUE_USERNAME)
        self.password = self.get_conf(Config.TITLE_EMAIL, Config.VALUE_PASSWORD)
        self.send = self.get_conf(Config.TITLE_EMAIL, Config.VALUE_SEND)
        self.token =  self.get_conf(Config.TITLE_TEST_DATA,Config.VALUE_TOKEN)
Exemplo n.º 7
0
    def __init__(self):
        """
		初始化
		"""
        self.config = ConfigParser()
        self.log = Log.MyLog()
        self.conf_path = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), 'config.ini')
        self.xml_report_path = Config.path_dir + '/Report/xml'
        self.html_report_path = Config.path_dir + '/Report/html'

        if not os.path.exists(self.conf_path):
            raise FileNotFoundError("请确保配置文件存在!")

        self.config.read(self.conf_path, encoding='utf-8')
        self.tester_debug = self.get_conf(Config.TITLE_DEBUG,
                                          Config.VALUE_TESTER)
        self.environment_debug = self.get_conf(Config.TITLE_DEBUG,
                                               Config.VALUE_ENVIRONMENT)
        self.versionCode_debug = self.get_conf(Config.TITLE_DEBUG,
                                               Config.VALUE_VERSION_CODE)
        self.host_debug = self.get_conf(Config.TITLE_DEBUG, Config.VALUE_HOST)

        self.tester_release = self.get_conf(Config.TITLE_RELEASE,
                                            Config.VALUE_TESTER)
        self.environment_release = self.get_conf(Config.TITLE_RELEASE,
                                                 Config.VALUE_ENVIRONMENT)
        self.versionCode_release = self.get_conf(Config.TITLE_RELEASE,
                                                 Config.VALUE_VERSION_CODE)
        self.host_release = self.get_conf(Config.TITLE_RELEASE,
                                          Config.VALUE_HOST)
Exemplo n.º 8
0
    def __init__(self):
        """
        初始化
        """
        self.config = ConfigParser()
        self.log = Log.MyLog()
        self.conf_path = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), 'config.ini')
        # print(self.conf_path)
        self.xml_report_path = Config.path_dir + '/allure-results'
        self.html_report_path = Config.path_dir + '/allure-report'

        if not os.path.exists(self.conf_path):
            raise FileNotFoundError("请确保配置文件存在!")
        self.config.read(self.conf_path, encoding='utf-8')

        # 一生约测试环境信息
        self.ysy_app = self.get_conf(Config.App_info, Config.YSY_APP)
        self.ysy_app_activity = self.get_conf(Config.App_info,
                                              Config.YSY_APP_ACTIVITY)
        self.tik_tok_app = self.get_conf(Config.App_info, Config.TIK_TOK_APP)
        self.tik_tok_app_activity = self.get_conf(Config.App_info,
                                                  Config.TIK_TOK_APP_ACTIVITY)
        self.sina = self.get_conf(Config.App_info, Config.SINA)
        self.sina_activity = self.get_conf(Config.App_info,
                                           Config.SINA_ACTIVITY)
Exemplo n.º 9
0
 def __init__(self):
     self.log = Log.MyLog()
     self.oper_j = operate_json.OperateJson()
     self.conf = Config.Config()
     self.excel = ExcelHandler.ExcelHandler()
     self.reqe = req_reload.ReqReload()
     self.test = Assert.Assertions()
 def setup_class(cls):
     #初始化用例参数,将全局变量替换成配置文件中得变量
     cls.result = {"result": True}
     #更新配置文件中的token
     cls.token = Token.Token()
     cls.token.save_token()
     cls.log = Log.MyLog()
     cls.Assert = Assert.Assertions()
Exemplo n.º 11
0
 def __init__(self):
     """
     :param env:
     """
     self.log = Log.MyLog()
     self.headers = {
         "User-Agent":
         "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
     }
Exemplo n.º 12
0
    def test_login_02(self, action):
        """
            用例描述:密码错误数据
        """

        # 写log
        with allure.step("写入Log"):
            log = Log.MyLog()
            log.info('文件已经开始执行')
            conf = Config()
            data = Login()

        request = Request.Request(action)

        #获取域名
        host = conf.host_debug
        req_url = 'http://' + host

        #获取请求参数
        urls = data.url
        params = data.data
        header = data.header
        requestsql = data.selectsql
        env = conf.environment
        responsecode = data.responsecode
        responsesql = data.responsesql
        casedescription = data.casedec

        #请求参数化
        with allure.step("获取输入参数值,{0}".format(requestsql[1])):
            try:
                sqlresult = SqlResult(requestsql[1], env).get_sqlresult()
                params[1][0]['auth'] = sqlresult['register_name']
            except:
                log.info("执行sql报错::" + requestsql[1])

        print(params[1][0])

        # 请求接口
        api_url = req_url + urls[1]
        with allure.step("开始请求接口,RUL: {0},header:{1},request:{2}".format(
                api_url, header[0], params[0][0])):
            response = request.post_request(api_url, json.dumps(params[1][0]),
                                            header[1])
            print(response)

        assertbody = Assertions()
        assertbody.assert_text(str(response['code']), str(responsecode[1]))
        with allure.step(
                "增加断言,ResponseCode:{0}=TestCode:{1},ResponseHeader:{2}".format(
                    response['code'], responsecode[1], response['header'])):
            if (response['code'] == responsecode[1]):
                #assertbody.assert_body(response['body'], 'message','密码错误')
                assertbody.assert_body(response['header'], 'X-Api-Error-Code',
                                       'ERR_LOGIN_FAILED')
            else:
                log.info("执行完成,Code不一致")
Exemplo n.º 13
0
    def test_updatehierarchy_03(self):
        """
            用例描述:不变层级,名称重复
        """

        # 写log
        with allure.step("写入Log"):
            log = Log.MyLog()
            log.info('文件已开始执行')
            conf = Config()
            data = UpdateHierarchy()

        # 获取请求域名
        host = conf.host_debug
        req_url = 'http://' + host

        # 获取请求参数
        urls = data.url[2]
        header = data.header[2]
        param = data.data[2]
        responsecode = data.responsecode[2]
        sql_name = data.sqlname[2]
        env = conf.environment
        selectsql = data.selectsql[2]
        errorcode = data.errorcode[2]
        parentid = SqlResult(selectsql, env).get_sqlresult()

        sqlname = str(sql_name).replace('@sqlresult', str(parentid['parent_id']))
        pname = SqlResult(sqlname, env).get_sqlresult()

        # 参数化请求参数
        with allure.step("获取输入参数值"):
            try:
                param[0]['id'] = parentid['id']
                param[0]['name'] = pname['name']
                param[0]['parent_id'] = parentid['parent_id']
            except:
                log.info("获取参数失败:{0}".format(param[0]))

        # 请求接口
        api_url = req_url + urls
        print(api_url)

        print(param[0])

        # post请求
        request = Request.Request()
        with allure.step("开始请求接口,RUL: {0},header:{1},request:{2}".format(api_url, header, param[0])):
            response = request.post_request(api_url, json.dumps(param[0]), header)
            print(response)

            # 增加断言
            with allure.step("接口返回结果:{0}".format(response)):
                if response['code'] == responsecode:
                    assertbody = Assertions()
                    assertbody.assert_text(response['body'], errorcode)
Exemplo n.º 14
0
 def setup_class(cls):
     """
     初始化用例参数,将全局变量替换成配置文件中得变量
     :return:
     """
     cls.result = {"result": True}
     cls.token = Token.Token()
     cls.token.save_token()
     cls.log = Log.MyLog()
     cls.Assert = Assert.Assertions()
Exemplo n.º 15
0
    def test_enablehierarchy_02(self):
        """
            用例描述:正常停用多个组织
        """

        # 写log
        with allure.step("写入Log"):
            log = Log.MyLog()
            log.info('文件已开始执行')
            conf = Config()
            data = EnableHierarchy()

        # 获取请求域名
        host = conf.host_debug
        req_url = 'http://' + host

        # 获取请求参数
        urls = data.url[1]
        header = data.header[1]
        param = data.data[1]
        selectsql = data.selectsql[1]
        responsecode = data.responsecode[1]
        env = conf.environment

        ids = SqlResult(selectsql, env).get_sqlresult_list()

        myid = []
        for i in range(len(ids)):
            for k, v in ids[i].items():
                myid.append(ids[i][k])
        print(myid)

        # 参数化请求参数
        with allure.step("获取输入参数值"):
            try:
                param[0]['ids'].extend(myid)
            except:
                log.info("获取参数失败:{0}".format(param[0]))

        # 请求接口
        api_url = req_url + urls

        # post请求
        request = Request.Request()
        with allure.step("开始请求接口,RUL: {0},header:{1},request:{2}".format(
                api_url, header, param[0])):
            response = request.post_request(api_url, json.dumps(param[0]),
                                            header)
            print(response)

        # 增加断言
        with allure.step("接口返回结果:{0}".format(response)):
            if response['code'] == responsecode:
                assertbody = Assertions()
                assertbody.assert_text(response['body'], True)
Exemplo n.º 16
0
 def __init__(self):
     self.config = Config.Config()
     self.log = Log.MyLog()
     self.data = ConfRelevance.ConfRelevance(
         CONF_PATH, "test_data").get_relevance_conf()
     self.headers = {
         "User-Agent":
         "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36",
         "Content-Type": "application/json",
         "X-Auth-Token": self.config.token
     }
Exemplo n.º 17
0
    def test_check_default_gasfee(self):
        logger = Log.Log(sys._getframe().f_code.co_name)
        logger.info("test begining")
        # param
        expect_value = '0'
        actual_value = None

        # test
        miner = Miner()
        actual_value = miner.xjrw_get_gasfee()

        assert expect_value == actual_value, f"error -> expect: {expect_value}, actual: {actual_value}"
Exemplo n.º 18
0
    def test_set_gasfee(self, expect_value, init_gasfee):
        init_gasfee
        logger = Log.Log(sys._getframe().f_code.co_name)
        logger.info("test begining")

        # test
        miner = Miner()
        miner.xjrw_set_gasfee(expect_value)
        actual_value = miner.xjrw_get_gasfee()

        # assert
        assert expect_value == actual_value, f"error -> expect: {expect_value}, actual: {actual_value}"
Exemplo n.º 19
0
    def __init__(self):
        """
        初始化
        """
        self.config = ConfigParser()
        self.log = Log.MyLog()
        self.conf_path = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), 'config.ini')
        self.xml_report_path = Config.path_dir + '/Report/xml'
        self.html_report_path = Config.path_dir + '/Report/html'

        if not os.path.exists(self.conf_path):
            raise FileNotFoundError("请确保配置文件存在!")

        self.config.read(self.conf_path, encoding='utf-8')

        if os.environ['Environ'] == 'test':
            self.tester = self.get_conf(Config.TITLE_DEBUG,
                                        Config.VALUE_TESTER)
            self.environment = self.get_conf(Config.TITLE_DEBUG,
                                             Config.VALUE_ENVIRONMENT)
            self.versionCode = self.get_conf(Config.TITLE_DEBUG,
                                             Config.VALUE_VERSION_CODE)
            self.host = self.get_conf(Config.TITLE_DEBUG, Config.VALUE_HOST)
            self.loginInfo = self.get_conf(Config.TITLE_DEBUG,
                                           Config.VALUE_LOGIN_INFO)
            self.Mysqlhost = self.get_conf(Config.TITLE_DEBUG,
                                           Config.VALUE_MYSQL_HOST)
            self.Mysqlport = self.get_conf(Config.TITLE_DEBUG,
                                           Config.VALUE_MYSQL_PORT)
            self.Mysqluser = self.get_conf(Config.TITLE_DEBUG,
                                           Config.VALUE_MYSQL_USER)
            self.Mysqlpasswd = self.get_conf(Config.TITLE_DEBUG,
                                             Config.VALUE_MYSQL_PASSWD)
        if os.environ['Environ'] == 'release':
            self.tester = self.get_conf(Config.TITLE_RELEASE,
                                        Config.VALUE_TESTER)
            self.environment = self.get_conf(Config.TITLE_RELEASE,
                                             Config.VALUE_ENVIRONMENT)
            self.versionCode = self.get_conf(Config.TITLE_RELEASE,
                                             Config.VALUE_VERSION_CODE)
            self.host = self.get_conf(Config.TITLE_RELEASE, Config.VALUE_HOST)
            self.loginInfo = self.get_conf(Config.TITLE_RELEASE,
                                           Config.VALUE_LOGIN_INFO)
            self.Mysqlhost = self.get_conf(Config.TITLE_RELEASE,
                                           Config.VALUE_MYSQL_HOST)
            self.Mysqlport = self.get_conf(Config.TITLE_RELEASE,
                                           Config.VALUE_MYSQL_PORT)
            self.Mysqluser = self.get_conf(Config.TITLE_RELEASE,
                                           Config.VALUE_MYSQL_USER)
            self.Mysqlpasswd = self.get_conf(Config.TITLE_RELEASE,
                                             Config.VALUE_MYSQL_PASSWD)
Exemplo n.º 20
0
 def setup_class(cls):
     #初始化用例参数,将全局变量替换成配置文件中得变量
     # cls.rel = ini_rel
     with allure.step("初始化环境变量"):
         cls.log = Log.MyLog()
         cls.Assert = Assert.Assertions()
         cls.log.info("设置project_token_name为amdin")
         conf = Config()
         conf.set_conf("test_data", "project_token_name", "admin")
         cls.result = {"result": True}
         #更新配置文件中的token
         cls.token = Token.Token()
         cls.token.save_token()
Exemplo n.º 21
0
 def dobbou_runner(self):
     if self.method.lower() == 'http':
         res = self.http_runner()
         return res
     elif self.method.lower() == 'https':
         res = self.https_runner()
         return res
     elif self.method.lower() == 'hessian':
         res = self.hessian_runner()
         return res
     else:
         Log.LOG('DOBBOU').log_info(
             'The protocol of Dobbou interface is invalid!')
Exemplo n.º 22
0
    def test_deletehierarchy_01(self):
        """
            用例描述:正常删除一个层级
        """

        #写log
        with allure.step("写入Log"):
            log = Log.MyLog()
            log.info('文件已开始执行')
            conf = Config()
            data = DeleteHierarchy()

        #获取请求域名
        host = conf.host_debug
        req_url = 'http://' + host

        # 获取请求参数
        urls = data.url[0]
        header = data.header[0]
        param = data.data[0]
        my_param = param[0]['id']
        selectsql = data.selectsql[0]
        responsecode = data.responsecode[0]
        env = conf.environment

        ids = SqlResult(selectsql, env).get_sqlresult()

        # 参数化请求参数
        with allure.step("获取输入参数值"):
            try:
                param[0]['id'].append(ids['id'])
            except:
                log.info("获取参数失败:{0}".format(param[0]))

        #请求接口
        api_url = req_url + urls
        print(api_url)

        #post请求
        request = Request.Request()
        with allure.step("开始请求接口,RUL: {0},header:{1},request:{2}".format(
                api_url, header, param[0])):
            response = request.post_request(api_url, json.dumps(my_param),
                                            header)
            print(response)

        # 增加断言
        with allure.step("接口返回结果:{0}".format(response)):
            if response['code'] == responsecode:
                assertbody = Assertions()
                assertbody.assert_text(response['body'], True)
Exemplo n.º 23
0
    def __init__(self):
        """
        初始化
        """
        self.config = ConfigParser()
        self.log = Log.MyLog()
        self.conf_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config.ini')
        # print(self.conf_path)
        self.xml_report_path = Config.path_dir+'/allure-results'
        self.html_report_path = Config.path_dir+'/Report'

        if not os.path.exists(self.conf_path):
            raise FileNotFoundError("请确保配置文件存在!")
        self.config.read(self.conf_path, encoding='utf-8')

        # 一生约测试库
        self.tester_debug = self.get_conf(Config.TITLE_DEBUG, Config.YSY_TESTER)
        self.environment_debug = self.get_conf(Config.TITLE_DEBUG, Config.YSY_TEST_ENVIRONMENT)
        self.host_debug = self.get_conf(Config.TITLE_DEBUG, Config.YSY_TEST_HOST)
        self.db_host_ysy_debug = self.get_conf(Config.TITLE_DEBUG,Config.YSY_TEST_DB_HOST)
        self.db_port_ysy_debug = self.get_conf(Config.TITLE_DEBUG,Config.YSY_TEST_DB_PORT)
        self.db_name_ysy_debug = self.get_conf(Config.TITLE_DEBUG, Config.YSY_TEST_DB_NAME)
        self.db_user_ysy_debug = self.get_conf(Config.TITLE_DEBUG, Config.YSY_TEST_DB_USER)
        self.db_pwd_ysy_debug = self.get_conf(Config.TITLE_DEBUG, Config.YSY_TEST_DB_PWD)
        self.yhz_host = self.get_conf(Config.TITLE_DEBUG,Config.YHZ_HOST)

        # 雨花斋测试库
        self.yhz_db_name = self.get_conf(Config.TITLE_DEBUG,Config.YHZ_DB_NAME)


        # 一生约正式库
        self.tester_release = self.get_conf(Config.TITLE_RELEASE, Config.YSY_REALSER)
        self.environment_release = self.get_conf(Config.TITLE_RELEASE, Config.YSY_REALSE_ENVIRONMENT)
        self.host_release = self.get_conf(Config.TITLE_RELEASE, Config.YSY_REALSE_HOST)
        self.db_host_ysy_release = self.get_conf(Config.TITLE_RELEASE, Config.YSY_REALSE_DB_HOST)
        self.db_port_ysy_release = self.get_conf(Config.TITLE_RELEASE, Config.YSY_REALSE_DB_PORT)
        self.db_name_ysy_release = self.get_conf(Config.TITLE_RELEASE, Config.YSY_REALSE_DB_NAME)
        self.db_user_ysy_release = self.get_conf(Config.TITLE_RELEASE, Config.YSY_REALSE_DB_USER)
        self.db_pwd_ysy_release = self.get_conf(Config.TITLE_RELEASE, Config.YSY_REALSE_DB_PWD)

        # 小猪数据库
        self.tysyo2o_host = self.get_conf(Config.TITLE_DEBUG, Config.TO2O_HOST)
        self.db_name_o2o_debug = self.get_conf(Config.TITLE_DEBUG,Config.TO2O_DB_NAME)


        self.smtpserver = self.get_conf(Config.TITLE_EMAIL, Config.VALUE_SMTP_SERVER)
        self.sender = self.get_conf(Config.TITLE_EMAIL, Config.VALUE_SENDER)
        self.receiver = self.get_conf(Config.TITLE_EMAIL, Config.VALUE_RECEIVER)
        self.username = self.get_conf(Config.TITLE_EMAIL, Config.VALUE_USERNAME)
        self.password = self.get_conf(Config.TITLE_EMAIL, Config.VALUE_PASSWORD)
Exemplo n.º 24
0
    def play(board_size, predictor: Network, max_moves, print_sensory=False):

        game = SnakeGame(board_size, max_moves=max_moves)

        while True:
            inputs = game.get_sensory_inputs()
            if (print_sensory):
                Log(str(inputs))
            index = predictor.predict(inputs)
            turn = ALL_TURNS[index]
            if (game.move(turn)):
                break

        return game
    def test_hierarchy_01(self):
        """
            用例描述:获取目录
        """

        #写log
        with allure.step("写入Log"):
            log = Log.MyLog()
            log.info('文件已开始执行')
            conf = Config()
            data = GetHierarchy()

        #获取请求域名
        host = conf.host_debug
        req_url = 'http://' + host
        env = conf.environment
        responsesql = data.responsesql
        responsecode = data.responsecode

        # 获取请求参数
        urls = data.url
        header = data.header

        #请求接口
        api_url = req_url + urls
        request = Request.Request()
        with allure.step("开始请求接口,RUL: {0},header:{1}".format(api_url, header)):
            response = request.get_request(api_url, None, header)
            print(response['body'])

        # 数据库查询结果
        try:
            # print(responsesql)
            responsesqlresult = SqlResult(responsesql, env).get_sqlresult_list()
            print(responsesqlresult)
            with allure.step("获取预期结果值成功"):
                log.info('查询结果数据库成功:' + responsesql)
        except:
            log.info('查询结果数据库失败:' + responsesql)

        print(responsecode)

        # 增加断言
        assertbody = Assertions()
        with allure.step("增加断言,接口返回结果:{0}".format(response)):
            assertbody.assert_text(str(response['code']), str(responsecode))
            if response['code'] == responsecode:
                for i in range(len(responsesqlresult)):
                    for k, v in responsesqlresult[i].items():
                        assertbody.assert_body(response['body'][i], k, responsesqlresult[i][k])
Exemplo n.º 26
0
    def __init__(self):
        """
        初始化
        """
        self.config = ConfigParser()
        self.log = Log.MyLog()
        self.conf_path = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), 'config.ini')
        self.xml_report_path = Config.path_dir + '/Report/xml'
        self.html_report_path = Config.path_dir + '/Report/html'

        if not os.path.exists(self.conf_path):
            raise FileNotFoundError("请确认配置文件存在!")

        self.config.read(self.conf_path, encoding='utf-8')
Exemplo n.º 27
0
    def __init__(self):
        """
        初始化
        """
        self.config = ConfigParser()
        self.log = Log.MyLog()

        self.xml_report_path = Config.path_dir + '/Report/xml'
        self.html_report_path = Config.path_dir + '/Report/html'
        self.json_schema_path = Config.path_dir + '/TestCase/JSONschema'
        self.debug_gossapi_host = "http://gossapit.xgimi.com"
        self.debug_goss_host = "http://goss.t.xgimi.com"
        self.debug_headers = {
            "Content-Type": "application/x-www-form-urlencoded"
        }
Exemplo n.º 28
0
    def __init__(self):
        self.config = Config.Config()
        self.log = Log.MyLog()
        self.relevance = ConfRelevance.ConfRelevance(
            CONF_PATH, "test_data").get_relevance_conf()
        self.headers = {
            "User-Agent":
            "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36",
            "Content-Type": "application/json",
            "X-Auth-Token": "${token_id}$"
        }

        self.address = {
            "address":
            "/v3/projects/${project_id}$/users/${admin_id}$/roles/${admin_role_id}$"
        }
    def test_getproduct_01(self, action):
        """
            用例描述:测试get1
        """

        with allure.step("用例开始"):  # 步骤2,step的参数将会打印到测试报告中
            allure.attach('test2', '开始测试'),

        log = Log.MyLog()
        log.info('文件已经开始执行')
        conf = Config()
        data = AddToCart()
        request = Request.Request(action)

        host = conf.host_debug
        port = conf.portShopService_debug
        req_url = 'http://' + host + ':' + port
        print(req_url)
        urls = data.url
        params = data.data
        header = data.header
        requestsql = data.requestsql
        responsecode = data.responsecode
        #responsesql = data.responsesql
        #connection=SqlResult.connect_mysql()
        with allure.step('请求参数:'):  # 步骤2,step的参数将会打印到测试报告中
            allure.attach(str(urls[0]), '请求url')
            allure.attach(str(params[0][0]), '请求参数:')
            allure.attach(str(urls[0]), '请求heder:')

        sqlresult = SqlResult(requestsql[0], 'debug').get_sqlresult()

        print(sqlresult['id'])

        api_url = req_url + urls[0]
        #print(api_url)
        print(params[0][0])
        params[0][0]['memberId'] = 7
        print(params[0][0])
        #print(header[0])
        response = request.post_request(api_url, params[0][0], header[0])
        with allure.step('执行测试完成:'):  # 步骤2,step的参数将会打印到测试报告中
            allure.attach(str(response['code']), '请求结果')
            allure.attach(str(response['body']), '请求结果体')
        assert response['code'] == responsecode[0]
    def test_addhierarchy_07(self):
        """
            用例描述:name字段传空
        """
        # 写log
        with allure.step("写入Log"):
            log = Log.MyLog()
            log.info('文件已经开始执行')
            conf = Config()
            data = AddHierarchy()

        # 获取请求域名
        host = conf.host_debug
        req_url = 'http://' + host

        # 获取请求参数
        urls = data.url[4]
        header = data.header[4]
        param = data.data[4]
        env = conf.environment
        responsecode = data.responsecode[4]
        responsesql = data.responsesql[4]
        selectsql = data.selectsql[4]
        errorcode = data.errorcode[4]
        print(param[0])

        # 请求接口
        api_url = req_url + urls
        print(api_url)

        # post请求
        request = Request.Request()
        with allure.step("开始请求接口,RUL: {0},header:{1},request:{2}".format(
                api_url, header, param[0])):
            response = request.post_request(api_url, json.dumps(param[0]),
                                            header)
            print(response)

        # 增加断言
        with allure.step("接口返回结果:{0}".format(response)):
            if response['code'] == responsecode:
                assert response['body']
                assertbody = Assertions()
                assertbody.assert_text(response['header']['X-Api-Error-Code'],
                                       errorcode)