コード例 #1
0
def test_top_write(module_name):
    excel.row_point += 1
    if excel_type == "xlsx":
        excel.sheet_fd.write(excel.row_point, 0, "Atten")
        excel.sheet_fd.write(excel.row_point, 1, "Downlink")
        excel.sheet_fd.write(excel.row_point, 2, "Uplink")
    elif excel_type == "xls":
        excel.sheet_fd.write(excel.row_point,
                             0,
                             "Atten",
                             style=zexcel.set_style(zexcel.BLACK,
                                                    280,
                                                    bold=False,
                                                    align='',
                                                    pattern_color='gray25'))
        excel.sheet_fd.write(excel.row_point,
                             1,
                             "Downlink",
                             style=zexcel.set_style(zexcel.BLACK,
                                                    280,
                                                    bold=False,
                                                    align='',
                                                    pattern_color='gray25'))
        excel.sheet_fd.write(excel.row_point,
                             2,
                             "Uplink",
                             style=zexcel.set_style(zexcel.BLACK,
                                                    280,
                                                    bold=False,
                                                    align='',
                                                    pattern_color='gray25'))
コード例 #2
0
def test_end():
    # 将统计的count pass fail写入excel
    test.total_num = test.pass_num + test.fail_num
    for key in excel.module_info:
        excel.sheet_fd.write(excel.module_info[key]["row"], zexcel.COUNT_COL, excel.module_info[key]["count"],
                             style=zexcel.set_style(zexcel.RED, 240, bold=False, align=''))
        excel.sheet_fd.write(excel.module_info[key]["row"], zexcel.PASS_COL, excel.module_info[key]["pass"],
                             style=zexcel.set_style(zexcel.RED, 240, bold=False, align=''))
        excel.sheet_fd.write(excel.module_info[key]["row"], zexcel.FAIL_COL, excel.module_info[key]["fail"],
                             style=zexcel.set_style(zexcel.RED, 240, bold=False, align=''))

    excel.sheet_fd.write(zexcel.PROJECT_ROW, zexcel.PROJECT_COL + 1, test.project,
                         style=zexcel.set_style(zexcel.BLACK, 260, bold=True, align='', pattern_color='light_orange'))
    excel.sheet_fd.write(zexcel.VERSION_ROW, zexcel.VERSION_COL + 1, test.version,
                         style=zexcel.set_style(zexcel.BLACK, 260, bold=True, align='', pattern_color='light_orange'))
    excel.sheet_fd.write(zexcel.MAC_ROW, zexcel.MAC_COL + 1, test.mac,
                         style=zexcel.set_style(zexcel.BLACK, 260, bold=True, align='', pattern_color='light_orange'))
    excel.sheet_fd.write(zexcel.DATE_ROW, zexcel.DATE_COL + 1, test.date,
                         style=zexcel.set_style(zexcel.BLACK, 260, bold=True, align='', pattern_color='light_orange'))
    excel.sheet_fd.write(zexcel.TOTAL_ROW, zexcel.TOTAL_COL + 1, test.total_num,
                         style=zexcel.set_style(zexcel.BLACK, 260, bold=True, align='', pattern_color='light_orange'))
    excel.sheet_fd.write(zexcel.TOTAL_PASS_ROW, zexcel.TOTAL_PASS_COL + 1, test.pass_num,
                         style=zexcel.set_style(zexcel.BLACK, 260, bold=True, align='', pattern_color='light_orange'))
    excel.sheet_fd.write(zexcel.TOTAL_FAIL_ROW, zexcel.TOTAL_FAIL_COL + 1, test.fail_num,
                         style=zexcel.set_style(zexcel.BLACK, 260, bold=True, align='', pattern_color='light_orange'))

    filename = "../results/" + test.output_file + ".xls"
    excel.excel_fd.save(filename)  # 保存xls
    logging.info("test end!")
    exit()
コード例 #3
0
def run_test_case(module_name):
    # 写excel表,test case的头部
    test_top_write(module_name)

    for attenuation in radio_rack.attenuation:

        set_command = "ATT "
        for channel in radio_rack.channel:
            set_command += channel + " " + attenuation + ";"
        set_command = set_command[:-1] + "<CR><LF>"
        set_RadioRack(set_command)

        logging.info(" ############ Uplink : %s dB", attenuation)
        uplink_data = run_IxChariot(attenuation + "db_uplink",
                                    radio_rack.wait_time)
        change_direction()

        logging.info(" ############ Downlink : %s dB", attenuation)
        downlink_data = run_IxChariot(attenuation + "db_downlink",
                                      radio_rack.wait_time)
        change_direction()

        # 写excel
        excel.row_point += 1
        if excel_type == "xlsx":
            excel.sheet_fd.write(excel.row_point, CASE_NAME_COL,
                                 attenuation + "dB")
            excel.sheet_fd.write(excel.row_point, CASE_UPLINK_COL, uplink_data)
            excel.sheet_fd.write(excel.row_point, CASE_DOWNLINK_COL,
                                 downlink_data)
        elif excel_type == "xls":
            excel.sheet_fd.write(excel.row_point,
                                 CASE_NAME_COL,
                                 attenuation + "dB",
                                 style=zexcel.set_style(zexcel.BLACK,
                                                        240,
                                                        bold=False,
                                                        align=''))
            excel.sheet_fd.write(excel.row_point,
                                 CASE_UPLINK_COL,
                                 uplink_data,
                                 style=zexcel.set_style(zexcel.GREEN,
                                                        240,
                                                        bold=False,
                                                        align=''))
            excel.sheet_fd.write(excel.row_point,
                                 CASE_DOWNLINK_COL,
                                 downlink_data,
                                 style=zexcel.set_style(zexcel.GREEN,
                                                        240,
                                                        bold=False,
                                                        align=''))
            filename = os.path.join(
                os.path.dirname(__file__) + "/../results/" + test.output_file +
                ".xls")
            excel.excel_fd.save(filename)  # 保存xls

        time.sleep(2)

    return True
コード例 #4
0
def run_test_case():
    test_time = 0
    while True:
        # 每个线程一个sheet
        for process in test.process:

            mem_result = start_connect_ssh(process)

            excel.row_point[process] += 1
            excel.sheet_fd[process].write(excel.row_point[process],
                                          CASE_TIME_COL,
                                          test_time,
                                          style=zexcel.set_style(zexcel.BLACK,
                                                                 240,
                                                                 bold=False,
                                                                 align=''))
            excel.sheet_fd[process].write(excel.row_point[process],
                                          CASE_MEM_COL,
                                          mem_result,
                                          style=zexcel.set_style(zexcel.BLACK,
                                                                 240,
                                                                 bold=False,
                                                                 align=''))

            filename = os.path.join(
                os.path.dirname(__file__) + "./../results/" +
                test.output_file + ".xls")
            excel.excel_fd.save(filename)  # 保存xls

        test_time += 1
        logging.info("time: %d", test_time)
        time.sleep(6)
コード例 #5
0
def run_test_case(module_name):
    # 写excel表,test case的头部
    test_top_write(module_name)
    for key in server.input_dict:
        # 填写测试名称到excel的第一列
        excel.row_point += 1
        excel.sheet_fd.write(excel.row_point, zexcel.CASE_NAME_COL, key,
                             style=zexcel.set_style(zexcel.BLACK, 240, bold=False, align=''))
        excel.module_info[module_name]["count"] += 1

        # 一个case里面可能会有多个请求
        request_i = 0
        request_result = True
        while request_i < len(server.input_dict[key]):
            try:
                if server.input_dict[key][request_i].__contains__("method"):   # api设置接口
                    request_data = server.input_dict[key][request_i]
                    request_data["sid"] = server.sid
                    logging.info("%s send:%s", key, request_data)
                    resp_data = requests.post(server.url, data=json.dumps(request_data), headers=server.headers)
                    logging.info("%s recv:%s", key, resp_data.text)
                    if resp_data.status_code == 200:
                        msg = json.loads(resp_data.text)
                        # 判断返回的数据与output_json里面的数据是否一致
                        if msg != server.output_dict[key][request_i]:
                            request_result = False
                else:   # wifi连接
                    wifi_info = server.input_dict[key][request_i]
                    if wifi_info["w2"]["ssid"]:
                        if not utils_wifi.start_connect_wifi(wifi_info["w2"]):
                            request_result = False

                    if wifi_info["w5"]["ssid"]:
                        if not utils_wifi.start_connect_wifi(wifi_info["w5"]):
                            request_result = False

            except Exception as e:
                logging.info("---异常---:", e)
                request_result = False

            request_i += 1
            time.sleep(2)

        # 填写测试结果到excel的第二列
        if request_result:
            logging.info("pass")
            excel.sheet_fd.write(excel.row_point, zexcel.CASE_RESULT_COL, "pass",
                                 style=zexcel.set_style(zexcel.GREEN, 240, bold=False, align=''))
            excel.module_info[module_name]["pass"] += 1
            test.pass_num += 1
        else:
            logging.info("fail")
            excel.sheet_fd.write(excel.row_point, zexcel.CASE_RESULT_COL, "fail",
                                 style=zexcel.set_style(zexcel.RED, 240, bold=False, align=''))
            excel.module_info[module_name]["fail"] += 1
            test.fail_num += 1

    return True
コード例 #6
0
def excel_init(module_name):
    excel.excel_fd = zexcel.excel_init()
    sheet_name = test.name + " " + module_name + "测试结果"
    excel.sheet_fd = zexcel.common_sheet_init(excel.excel_fd, sheet_name)
    # 从第二行开始写入
    excel.row_point = 1
    rows = ['', 'Count', 'Eth', 'Wifi', 'Time']
    for index, val in enumerate(rows):
        excel.sheet_fd.write(1,
                             index,
                             val,
                             style=zexcel.set_style(zexcel.BLACK,
                                                    280,
                                                    bold=True,
                                                    pattern_color='gray25'))

    # 写设备信息
    excel.sheet_fd.write(zexcel.PROJECT_ROW,
                         zexcel.PROJECT_COL + 1,
                         test.project,
                         style=zexcel.set_style(zexcel.BLACK,
                                                260,
                                                bold=True,
                                                align='',
                                                pattern_color='light_orange'))
    excel.sheet_fd.write(zexcel.VERSION_ROW,
                         zexcel.VERSION_COL + 1,
                         test.version,
                         style=zexcel.set_style(zexcel.BLACK,
                                                260,
                                                bold=True,
                                                align='',
                                                pattern_color='light_orange'))
    excel.sheet_fd.write(zexcel.MAC_ROW,
                         zexcel.MAC_COL + 1,
                         test.mac,
                         style=zexcel.set_style(zexcel.BLACK,
                                                260,
                                                bold=True,
                                                align='',
                                                pattern_color='light_orange'))
    excel.sheet_fd.write(zexcel.DATE_ROW,
                         zexcel.DATE_COL + 1,
                         test.date,
                         style=zexcel.set_style(zexcel.BLACK,
                                                260,
                                                bold=True,
                                                align='',
                                                pattern_color='light_orange'))

    filename = os.path.join(
        os.path.dirname(__file__) + "./../results/" + test.output_file +
        ".xls")
    excel.excel_fd.save(filename)  # 保存xls
コード例 #7
0
def excel_init():
    excel.excel_fd = zexcel.excel_init()

    # 每个线程一个sheet
    for process in test.process:
        logging.info(process)
        excel.sheet_fd[process] = excel.excel_fd.add_sheet(process)  # 增加sheet
        excel.sheet_fd[process].col(CASE_TIME_COL).width = 200 * 25  # 设置第1列列宽
        excel.sheet_fd[process].col(CASE_MEM_COL).width = 200 * 25  # 设置第2列列宽
        excel.row_point[process] = 0

        rows = ['时间(分钟)', '内存(Kb)']
        for index, val in enumerate(rows):
            excel.sheet_fd[process].write(excel.row_point[process],
                                          index,
                                          val,
                                          style=zexcel.set_style(
                                              zexcel.BLACK,
                                              280,
                                              bold=True,
                                              pattern_color='gray25'))

    filename = os.path.join(
        os.path.dirname(__file__) + "./../results/" + test.output_file +
        ".xls")
    excel.excel_fd.save(filename)  # 保存xls
コード例 #8
0
def excel_init(module_name):
    excel.excel_fd = zexcel.excel_init()
    sheet_name = test.name + " " + module_name + "测试结果"
    excel.sheet_fd = zexcel.sheet_init(excel.excel_fd, sheet_name)

    # 写设备信息
    excel.sheet_fd.write(zexcel.PROJECT_ROW,
                         zexcel.PROJECT_COL + 1,
                         test.project,
                         style=zexcel.set_style(zexcel.BLACK,
                                                260,
                                                bold=True,
                                                align='',
                                                pattern_color='light_orange'))
    excel.sheet_fd.write(zexcel.VERSION_ROW,
                         zexcel.VERSION_COL + 1,
                         test.version,
                         style=zexcel.set_style(zexcel.BLACK,
                                                260,
                                                bold=True,
                                                align='',
                                                pattern_color='light_orange'))
    excel.sheet_fd.write(zexcel.MAC_ROW,
                         zexcel.MAC_COL + 1,
                         test.mac,
                         style=zexcel.set_style(zexcel.BLACK,
                                                260,
                                                bold=True,
                                                align='',
                                                pattern_color='light_orange'))
    excel.sheet_fd.write(zexcel.DATE_ROW,
                         zexcel.DATE_COL + 1,
                         test.date,
                         style=zexcel.set_style(zexcel.BLACK,
                                                260,
                                                bold=True,
                                                align='',
                                                pattern_color='light_orange'))

    filename = os.path.join(
        os.path.dirname(__file__) + "./../results/" + test.output_file +
        ".xls")
    excel.excel_fd.save(filename)  # 保存xls

    # 从第二行开始写入
    excel.row_point = 1
コード例 #9
0
def test_top_write(module_name):
    excel.row_point += 1
    excel.sheet_fd.write(excel.row_point, zexcel.CASE_NAME_COL, module_name.capitalize() + "TestCase",
                         style=zexcel.set_style(zexcel.BLACK, 280, bold=False, align='', pattern_color='sky_blue'))
    excel.module_info[module_name] = {}
    excel.module_info[module_name]["row"] = excel.row_point
    excel.module_info[module_name]["count"] = 0
    excel.module_info[module_name]["pass"] = 0
    excel.module_info[module_name]["fail"] = 0
コード例 #10
0
def test_end():
    # 将统计的count pass fail写入excel
    test.total_num = test.pass_num + test.fail_num
    for key in excel.module_info:
        excel.sheet_fd.write(excel.module_info[key]["row"],
                             zexcel.COUNT_COL,
                             excel.module_info[key]["count"],
                             style=zexcel.set_style(zexcel.RED,
                                                    240,
                                                    bold=False,
                                                    align=''))
        excel.sheet_fd.write(excel.module_info[key]["row"],
                             zexcel.PASS_COL,
                             excel.module_info[key]["pass"],
                             style=zexcel.set_style(zexcel.RED,
                                                    240,
                                                    bold=False,
                                                    align=''))
        excel.sheet_fd.write(excel.module_info[key]["row"],
                             zexcel.FAIL_COL,
                             excel.module_info[key]["fail"],
                             style=zexcel.set_style(zexcel.RED,
                                                    240,
                                                    bold=False,
                                                    align=''))

    excel.sheet_fd.write(zexcel.TOTAL_ROW,
                         zexcel.TOTAL_COL + 1,
                         test.total_num,
                         style=zexcel.set_style(zexcel.BLACK,
                                                260,
                                                bold=True,
                                                align='',
                                                pattern_color='light_orange'))
    excel.sheet_fd.write(zexcel.TOTAL_PASS_ROW,
                         zexcel.TOTAL_PASS_COL + 1,
                         test.pass_num,
                         style=zexcel.set_style(zexcel.BLACK,
                                                260,
                                                bold=True,
                                                align='',
                                                pattern_color='light_orange'))
    excel.sheet_fd.write(zexcel.TOTAL_FAIL_ROW,
                         zexcel.TOTAL_FAIL_COL + 1,
                         test.fail_num,
                         style=zexcel.set_style(zexcel.BLACK,
                                                260,
                                                bold=True,
                                                align='',
                                                pattern_color='light_orange'))

    filename = os.path.join(
        os.path.dirname(__file__) + "./../results/" + test.output_file +
        ".xls")
    excel.excel_fd.save(filename)  # 保存xls
    logging.info("test end!")
    exit()
コード例 #11
0
def excel_init(module_name):
    excel.excel_fd = zexcel.excel_init()
    sheet_name = module_name + "测试结果"
    excel.sheet_fd = zexcel.common_sheet_init(excel.excel_fd, sheet_name)

    # 从第二行开始写入
    excel.row_point = 1
    rows = ['', 'Result', 'Version', 'Count']
    for index, val in enumerate(rows):
        excel.sheet_fd.write(1,
                             index,
                             val,
                             style=zexcel.set_style(zexcel.BLACK,
                                                    280,
                                                    bold=True,
                                                    pattern_color='gray25'))

    filename = os.path.join(
        os.path.dirname(__file__) + "./../results/" + test.output_file +
        ".xls")
    excel.excel_fd.save(filename)  # 保存xls

    # 从第二行开始写入
    excel.row_point = 1
コード例 #12
0
ファイル: control_stress.py プロジェクト: creatorly/zunittest
def run_test_case(module_name, count_max):
    # 写excel表,test case的头部
    test_top_write(module_name)
    test_count = 0

    while test_count <= count_max:
        test_count += 1
        for key in server.input_dict:
            # 填写测试名称到excel的第一列
            excel.row_point += 1
            excel.sheet_fd.write(excel.row_point,
                                 zexcel.CASE_NAME_COL,
                                 key,
                                 style=zexcel.set_style(zexcel.BLACK,
                                                        240,
                                                        bold=False,
                                                        align=''))
            excel.module_info[module_name]["count"] += 1

            # 一个case里面可能会有多个请求
            request_i = 0
            request_result = True
            net_result = True
            while request_i < len(server.input_dict[key]):
                try:
                    # 有url,说明要访问tlink
                    if server.input_dict[key][request_i].__contains__("url"):
                        request_url = server.host + server.input_dict[key][
                            request_i]["url"]
                        request_head = {'content-type': 'application/json'}
                        request_data = {}
                        # 有head说明需要设置头部
                        if server.input_dict[key][request_i].__contains__("head_1") and \
                                server.input_dict[key][request_i].__contains__("head_2"):
                            request_head = {
                                server.input_dict[key][request_i]["head_1"]:
                                server.input_dict[key][request_i]["head_2"],
                                'content-type':
                                'application/json'
                            }

                        # 控制事件
                        if server.input_dict[key][request_i].__contains__(
                                "control"):
                            server.wait_time = 5
                            request_data = server.input_dict[key][request_i][
                                "control"]
                            server.sno = str(uuid.uuid1())
                            request_data["sno"] = server.sno
                        # 控制相应事件(前提要有控制,否则sno会错误)
                        elif server.input_dict[key][request_i].__contains__(
                                "control_resp"):
                            server.wait_time = 1
                            request_data = server.input_dict[key][request_i][
                                "control_resp"]
                            request_data["sno"] = server.sno
                        else:
                            server.wait_time = 1

                        logging.info("request_url:%s", request_url)
                        logging.info("%s send:%s", key, request_data)

                        resp_data = requests.post(
                            request_url,
                            data=json.dumps(request_data),
                            headers=request_head,
                            timeout=5)
                        logging.info("%s recv:%s", key, resp_data.text)
                        if resp_data.status_code == 200:
                            msg = json.loads(resp_data.text)
                            if msg["code"] == 200:
                                # 全部相等
                                if server.output_dict[key][
                                        request_i].__contains__("total_same"):
                                    if msg != server.output_dict[key][
                                            request_i]["total_same"]:
                                        request_result = False
                                # 部分相等
                                elif server.output_dict[key][
                                        request_i].__contains__("part_same"):
                                    if not comp_json_value(
                                            msg, server.output_dict[key]
                                        [request_i]["part_same"]):
                                        request_result = False
                            else:
                                net_result = False
                        else:
                            net_result = False

                    else:
                        server.wait_time = 1

                except Exception as e:
                    logging.info("---异常---:", e)
                    request_result = False
                    net_result = False

                request_i += 1
                time.sleep(server.wait_time)

            # 填写测试结果到excel的第二列
            if net_result:
                if request_result:
                    logging.info("%s: pass", key)
                    excel.sheet_fd.write(excel.row_point,
                                         zexcel.CASE_RESULT_COL,
                                         "pass",
                                         style=zexcel.set_style(zexcel.GREEN,
                                                                240,
                                                                bold=False,
                                                                align=''))
                    excel.module_info[module_name]["pass"] += 1
                    test.pass_num += 1
                else:
                    logging.info("%s: fail", key)
                    excel.sheet_fd.write(excel.row_point,
                                         zexcel.CASE_RESULT_COL,
                                         "fail",
                                         style=zexcel.set_style(zexcel.RED,
                                                                240,
                                                                bold=False,
                                                                align=''))
                    excel.module_info[module_name]["fail"] += 1
                    test.fail_num += 1
            else:
                logging.info("%s: fail", key)
                excel.sheet_fd.write(excel.row_point,
                                     zexcel.CASE_RESULT_COL,
                                     "net fail",
                                     style=zexcel.set_style(zexcel.RED,
                                                            240,
                                                            bold=False,
                                                            align=''))
                excel.module_info[module_name]["fail"] += 1
                test.fail_num += 1

            filename = os.path.join(
                os.path.dirname(__file__) + "/../results/" + test.output_file +
                ".xls")
            excel.excel_fd.save(filename)  # 保存xls

    return True
コード例 #13
0
def run_test_case(module_name, count_max):
    # 写excel表,test case的头部
    test_top_write(module_name)
    test_count = 1
    request_data = {
        "ver": "v1",
        "sid": "00000000000000000000000000000000",
        "method": "api",
        "param": {
            "msg_id": 11111,
            "params": [{
                "module": "system",
                "api": "restart"
            }]
        }
    }

    while test_count <= count_max:
        # 填写测试次数
        excel.row_point += 1
        excel.sheet_fd.write(excel.row_point,
                             CASE_COUNT_COL,
                             test_count,
                             style=zexcel.set_style(zexcel.BLACK,
                                                    240,
                                                    bold=False,
                                                    align=''))
        excel.module_info[module_name]["count"] += 1

        server.sid = utils_login.get_sid(server.url, server.headers,
                                         server.password)
        if not server.sid:
            logging.error("login fail")
            test_end()

        wan_result = False
        wifi_result = False
        try:
            logging.info("send:%s", request_data)
            request_data["sid"] = server.sid
            resp_data = requests.post(server.url,
                                      data=json.dumps(request_data),
                                      headers=server.headers)
            logging.info("recv:%s", resp_data.text)
            if resp_data.status_code == 200:
                msg = json.loads(resp_data.text)
                if msg["errcode"] == 0:
                    i = 0
                    while i < test.timeout:
                        i += 1
                        logging.info("ping count %s", i)
                        time.sleep(2)
                        wan_result = requests_internet()
                        if wan_result:
                            break

                    i = 0
                    while i < test.timeout:
                        i += 1
                        logging.info("wifi connect count %s", i)
                        time.sleep(2)
                        wan_result = requests_internet()
                        if wan_result:
                            break

        except Exception as e:
            logging.info("---异常---:", e)

        if wan_result:
            logging.info("count %s pass", test_count)
            test.pass_num += 1
            excel.sheet_fd.write(excel.row_point,
                                 CASE_ETH_COL,
                                 "pass",
                                 style=zexcel.set_style(zexcel.GREEN,
                                                        240,
                                                        bold=False,
                                                        align=''))
            excel.module_info[module_name]["pass"] += 1
        else:
            logging.info("fail")
            break

        test_count += 1
        time.sleep(2)

        filename = os.path.join(
            os.path.dirname(__file__) + "./../results/" + test.output_file +
            ".xls")
        excel.excel_fd.save(filename)  # 保存xls

    return True
コード例 #14
0
def excel_init(module_name):
    if excel_type == "xlsx":
        filename = os.path.join(
            os.path.dirname(__file__) + "/../results/" + test.output_file +
            ".xlsx")
        excel.excel_fd = xlsxwriter.Workbook(filename)

        sheet_name = module_name + "测试结果"

        excel.sheet_fd = excel.excel_fd.add_worksheet(sheet_name)  # 增加sheet
        excel.sheet_fd.set_column(0, 3, 10)

    elif excel_type == "xls":
        sheet_name = module_name + "测试结果"
        excel.excel_fd = zexcel.excel_init()
        excel.sheet_fd = excel.excel_fd.add_sheet(sheet_name)  # 增加sheet
        excel.sheet_fd.col(zexcel.CASE_NAME_COL).width = 200 * 15  # 设置第1列列宽
        excel.sheet_fd.col(zexcel.CASE_RESULT_COL).width = 200 * 15  # 设置第2列列宽
        excel.sheet_fd.col(zexcel.COUNT_COL).width = 200 * 15  # 设置第3列列宽
        excel.sheet_fd.col(zexcel.PASS_COL).width = 200 * 15  # 设置第4列列宽
        excel.sheet_fd.col(zexcel.FAIL_COL).width = 200 * 15  # 设置第5列列宽
        excel.sheet_fd.col(zexcel.PROJECT_COL).width = 180 * 15  # 设置第7列列宽
        excel.sheet_fd.col(zexcel.PROJECT_COL + 1).width = 360 * 15  # 设置第8列列宽

        # 写第一行数据
        excel.sheet_fd.write_merge(0, 0, 0, 4, sheet_name,
                                   zexcel.set_style(0x7FFF, 320, bold=True))

        excel.sheet_fd.write(zexcel.PROJECT_ROW,
                             zexcel.PROJECT_COL,
                             "project:",
                             style=zexcel.set_style(
                                 zexcel.BLACK,
                                 260,
                                 bold=True,
                                 align='',
                                 pattern_color='light_orange'))
        excel.sheet_fd.write(zexcel.VERSION_ROW,
                             zexcel.VERSION_COL,
                             "version:",
                             style=zexcel.set_style(
                                 zexcel.BLACK,
                                 260,
                                 bold=True,
                                 align='',
                                 pattern_color='light_orange'))
        excel.sheet_fd.write(zexcel.MAC_ROW,
                             zexcel.MAC_COL,
                             "mac:",
                             style=zexcel.set_style(
                                 zexcel.BLACK,
                                 260,
                                 bold=True,
                                 align='',
                                 pattern_color='light_orange'))
        excel.sheet_fd.write(zexcel.DATE_ROW,
                             zexcel.DATE_COL,
                             "date:",
                             style=zexcel.set_style(
                                 zexcel.BLACK,
                                 260,
                                 bold=True,
                                 align='',
                                 pattern_color='light_orange'))

        # 写设备信息
        excel.sheet_fd.write(zexcel.PROJECT_ROW,
                             zexcel.PROJECT_COL + 1,
                             test.project,
                             style=zexcel.set_style(
                                 zexcel.BLACK,
                                 260,
                                 bold=True,
                                 align='',
                                 pattern_color='light_orange'))
        excel.sheet_fd.write(zexcel.VERSION_ROW,
                             zexcel.VERSION_COL + 1,
                             test.version,
                             style=zexcel.set_style(
                                 zexcel.BLACK,
                                 260,
                                 bold=True,
                                 align='',
                                 pattern_color='light_orange'))
        excel.sheet_fd.write(zexcel.MAC_ROW,
                             zexcel.MAC_COL + 1,
                             test.mac,
                             style=zexcel.set_style(
                                 zexcel.BLACK,
                                 260,
                                 bold=True,
                                 align='',
                                 pattern_color='light_orange'))
        excel.sheet_fd.write(zexcel.DATE_ROW,
                             zexcel.DATE_COL + 1,
                             test.date,
                             style=zexcel.set_style(
                                 zexcel.BLACK,
                                 260,
                                 bold=True,
                                 align='',
                                 pattern_color='light_orange'))

        filename = os.path.join(
            os.path.dirname(__file__) + "/../results/" + test.output_file +
            ".xls")
        excel.excel_fd.save(filename)  # 保存xls

    # 从第二行开始写入
    excel.row_point = 1
コード例 #15
0
def run_test_case(module_name):
    # 写excel表,test case的头部
    test_top_write(module_name)

    for key in server.input_dict:
        # 填写测试名称到excel的第一列
        excel.row_point += 1
        excel.sheet_fd.write(excel.row_point,
                             zexcel.CASE_NAME_COL,
                             key,
                             style=zexcel.set_style(zexcel.BLACK,
                                                    240,
                                                    bold=False,
                                                    align=''))
        excel.module_info[module_name]["count"] += 1

        # 一个case里面可能会有多个请求
        request_i = 0
        request_result = True
        while request_i < len(server.input_dict[key]):
            try:
                request_data = server.input_dict[key][request_i]
                request_data["sid"] = server.sid
                logging.info("%s send:%s", key, request_data)
                resp_data = requests.post(server.url,
                                          data=json.dumps(request_data),
                                          headers=server.headers,
                                          timeout=5)
                logging.info("%s recv:%s", key, resp_data.text)
                if resp_data.status_code == 200:
                    logging.info("%s src:%s", key,
                                 server.output_dict[key][request_i])
                    msg = json.loads(resp_data.text)

                    if test.name == "static":
                        # 判断返回的数据与output_json里面的数据是否一致
                        if msg != server.output_dict[key][request_i]:
                            request_result = False
                    elif test.name == "dynamic":
                        # 判断返回的数据与output_json里面的是结构是否一致
                        if not comp_json_key(
                                msg, server.output_dict[key][request_i]):
                            request_result = False

            except Exception as e:
                logging.info("---异常---:", e)
                request_result = False

            request_i += 1
            time.sleep(1)

        # 填写测试结果到excel的第二列
        if request_result:
            logging.info("pass")
            excel.sheet_fd.write(excel.row_point,
                                 zexcel.CASE_RESULT_COL,
                                 "pass",
                                 style=zexcel.set_style(zexcel.GREEN,
                                                        240,
                                                        bold=False,
                                                        align=''))
            excel.module_info[module_name]["pass"] += 1
            test.pass_num += 1
        else:
            logging.info("fail")
            excel.sheet_fd.write(excel.row_point,
                                 zexcel.CASE_RESULT_COL,
                                 "fail",
                                 style=zexcel.set_style(zexcel.RED,
                                                        240,
                                                        bold=False,
                                                        align=''))
            excel.module_info[module_name]["fail"] += 1
            test.fail_num += 1

        filename = os.path.join(
            os.path.dirname(__file__) + "./../results/" + test.output_file +
            ".xls")
        excel.excel_fd.save(filename)  # 保存xls

    return True
コード例 #16
0
ファイル: wifi_stress.py プロジェクト: creatorly/zunittest
def run_test_case(module_name, count_max):
    # 写excel表,test case的头部
    test_top_write("2.4G")
    test_top_write("5G")
    test_count = 0

    while test_count <= count_max:
        test_count += 1
        for key in server.input_dict:
            # 填写测试名称到excel的第一列
            excel.row_point += 1
            excel.sheet_fd.write(excel.row_point, zexcel.CASE_NAME_COL, test_count,
                                 style=zexcel.set_style(zexcel.BLACK, 240, bold=False, align=''))
            excel.module_info["2.4G"]["count"] += 1
            excel.module_info["5G"]["count"] += 1

            # 一个case里面可能会有多个请求
            request_i = 0
            request_result = True
            test_module = "2.4G"
            while request_i < len(server.input_dict[key]):
                try:
                    if server.input_dict[key][request_i].__contains__("method"):   # api设置接口
                        request_data = server.input_dict[key][request_i]
                        request_data["sid"] = server.sid
                        logging.info("%s send:%s", key, request_data)
                        resp_data = requests.post(server.url, data=json.dumps(request_data), headers=server.headers, timeout=5)
                        logging.info("%s recv:%s", key, resp_data.text)
                        if resp_data.status_code == 200:
                            msg = json.loads(resp_data.text)
                            # 判断返回的数据与output_json里面的数据是否一致
                            if msg != server.output_dict[key][request_i]:
                                request_result = False
                    else:   # wifi连接
                        wifi_info = server.input_dict[key][request_i]
                        if wifi_info.__contains__("w2"):
                            test_module = "2.4G"
                            if not utils_wifi.start_connect_wifi(wifi_info["w2"]):
                                request_result = False
                            else:
                                if not requests_zrouter():
                                    request_result = False

                        if wifi_info.__contains__("w5"):
                            test_module = "5G"
                            if not utils_wifi.start_connect_wifi(wifi_info["w5"]):
                                request_result = False
                            else:
                                if not requests_zrouter():
                                    request_result = False

                except Exception as e:
                    logging.info("---异常---:", e)
                    request_result = False

                request_i += 1
                time.sleep(2)

            # 填写测试结果到excel的第二列
            if request_result:
                logging.info("pass")
                excel.sheet_fd.write(excel.row_point, zexcel.CASE_RESULT_COL, "pass",
                                     style=zexcel.set_style(zexcel.GREEN, 240, bold=False, align=''))
                if test_module == "2.4G":
                    excel.module_info["2.4G"]["pass"] += 1
                elif test_module == "5G":
                    excel.module_info["5G"]["pass"] += 1
                test.pass_num += 1
            else:
                logging.info("fail")
                excel.sheet_fd.write(excel.row_point, zexcel.CASE_RESULT_COL, "fail",
                                     style=zexcel.set_style(zexcel.RED, 240, bold=False, align=''))
                if test_module == "2.4G":
                    excel.module_info["2.4G"]["fail"] += 1
                elif test_module == "5G":
                    excel.module_info["5G"]["fail"] += 1
                test.fail_num += 1

            filename = os.path.join(os.path.dirname(__file__) + "./../results/" + test.output_file + ".xls")
            excel.excel_fd.save(filename)  # 保存xls

        logging.info("2.4G pass: %d", excel.module_info["2.4G"]["pass"])
        logging.info("2.4G fail: %d", excel.module_info["2.4G"]["fail"])
        logging.info("2.4G total: %d", test_count)

        logging.info("5G pass: %d", excel.module_info["5G"]["pass"])
        logging.info("5G fail: %d", excel.module_info["5G"]["fail"])
        logging.info("5G total: %d", test_count)

    return True
コード例 #17
0
def run_test_case(module_name, count_max):
    # 写excel表,test case的头部
    test_top_write(module_name)

    test_count = 1
    while test_count <= count_max:
        for key in server.input_dict:
            # 填写测试名称到excel的第一列
            excel.row_point += 1
            excel.sheet_fd.write(excel.row_point,
                                 zexcel.CASE_NAME_COL,
                                 key,
                                 style=zexcel.set_style(zexcel.BLACK,
                                                        240,
                                                        bold=False,
                                                        align=''))
            excel.module_info[module_name]["count"] += 1

            # 一个case里面可能会有多个请求
            request_i = 0
            request_result = True
            while request_i < len(server.input_dict[key]):
                try:
                    # 有url,说明要访问tlink
                    if server.input_dict[key][request_i].__contains__("url") and \
                            server.input_dict[key][request_i].__contains__("control"):
                        request_url = server.url + server.input_dict[key][
                            request_i]["url"]
                        request_head = {'content-type': 'application/json'}
                        request_data = server.input_dict[key][request_i][
                            "control"]

                        logging.info("%s send:%s", key, request_data)
                        resp_data = requests.post(
                            request_url,
                            data=json.dumps(request_data),
                            headers=request_head,
                            timeout=5)
                        logging.info("%s recv:%s", key, resp_data.text)
                        if resp_data.status_code == 200:
                            msg = json.loads(resp_data.text)
                            # 全部相等
                            if msg != server.output_dict[key][request_i]:
                                request_result = False

                    elif server.input_dict[key][request_i].__contains__("url") and \
                            server.input_dict[key][request_i].__contains__("query"):
                        i = 0
                        while i < int(test.ota_timeout):
                            request_url = server.url + server.input_dict[key][
                                request_i]["url"]
                            request_head = {'content-type': 'application/json'}
                            request_data = server.input_dict[key][request_i][
                                "query"]

                            logging.info("count %d %s send:%s", i, key,
                                         request_data)
                            resp_data = requests.post(
                                request_url,
                                data=json.dumps(request_data),
                                headers=request_head,
                                timeout=5)
                            logging.info("%s recv:%s", key, resp_data.text)
                            if resp_data.status_code == 200:
                                msg = json.loads(resp_data.text)
                                if not comp_json_value(
                                        msg,
                                        server.output_dict[key][request_i]):
                                    request_result = False
                                else:
                                    excel.sheet_fd.write(
                                        excel.row_point,
                                        OTA_VERSION_COL,
                                        server.output_dict[key][request_i]
                                        ["data"]["version"],
                                        style=zexcel.set_style(zexcel.GREEN,
                                                               240,
                                                               bold=False,
                                                               align=''))
                                    request_result = True
                                    break

                            i += 1
                            time.sleep(1)

                    else:
                        server.wait_time = 1

                except Exception as e:
                    logging.info("---异常---:", e)
                    request_result = False

                request_i += 1
                time.sleep(server.wait_time)

            # 填写测试结果到excel的第二列
            if request_result:
                logging.info("%s: pass", key)
                excel.sheet_fd.write(excel.row_point,
                                     OTA_RESULT_COL,
                                     "pass",
                                     style=zexcel.set_style(zexcel.GREEN,
                                                            240,
                                                            bold=False,
                                                            align=''))
                excel.module_info[module_name]["pass"] += 1
                test.pass_num += 1
            else:
                logging.info("%s: fail", key)
                excel.sheet_fd.write(excel.row_point,
                                     OTA_RESULT_COL,
                                     "fail",
                                     style=zexcel.set_style(zexcel.RED,
                                                            240,
                                                            bold=False,
                                                            align=''))
                excel.module_info[module_name]["fail"] += 1
                test.fail_num += 1
                test_end()

        excel.row_point += 1
        excel.sheet_fd.write(excel.row_point,
                             OTA_COUNT_COL,
                             test_count,
                             style=zexcel.set_style(zexcel.BLACK,
                                                    240,
                                                    bold=False,
                                                    align=''))

        test_count += 1
        time.sleep(2)

        filename = os.path.join(
            os.path.dirname(__file__) + "./../results/" + test.output_file +
            ".xls")
        excel.excel_fd.save(filename)  # 保存xls

    return True
コード例 #18
0
def run_test_case(module_name):
    # 写excel表,test case的头部
    test_top_write(module_name)
    for key in server.input_dict:
        # 填写测试名称到excel的第一列
        excel.row_point += 1
        excel.sheet_fd.write(excel.row_point, zexcel.CASE_NAME_COL, key,
                             style=zexcel.set_style(zexcel.BLACK, 240, bold=False, align=''))
        excel.module_info[module_name]["count"] += 1

        # 一个case里面可能会有多个请求
        request_i = 0
        request_result = True
        while request_i < len(server.input_dict[key]):
            try:
                # 有url,说明要访问tlink
                if server.input_dict[key][request_i].__contains__("url"):
                    request_url = server.url + server.input_dict[key][request_i]["url"]
                    request_head = {'content-type': 'application/json'}
                    request_data = {}
                    # 有head说明需要设置头部
                    if server.input_dict[key][request_i].__contains__("head_1") and \
                            server.input_dict[key][request_i].__contains__("head_2"):
                        request_head = {
                            server.input_dict[key][request_i]["head_1"]: server.input_dict[key][request_i]["head_2"],
                            'content-type': 'application/json'}

                    # 请求事件
                    if server.input_dict[key][request_i].__contains__("query"):
                        server.wait_time = 1
                        request_data = server.input_dict[key][request_i]["query"]
                    else:
                        server.wait_time = 1

                    logging.info("%s send:%s", key, request_data)
                    resp_data = requests.post(request_url, data=json.dumps(request_data), headers=request_head, timeout=5)
                    logging.info("%s recv:%s", key, resp_data.text)
                    if resp_data.status_code == 200:
                        msg = json.loads(resp_data.text)
                        # 全部相等
                        if server.output_dict[key][request_i].__contains__("total_same"):
                            if msg != server.output_dict[key][request_i]["total_same"]:
                                request_result = False
                        # 部分相等
                        elif server.output_dict[key][request_i].__contains__("part_same"):
                            if not comp_json_value(msg, server.output_dict[key][request_i]["part_same"]):
                                request_result = False

                elif server.input_dict[key][request_i].__contains__("wifi_connect"):
                    if not utils_wifi.start_connect_wifi(server.input_dict[key][request_i]["wifi_connect"]):
                        request_result = False
                elif server.input_dict[key][request_i].__contains__("check_ssh_on"):
                    if not start_connect_ssh(server.input_dict[key][request_i]["check_ssh_on"]):
                        request_result = False
                elif server.input_dict[key][request_i].__contains__("check_ssh_off"):
                    if start_connect_ssh(server.input_dict[key][request_i]["check_ssh_off"]):
                        request_result = False
                elif server.input_dict[key][request_i].__contains__("zgateway_mqtt_connect"):
                    server.wait_time = 3
                    if not start_connect_zgteway_mqtt(server.input_dict[key][request_i]["zgateway_mqtt_connect"]):
                        request_result = False
                elif server.input_dict[key][request_i].__contains__("zgateway_mqtt_control"):
                    if not mqttClient.control_response:
                        request_result = False
                elif server.input_dict[key][request_i].__contains__("restart_zgateway"):
                    if not restart_zgateway(server.input_dict[key][request_i]["restart_zgateway"]):
                        request_result = False
                    else:
                        mqttClient.broadcast_response = False
                        server.wait_time = 15
                elif server.input_dict[key][request_i].__contains__("check_broadcast"):
                    server.wait_time = 1
                    if not mqttClient.broadcast_response:
                        request_result = False
                elif server.input_dict[key][request_i].__contains__("zgateway_mqtt_disconnect"):
                    mqttClient.stop = True
                    server.wait_time = 5
                elif server.input_dict[key][request_i].__contains__("open_remote_ssh"):
                    if not open_remote_ssh(server.input_dict[key][request_i]["open_remote_ssh"]):
                        server.wait_time = 3
                        request_result = False
                elif server.input_dict[key][request_i].__contains__("close_remote_ssh"):
                    if not close_remote_ssh(server.input_dict[key][request_i]["close_remote_ssh"]):
                        server.wait_time = 3
                        request_result = False

                else:
                    server.wait_time = 1

            except Exception as e:
                logging.info("---异常---:", e)
                request_result = False

            request_i += 1
            time.sleep(server.wait_time)

        # 填写测试结果到excel的第二列
        if request_result:
            logging.info("%s: pass", key)
            excel.sheet_fd.write(excel.row_point, zexcel.CASE_RESULT_COL, "pass",
                                 style=zexcel.set_style(zexcel.GREEN, 240, bold=False, align=''))
            excel.module_info[module_name]["pass"] += 1
            test.pass_num += 1
        else:
            logging.info("%s: fail", key)
            excel.sheet_fd.write(excel.row_point, zexcel.CASE_RESULT_COL, "fail",
                                 style=zexcel.set_style(zexcel.RED, 240, bold=False, align=''))
            excel.module_info[module_name]["fail"] += 1
            test.fail_num += 1

        filename = os.path.join(os.path.dirname(__file__) + "/../results/" + test.output_file + ".xls")
        excel.excel_fd.save(filename)  # 保存xls
    return True
コード例 #19
0
ファイル: soft_recovery.py プロジェクト: creatorly/zunittest
def run_test_case(module_name, count_max):
    # 写excel表,test case的头部
    test_top_write(module_name)

    test_count = 1
    while test_count <= count_max:
        server.sid = utils_login.get_sid(server.url, server.headers, server.password)
        if not server.sid:
            logging.error("login fail")
            test_end()

        for key in server.input_dict:
            # 填写测试名称到excel的第一列
            excel.row_point += 1
            excel.sheet_fd.write(excel.row_point, zexcel.CASE_NAME_COL, key,
                                 style=zexcel.set_style(zexcel.BLACK, 240, bold=False, align=''))
            excel.module_info[module_name]["count"] += 1

            # 一个case里面可能会有多个请求
            request_i = 0
            request_result = True
            while request_i < len(server.input_dict[key]):
                try:
                    request_data = server.input_dict[key][request_i]
                    request_data["sid"] = server.sid
                    logging.info("%s send:%s", key, request_data)
                    resp_data = requests.post(server.url, data=json.dumps(request_data), headers=server.headers, timeout=5)
                    logging.info("%s recv:%s", key, resp_data.text)
                    if resp_data.status_code == 200:
                        logging.info("%s src:%s", key, server.output_dict[key][request_i])
                        msg = json.loads(resp_data.text)

                        # 判断返回的数据与output_json里面的数据是否一致
                        if msg != server.output_dict[key][request_i]:
                            request_result = False

                except Exception as e:
                    logging.info("---异常---:", e)
                    request_result = False

                request_i += 1
                time.sleep(1)

            # 填写测试结果到excel的第二列
            if request_result:
                logging.info("pass")
                excel.sheet_fd.write(excel.row_point, zexcel.CASE_RESULT_COL, "pass",
                                     style=zexcel.set_style(zexcel.GREEN, 240, bold=False, align=''))
                excel.module_info[module_name]["pass"] += 1
                test.pass_num += 1
            else:
                logging.info("fail")
                excel.sheet_fd.write(excel.row_point, zexcel.CASE_RESULT_COL, "fail",
                                     style=zexcel.set_style(zexcel.RED, 240, bold=False, align=''))
                excel.module_info[module_name]["fail"] += 1
                test.fail_num += 1

        # 填写测试次数
        excel.row_point += 1
        excel.sheet_fd.write(excel.row_point, CASE_COUNT_COL, test_count,
                             style=zexcel.set_style(zexcel.BLACK, 240, bold=False, align=''))
        excel.module_info[module_name]["count"] += 1

        wan_result = False
        i = 0
        while i < test.timeout:
            i += 1
            logging.info("ping count %s", i)
            time.sleep(2)
            wan_result = requests_internet()
            if wan_result:
                break

        if wan_result:
            logging.info("count %s pass", test_count)
            test.pass_num += 1
            excel.sheet_fd.write(excel.row_point, CASE_ETH_COL, "pass",
                                 style=zexcel.set_style(zexcel.GREEN, 240, bold=False, align=''))
            excel.module_info[module_name]["pass"] += 1
        else:
            logging.info("fail")
            break

        test_count += 1
        time.sleep(2)

        filename = os.path.join(os.path.dirname(__file__) + "./../results/" + test.output_file + ".xls")
        excel.excel_fd.save(filename)  # 保存xls

    return True