Update code for test log (#5645)

* [skip ci] Update test code

Signed-off-by: wangting0128 <ting.wang@zilliz.com>

* [skip ci] Update code for test log

Signed-off-by: wangting0128 <ting.wang@zilliz.com>
pull/5648/head^2
紫晴 2021-06-07 15:21:36 +08:00 committed by GitHub
parent 7d9d524539
commit 06edb1d67f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 77 additions and 116 deletions

View File

@ -1,5 +1,6 @@
from utils.util_log import test_log as log
from common.common_type import *
from common.code_mapping import ErrorCode, ErrorMessage
from pymilvus_orm import Collection, Partition
from utils.api_request import Error
@ -28,8 +29,8 @@ class ResponseChecker:
elif self.check_task == CheckTasks.err_res:
result = self.assert_exception(self.response, self.succ, self.kwargs_dict)
elif self.check_task == CheckTasks.check_list_count and self.check_params is not None:
result = self.check_list_count(self.response, self.func_name, self.check_params)
elif self.check_task == CheckTasks.check_list_count and self.check_items is not None:
result = self.check_list_count(self.response, self.func_name, self.check_items)
elif self.check_task == CheckTasks.check_collection_property:
result = self.check_collection_property(self.response, self.func_name, self.kwargs_dict)
@ -51,8 +52,9 @@ class ResponseChecker:
assert actual is False
assert len(error_dict) > 0
if isinstance(res, Error):
assert res.code == error_dict["err_code"] \
or error_dict["err_msg"] in res.message
err_code = error_dict["err_code"]
assert res.code == err_code or ErrorMessage[err_code] in res.message
# assert res.code == error_dict["err_code"] or error_dict["err_msg"] in res.message
else:
log.error("[CheckFunc] Response of API is not an error: %s" % str(res))
assert False

View File

@ -0,0 +1,10 @@
from enum import Enum
class ErrorCode(Enum):
ErrorOk = 0
Error = 1
ErrorMessage = {ErrorCode.ErrorOk: "",
ErrorCode.Error: "is illegal"}

View File

@ -187,38 +187,54 @@ def jaccard(x, y):
y = np.asarray(y, np.bool)
return 1 - np.double(np.bitwise_and(x, y).sum()) / np.double(np.bitwise_or(x, y).sum())
def hamming(x, y):
x = np.asarray(x, np.bool)
y = np.asarray(y, np.bool)
return np.bitwise_xor(x, y).sum()
def tanimoto(x, y):
x = np.asarray(x, np.bool)
y = np.asarray(y, np.bool)
return -np.log2(np.double(np.bitwise_and(x, y).sum()) / np.double(np.bitwise_or(x, y).sum()))
def substructure(x, y):
x = np.asarray(x, np.bool)
y = np.asarray(y, np.bool)
return 1 - np.double(np.bitwise_and(x, y).sum()) / np.count_nonzero(y)
def superstructure(x, y):
x = np.asarray(x, np.bool)
y = np.asarray(y, np.bool)
return 1 - np.double(np.bitwise_and(x, y).sum()) / np.count_nonzero(x)
def modify_file(file_name_list, input_content=""):
if not isinstance(file_name_list, list):
def modify_file(file_path_list, is_modify=False, input_content=""):
"""
file_path_list : file list -> list[<file_path>]
is_modify : does the file need to be reset
input_content the content that need to insert to the file
"""
if not isinstance(file_path_list, list):
log.error("[modify_file] file is not a list.")
for file_name in file_name_list:
if not os.path.isfile(file_name):
log.error("[modify_file] file(%s) is not exist." % file_name)
for file_path in file_path_list:
folder_path, file_name = os.path.split(file_path)
if not os.path.isdir(folder_path):
log.debug("[modify_file] folder(%s) is not exist." % folder_path)
os.makedirs(folder_path)
with open(file_name, "r+") as f:
f.seek(0)
f.truncate()
f.write(input_content)
f.close()
log.info("[modify_file] File(%s) modification is complete." % file_name_list)
if not os.path.isfile(file_path):
log.error("[modify_file] file(%s) is not exist." % file_path)
else:
if is_modify is True:
log.debug("[modify_file] start modifying file(%s)..." % file_path)
with open(file_path, "r+") as f:
f.seek(0)
f.truncate()
f.write(input_content)
f.close()
log.info("[modify_file] File(%s) modification is complete." % file_path_list)

View File

@ -1,17 +1,27 @@
import json
import os
class TestInfo:
def __init__(self):
self.get_default_config()
@staticmethod
def get_env_variable(var="CI_LOG_PATH"):
""" get log path of testing """
try:
log_path = os.environ[var]
return str(log_path)
except Exception as e:
log_path = "/tmp/log"
print("Failed to get environment variables : %s, Use default path : %s" % (str(e), log_path))
return log_path
def get_default_config(self):
""" Make sure the path exists """
self.home_dir = "/tmp/"
self.log_dir = self.home_dir + "log/"
self.log_debug = "%s/refactor_test.debug" % self.log_dir
self.log_info = "%s/refactor_test.log" % self.log_dir
self.log_err = "%s/refactor_test.err" % self.log_dir
self.log_dir = self.get_env_variable()
self.log_debug = "%s/ci_test_log.debug" % self.log_dir
self.log_info = "%s/ci_test_log.log" % self.log_dir
self.log_err = "%s/ci_test_log.err" % self.log_dir
test_info = TestInfo()

View File

@ -10,12 +10,13 @@ def pytest_addoption(parser):
parser.addoption("--handler", action="store", default="GRPC", help="handler of request")
parser.addoption("--tag", action="store", default="all", help="only run tests matching the tag.")
parser.addoption('--dry_run', action='store_true', default=False, help="")
parser.addoption('--partition_name', action='store_true', default="partition_name", help="name of partition")
parser.addoption('--descriptions', action='store_true', default="partition_des", help="descriptions of partition")
parser.addoption('--collection_name', action='store_true', default="collection_name", help="name of collection")
parser.addoption('--search_vectors', action='store_true', default="search_vectors", help="vectors of search")
parser.addoption('--index_param', action='store_true', default="index_param", help="index_param of index")
parser.addoption('--data', action='store_true', default="data", help="data of request")
parser.addoption('--partition_name', action='store', default="partition_name", help="name of partition")
parser.addoption('--descriptions', action='store', default="partition_des", help="descriptions of partition")
parser.addoption('--collection_name', action='store', default="collection_name", help="name of collection")
parser.addoption('--search_vectors', action='store', default="search_vectors", help="vectors of search")
parser.addoption('--index_param', action='store', default="index_param", help="index_param of index")
parser.addoption('--data', action='store', default="data", help="data of request")
parser.addoption('--log_path', action='store', default="/tmp/ci_logs/", help="log path of ci test")
@pytest.fixture
@ -86,3 +87,8 @@ def index_param(request):
@pytest.fixture
def data(request):
return request.config.getoption("--data")
@pytest.fixture
def log_path(request):
return request.config.getoption("--log_path")

View File

@ -1,5 +1,5 @@
[pytest]
addopts = --host 192.168.1.239 --html=/Users/yanliang/Docuement/report.html
addopts = --host 192.168.1.239 --html=/Users/wt/Desktop/report.html --self-contained-html
-;addopts = --host 172.28.255.155 --html=/tmp/report.html
# python3 -W ignore -m pytest

View File

@ -1,4 +1,5 @@
import pytest
import os
from pymilvus_orm.default_config import DefaultConfig
from base.client_base import TestcaseBase
@ -292,7 +293,3 @@ class TestConnectionOperation(TestcaseBase):
self.connection_wrap.add_connection(default={"host": host, "port": port}, dev={"host": host, "port": port})
log.info(self.connection_wrap.list_connections()[0])
assert self.connection_wrap.list_connections()[0] == ['default', 'dev']

View File

@ -1,64 +0,0 @@
import pytest
from milvus import DataType
from common.common_type import *
from common.common_func import *
from base.client_base import TestcaseBase
from utils.util_log import test_log as log
class TestParams(TestcaseBase):
def test_1(self):
self.connection.configure(check_res='', default={"host": "192.168.1.240", "port": "19530"})
res_ = self.connection.get_connection(alias='default')
log.info("res : %s" % str(res_))
log.info("self.connection : %s" % str(self.connection))
log.info("self.collection : %s" % str(self.collection))
log.info("self.partition : %s" % str(self.partition))
log.info("self.index : %s" % str(self.index))
log.info("self.utility : %s" % str(self.utility))
# @pytest.mark.parametrize("collection_name", get_invalid_strs)
# @pytest.mark.parametrize("fields", [get_binary_default_fields()])
# @pytest.mark.parametrize("partition_tag, field_name, params, entities",
# [(default_tag, default_float_vec_field_name, gen_simple_index()[0], get_entities()[0])])
# def test_collection_name_params_check(self, collection_name, fields, partition_tag, field_name, params, entities):
#
# self.create_collection(collection_name, fields, check_res=cname_param_check)
# self.get_collection_stats(collection_name, check_res=cname_param_check)
# self.flush(collection_name, check_res=cname_param_check)
#
# self.drop_collection(collection_name, check_res=cname_param_check)
# self.has_collection(collection_name, check_res=cname_param_check)
# self.describe_collection(collection_name, check_res=cname_param_check)
# self.load_collection(collection_name, check_res=cname_param_check)
# self.release_collection(collection_name, check_res=cname_param_check)
#
# self.create_partition(collection_name, partition_tag, check_res=cname_param_check)
# self.drop_partition(collection_name, partition_tag, check_res=cname_param_check)
# self.has_partition(collection_name, partition_tag, check_res=cname_param_check)
# self.load_partitions(collection_name, partition_tag, check_res=cname_param_check)
# self.release_partitions(collection_name, partition_tag, check_res=cname_param_check)
# self.list_partitions(collection_name, check_res=cname_param_check)
#
# self.create_index(collection_name, field_name, params, check_res=cname_param_check)
# self.drop_index(collection_name, field_name, check_res=cname_param_check)
# self.describe_index(collection_name, field_name, check_res=cname_param_check)
# self.search(collection_name, dsl=[1], check_res=cname_param_check)
#
# # self.insert(collection_name, entities=[1])
#
# @pytest.mark.parametrize("collection_name, fields", [(get_unique_str(), get_binary_default_fields())])
# @pytest.mark.parametrize("partition_tag", get_invalid_strs)
# def test_partition_tag_params_check(self, collection_name, fields, partition_tag):
# self.create_collection(collection_name, fields)
#
# self.create_partition(collection_name, partition_tag, check_res=pname_param_check)
# self.drop_partition(collection_name, partition_tag, check_res=pname_param_check)
# self.has_partition(collection_name, partition_tag, check_res=pname_param_check)
# """No parameter check"""
# # self.load_partitions(collection_name, partition_tag, check_res=None)
# # self.release_partitions(collection_name, partition_tag, check_res=None)
#
# self.drop_collection(collection_name)

View File

@ -1,16 +0,0 @@
import pytest
from milvus import DataType
from common.common_type import *
from common.common_func import *
from base.ClientRequest import Base, ApiReq
class CheckParams:
def __init__(self):
pass
@staticmethod
def check_str_param(self):
pass

View File

@ -3,7 +3,7 @@ from utils.util_log import test_log as log
class Error:
def __init__(self, error):
self.code = getattr(error, 'code', 99999)
self.code = getattr(error, 'code', -1)
self.message = getattr(error, 'message', str(error))

View File

@ -37,11 +37,11 @@ class TestLog:
self.log.addHandler(ch)
except Exception as e:
print("Can not use %s or %s to log." % (log_file, log_err))
print("Can not use %s or %s or %s to log. error : %s" % (log_debug, log_file, log_err, str(e)))
"""All modules share this unified log"""
log_debug = test_info.log_debug
log_info = test_info.log_info
log_err = test_info.log_err
test_log = TestLog('refactor_test', log_debug, log_info, log_err).log
test_log = TestLog('ci_test', log_debug, log_info, log_err).log