Update collection case for error check (#5677)

* add schema wrapper

Signed-off-by: ThreadDao <yufen.zong@zilliz.com>

* update collection error check

Signed-off-by: ThreadDao <yufen.zong@zilliz.com>

* [skip ci] skip

Signed-off-by: ThreadDao <yufen.zong@zilliz.com>
This commit is contained in:
ThreadDao 2021-06-09 09:21:35 +08:00 committed by GitHub
parent 0626e4ac48
commit cf8f52ee87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 400 additions and 312 deletions

View File

@ -7,6 +7,7 @@ from base.collection_wrapper import ApiCollectionWrapper
from base.partition_wrapper import ApiPartitionWrapper
from base.index_wrapper import ApiIndexWrapper
from base.utility_wrapper import ApiUtilityWrapper
from base.schema_wrapper import ApiCollectionSchemaWrapper, ApiFieldSchemaWrapper
from config.test_info import test_info
from utils.util_log import test_log as log
@ -37,6 +38,8 @@ class Base:
partition_wrap = None
index_wrap = None
utility_wrap = None
collection_schema_wrap = None
field_schema_wrap = None
def setup_class(self):
log.info("[setup_class] Start setup class...")
@ -51,6 +54,8 @@ class Base:
self.partition_wrap = ApiPartitionWrapper()
self.index_wrap = ApiIndexWrapper()
self.utility_wrap = ApiUtilityWrapper()
self.collection_schema_wrap = ApiCollectionSchemaWrapper()
self.field_schema_wrap = ApiFieldSchemaWrapper()
def teardown(self):
log.info(("*" * 35) + " teardown " + ("*" * 35))

View File

@ -0,0 +1,60 @@
import sys
sys.path.append("..")
from check.func_check import ResponseChecker
from utils.api_request import api_request
from pymilvus_orm import CollectionSchema, FieldSchema
class ApiCollectionSchemaWrapper:
collection_schema = None
def init_collection_schema(self, fields, description="", check_task=None, check_items=None, **kwargs):
"""In order to distinguish the same name of CollectionSchema"""
func_name = sys._getframe().f_code.co_name
response, is_succ = api_request([CollectionSchema, fields, description], **kwargs)
self.collection_schema = response if is_succ else None
check_result = ResponseChecker(response, func_name, check_task, check_items, is_succ=is_succ, fields=fields,
description=description, **kwargs).run()
return response, check_result
@property
def primary_field(self):
return self.collection_schema.primary_field if self.collection_schema else None
@property
def fields(self):
return self.collection_schema.fields if self.collection_schema else None
@property
def description(self):
return self.collection_schema.description if self.collection_schema else None
@property
def auto_id(self):
return self.collection_schema.auto_id if self.collection_schema else None
class ApiFieldSchemaWrapper:
field_schema = None
def init_field_schema(self, name, dtype, description="", check_task=None, check_items=None, **kwargs):
"""In order to distinguish the same name of FieldSchema"""
func_name = sys._getframe().f_code.co_name
response, is_succ = api_request([FieldSchema, name, dtype, description], **kwargs)
self.field_schema = response if is_succ else None
check_result = ResponseChecker(response, func_name, check_task, check_items, is_succ, name=name, dtype=dtype,
description=description, **kwargs).run()
return response, check_result
@property
def description(self):
return self.field_schema.description if self.field_schema else None
@property
def params(self):
return self.field_schema.params if self.field_schema else None
@property
def dtype(self):
return self.field_schema.dtype if self.field_schema else None

View File

@ -1,6 +1,7 @@
from utils.util_log import test_log as log
from common.common_type import *
from common.code_mapping import ErrorCode, ErrorMessage
from common import common_type as ct
from common.common_type import CheckTasks
# from common.code_mapping import ErrorCode, ErrorMessage
from pymilvus_orm import Collection, Partition
from utils.api_request import Error
@ -52,9 +53,8 @@ class ResponseChecker:
assert actual is False
assert len(error_dict) > 0
if isinstance(res, Error):
# 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
error_code = error_dict[ct.err_code]
assert res.code == error_code or error_dict[ct.err_msg] in res.message
else:
log.error("[CheckFunc] Response of API is not an error: %s" % str(res))
assert False

View File

@ -6,13 +6,12 @@ import pandas as pd
from sklearn import preprocessing
from pymilvus_orm.types import DataType
from pymilvus_orm.schema import CollectionSchema, FieldSchema
from base.schema_wrapper import ApiCollectionSchemaWrapper, ApiFieldSchemaWrapper
from common import common_type as ct
from utils.util_log import test_log as log
import threading
import traceback
"""" Methods of processing data """
l2 = lambda x, y: np.linalg.norm(np.array(x) - np.array(y))
@ -27,43 +26,51 @@ def gen_str_by_length(length=8):
def gen_int64_field(name=ct.default_int64_field_name, is_primary=False, description=ct.default_desc):
int64_field = FieldSchema(name=name, dtype=DataType.INT64, description=description, is_primary=is_primary)
int64_field, _ = ApiFieldSchemaWrapper().init_field_schema(name=name, dtype=DataType.INT64, description=description,
is_primary=is_primary)
return int64_field
def gen_float_field(name=ct.default_float_field_name, is_primary=False, description=ct.default_desc):
float_field = FieldSchema(name=name, dtype=DataType.FLOAT, description=description, is_primary=is_primary)
float_field, _ = ApiFieldSchemaWrapper().init_field_schema(name=name, dtype=DataType.FLOAT, description=description,
is_primary=is_primary)
return float_field
def gen_float_vec_field(name=ct.default_float_vec_field_name, is_primary=False, dim=ct.default_dim,
description=ct.default_desc):
float_vec_field = FieldSchema(name=name, dtype=DataType.FLOAT_VECTOR, description=description, dim=dim,
is_primary=is_primary)
float_vec_field, _ = ApiFieldSchemaWrapper().init_field_schema(name=name, dtype=DataType.FLOAT_VECTOR,
description=description, dim=dim,
is_primary=is_primary)
return float_vec_field
def gen_binary_vec_field(name=ct.default_binary_vec_field_name, is_primary=False, dim=ct.default_dim,
description=ct.default_desc):
binary_vec_field = FieldSchema(name=name, dtype=DataType.BINARY_VECTOR, description=description, dim=dim,
is_primary=is_primary)
binary_vec_field, _ = ApiFieldSchemaWrapper().init_field_schema(name=name, dtype=DataType.BINARY_VECTOR,
description=description, dim=dim,
is_primary=is_primary)
return binary_vec_field
def gen_default_collection_schema(description=ct.default_desc, primary_field=None):
fields = [gen_int64_field(), gen_float_field(), gen_float_vec_field()]
schema = CollectionSchema(fields=fields, description=description, primary_field=primary_field)
schema, _ = ApiCollectionSchemaWrapper().init_collection_schema(fields=fields, description=description,
primary_field=primary_field)
log.error(schema)
return schema
def gen_collection_schema(fields, primary_field=None, description=ct.default_desc):
schema = CollectionSchema(fields=fields, primary_field=primary_field, description=description)
schema, _ = ApiCollectionSchemaWrapper().init_collection_schema(fields=fields, primary_field=primary_field,
description=description)
return schema
def gen_default_binary_collection_schema(description=ct.default_desc, primary_field=None):
fields = [gen_int64_field(), gen_float_field(), gen_binary_vec_field()]
binary_schema = CollectionSchema(fields=fields, description=description, primary_field=primary_field)
binary_schema, _ = ApiCollectionSchemaWrapper().init_collection_schema(fields=fields, description=description,
primary_field=primary_field)
return binary_schema
@ -134,9 +141,9 @@ def gen_numpy_data(nb=ct.default_nb, dim=ct.default_dim):
def gen_default_binary_list_data(nb=ct.default_nb, dim=ct.default_dim):
int_values = [i for i in range(nb)]
float_values = [np.float32(i) for i in range(nb)]
_, binary_vec_values = gen_binary_vectors(nb, dim)
binary_raw_values, binary_vec_values = gen_binary_vectors(nb, dim)
data = [int_values, float_values, binary_vec_values]
return data
return data, binary_raw_values
def gen_simple_index():
@ -167,26 +174,11 @@ def gen_all_type_fields():
fields = []
for k, v in DataType.__members__.items():
if v != DataType.UNKNOWN:
field = FieldSchema(name=k.lower(), dtype=v)
field, _ = ApiFieldSchemaWrapper().init_field_schema(name=k.lower(), dtype=v)
fields.append(field)
return fields
def gen_invalid_dataframe():
vec = gen_vectors(3, 2)
dfs = [
# just columns df
pd.DataFrame(columns=[ct.default_int64_field_name, ct.default_float_vec_field_name]),
# no column just data df
pd.DataFrame({' ': vec}),
# datetime df
pd.DataFrame({"date": pd.date_range('20210101', periods=3)}),
# invalid column df
pd.DataFrame({'%$#': vec}),
]
return dfs
def jaccard(x, y):
x = np.asarray(x, np.bool)
y = np.asarray(y, np.bool)

View File

@ -34,7 +34,8 @@ float_vec_field_desc = "float vector type field"
binary_vec_field_desc = "binary vector type field"
Not_Exist = "Not_Exist"
err_code = "err_code"
err_msg = "err_msg"
"""" List of parameters used to pass """
get_invalid_strs = [

View File

@ -1,32 +1,30 @@
import pandas as pd
import pytest
from pymilvus import DataType
from pymilvus_orm import FieldSchema
from base.client_base import TestcaseBase
from utils.util_log import test_log as log
# from utils.util_log import test_log as log
from common import common_func as cf
from common import common_type as ct
from common.common_type import CaseLabel, CheckTasks
prefix = "collection"
default_schema = cf.gen_default_collection_schema()
default_binary_schema = cf.gen_default_binary_collection_schema()
def assert_default_collection(collection, exp_name=None, exp_schema=default_schema, exp_num=0, exp_primary=None):
def assert_default_collection(collection_w, exp_name=None, exp_schema=default_schema, exp_num=0, exp_primary=None):
if exp_name:
assert collection.name == exp_name
assert collection.description == exp_schema.description
assert collection.schema == exp_schema
assert collection_w.name == exp_name
assert collection_w.description == exp_schema.description
assert collection_w.schema == exp_schema
if exp_num == 0:
assert collection.is_empty
assert collection.num_entities == exp_num
assert collection_w.is_empty
assert collection_w.num_entities == exp_num
if exp_primary is None:
assert collection.primary_field is None
assert collection_w.primary_field is None
else:
assert collection.primary_field == exp_primary
assert collection_w.primary_field == exp_primary
class TestCollectionParams(TestcaseBase):
@ -34,13 +32,10 @@ class TestCollectionParams(TestcaseBase):
'''
def teardown_method(self):
if self.collection_wrap is not None and self.collection_wrap.collection is not None:
self.collection_wrap.drop()
if self.self.collection_wrap is not None and self.self.collection_wrap.collection is not None:
self.self.collection_wrap.drop()
'''
def setup_method(self):
pass
@pytest.fixture(scope="function", params=ct.get_invalid_strs)
def get_invalid_type_schema(self, request):
if request.param is None:
@ -87,23 +82,35 @@ class TestCollectionParams(TestcaseBase):
"""
self._connect()
c_name = ""
ex, check = self.collection_wrap.init_collection(c_name, schema=default_schema,
check_task=CheckTasks.err_res)
assert "value is illegal" in str(ex)
error = {ct.err_code: 1, ct.err_msg: "value is illegal"}
self.collection_wrap.init_collection(c_name, schema=default_schema, check_task=CheckTasks.err_res,
check_items=error)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_invalid_name(self, get_invalid_string):
@pytest.mark.parametrize("name", [[], 1, [1, "2", 3], (1,), {1: 1}, None])
def test_collection_illegal_name(self, name):
"""
target: test collection with illegal name
method: create collection with illegal name
expected: raise exception
"""
self._connect()
error = {ct.err_code: 1, ct.err_msg: "`collection_name` value {} is illegal".format(name)}
self.collection_wrap.init_collection(name, schema=default_schema, check_task=CheckTasks.err_res,
check_items=error)
@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.parametrize("name", ["12-s", "12 s", "(mn)", "中文", "%$#", "a".join("a" for i in range(256))])
def test_collection_invalid_name(self, name):
"""
target: test collection with invalid name
method: create collection with invalid name
expected: raise exception
"""
self._connect()
c_name = get_invalid_string
ex, check = self.collection_wrap.init_collection(c_name, schema=default_schema,
check_task=CheckTasks.err_res)
assert "invalid" or "illegal" in str(ex)
error = {ct.err_code: 1, ct.err_msg: "Invalid collection name: {}".format(name)}
self.collection_wrap.init_collection(name, schema=default_schema, check_task=CheckTasks.err_res,
check_items=error)
@pytest.mark.tags(CaseLabel.L0)
def test_collection_dup_name(self):
@ -113,14 +120,13 @@ class TestCollectionParams(TestcaseBase):
expected: collection properties consistent
"""
self._connect()
collection = self._collection()
c_name = collection.name
assert_default_collection(collection)
dup_collection, _ = self.collection_wrap.init_collection(c_name)
assert collection.name == dup_collection.name
assert collection.schema == dup_collection.schema
assert collection.num_entities == dup_collection.num_entities
assert collection.name, _ in self.utility_wrap.list_collections()[0]
collection_w = self.init_collection_wrap()
assert_default_collection(collection_w)
self.collection_wrap.init_collection(collection_w.name)
assert collection_w.name == self.collection_wrap.name
assert collection_w.schema == self.collection_wrap.schema
assert collection_w.num_entities == self.collection_wrap.num_entities
assert collection_w.name, _ in self.utility_wrap.list_collections()[0]
@pytest.mark.tags(CaseLabel.L1)
def test_collection_dup_name_with_desc(self):
@ -131,12 +137,11 @@ class TestCollectionParams(TestcaseBase):
"""
self._connect()
schema = cf.gen_default_collection_schema(description=ct.collection_desc)
collection = self._collection(schema=schema)
assert_default_collection(collection, exp_schema=schema)
c_name = collection.name
dup_collection, _ = self.collection_wrap.init_collection(c_name)
assert_default_collection(dup_collection, c_name, exp_schema=schema)
assert collection.description == dup_collection.description
collection_w = self.init_collection_wrap(schema=schema)
assert_default_collection(collection_w, exp_schema=schema)
self.collection_wrap.init_collection(collection_w.name)
assert_default_collection(self.collection_wrap, collection_w.name, exp_schema=schema)
assert collection_w.description == self.collection_wrap.description
@pytest.mark.tags(CaseLabel.L1)
def test_collection_dup_name_new_schema(self):
@ -147,14 +152,14 @@ class TestCollectionParams(TestcaseBase):
expected: raise exception
"""
self._connect()
collection = self._collection()
c_name = collection.name
assert_default_collection(collection)
collection_w = self.init_collection_wrap()
c_name = collection_w.name
assert_default_collection(collection_w)
fields = [cf.gen_int64_field()]
schema = cf.gen_collection_schema(fields=fields)
ex, _ = self.collection_wrap.init_collection(c_name, schema=schema,
check_task=CheckTasks.err_res)
assert "The collection already exist, but the schema isnot the same as the passed in" in str(ex)
error = {ct.err_code: 1, ct.err_msg: "The collection already exist, but the schema isnot the same as the "
"passed in"}
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_dup_name_new_primary(self):
@ -165,14 +170,14 @@ class TestCollectionParams(TestcaseBase):
expected: raise exception
"""
self._connect()
collection = self._collection()
c_name = collection.name
assert_default_collection(collection)
collection_w = self.init_collection_wrap()
c_name = collection_w.name
assert_default_collection(collection_w)
schema = cf.gen_default_collection_schema(primary_field=ct.default_int64_field_name)
ex, _ = self.collection_wrap.init_collection(c_name, schema=schema,
check_task=CheckTasks.err_res)
assert "The collection already exist, but the schema isnot the same as the passed in" in str(ex)
assert collection.primary_field is None
error = {ct.err_code: 1, ct.err_msg: "The collection already exist, but the schema isnot the same as the "
"passed in"}
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)
assert collection_w.primary_field is None
@pytest.mark.tags(CaseLabel.L1)
def test_collection_dup_name_new_dim(self):
@ -183,16 +188,16 @@ class TestCollectionParams(TestcaseBase):
"""
self._connect()
new_dim = 120
collection = self._collection()
c_name = collection.name
assert_default_collection(collection)
collection_w = self.init_collection_wrap()
c_name = collection_w.name
assert_default_collection(collection_w)
schema = cf.gen_default_collection_schema()
new_fields = cf.gen_float_vec_field(dim=new_dim)
schema.fields[-1] = new_fields
ex, _ = self.collection_wrap.init_collection(c_name, schema=schema,
check_task=CheckTasks.err_res)
assert "The collection already exist, but the schema isnot the same as the passed in" in str(ex)
assert collection.primary_field is None
error = {ct.err_code: 1, ct.err_msg: "The collection already exist, but the schema isnot the same as the "
"passed in"}
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)
assert collection_w.primary_field is None
@pytest.mark.tags(CaseLabel.L1)
def test_collection_dup_name_invalid_schema_type(self, get_invalid_type_schema):
@ -202,13 +207,13 @@ class TestCollectionParams(TestcaseBase):
expected: raise exception and
"""
self._connect()
collection = self._collection()
c_name = collection.name
assert_default_collection(collection)
ex, _ = self.collection_wrap.init_collection(c_name, schema=get_invalid_type_schema,
check_task=CheckTasks.err_res)
assert "schema type must be schema.CollectionSchema" in str(ex)
assert_default_collection(collection, c_name)
collection_w = self.init_collection_wrap()
assert_default_collection(collection_w)
error = {ct.err_code: 1, ct.err_msg: "schema type must be schema.CollectionSchema"}
schema = get_invalid_type_schema
self.collection_wrap.init_collection(collection_w.name, schema=schema,
check_task=CheckTasks.err_res, check_items=error)
assert_default_collection(collection_w, collection_w.name)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_dup_name_same_schema(self):
@ -218,14 +223,12 @@ class TestCollectionParams(TestcaseBase):
expected: two collection object is available
"""
self._connect()
collection = self._collection(schema=default_schema)
c_name = collection.name
assert_default_collection(collection)
dup_collection, _ = self.collection_wrap.init_collection(c_name, schema=default_schema)
assert_default_collection(dup_collection, c_name)
collection_w = self.init_collection_wrap(schema=default_schema)
assert_default_collection(collection_w)
self.collection_wrap.init_collection(collection_w.name, schema=default_schema)
assert_default_collection(self.collection_wrap, self.collection_wrap.name)
@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.xfail(reason="issue #5367")
def test_collection_dup_name_none_schema_dataframe(self):
"""
target: test collection with dup name and insert dataframe
@ -234,14 +237,13 @@ class TestCollectionParams(TestcaseBase):
"""
conn = self._connect()
nb = ct.default_nb
collection = self._collection()
c_name = collection.name
assert_default_collection(collection)
collection_w = self.init_collection_wrap()
assert_default_collection(collection_w)
df = cf.gen_default_dataframe_data(nb)
dup_collection, _ = self.collection_wrap.init_collection(c_name, schema=None, data=df)
conn.flush([c_name])
assert_default_collection(dup_collection, c_name, exp_num=nb)
assert collection.num_entities == nb
self.collection_wrap.init_collection(collection_w.name, schema=None, data=df)
conn.flush([collection_w.name])
assert_default_collection(self.collection_wrap, collection_w.name, exp_num=nb)
assert collection_w.num_entities == nb
@pytest.mark.tags(CaseLabel.L1)
def test_collection_dup_name_none_schema_data_list(self):
@ -252,14 +254,13 @@ class TestCollectionParams(TestcaseBase):
"""
conn = self._connect()
nb = ct.default_nb
collection = self._collection()
c_name = collection.name
assert_default_collection(collection)
collection_w = self.init_collection_wrap()
assert_default_collection(collection_w)
data = cf.gen_default_dataframe_data(nb)
dup_collection, _ = self.collection_wrap.init_collection(c_name, schema=None, data=data)
conn.flush([c_name])
assert_default_collection(dup_collection, c_name, exp_num=nb)
assert collection.num_entities == nb
self.collection_wrap.init_collection(collection_w.name, schema=None, data=data)
conn.flush([collection_w.name])
assert_default_collection(self.collection_wrap, collection_w.name, exp_num=nb)
assert collection_w.num_entities == nb
@pytest.mark.tags(CaseLabel.L0)
def test_collection_none_schema(self):
@ -270,9 +271,8 @@ class TestCollectionParams(TestcaseBase):
"""
self._connect()
c_name = cf.gen_unique_str(prefix)
ex, _ = self.collection_wrap.init_collection(c_name, schema=None,
check_task=CheckTasks.err_res)
assert "Collection missing schema" in str(ex)
error = {ct.err_code: 1, ct.err_msg: "Collection missing schema"}
self.collection_wrap.init_collection(c_name, schema=None, check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L0)
def test_collection_invalid_type_schema(self, get_invalid_type_schema):
@ -283,9 +283,9 @@ class TestCollectionParams(TestcaseBase):
"""
self._connect()
c_name = cf.gen_unique_str(prefix)
ex, _ = self.collection_wrap.init_collection(c_name, schema=get_invalid_type_schema,
check_task=CheckTasks.err_res)
assert "schema type must be schema.CollectionSchema" in str(ex)
error = {ct.err_code: 1, ct.err_msg: "schema type must be schema.CollectionSchema"}
self.collection_wrap.init_collection(c_name, schema=get_invalid_type_schema,
check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_invalid_type_fields(self, get_invalid_type_fields):
@ -296,8 +296,9 @@ class TestCollectionParams(TestcaseBase):
"""
self._connect()
fields = get_invalid_type_fields
with pytest.raises(Exception, match="The fields of schema must be type list"):
cf.gen_collection_schema(fields=fields)
error = {ct.err_code: 1, ct.err_msg: "The fields of schema must be type list"}
self.collection_schema_wrap.init_collection_schema(fields=fields,
check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_with_unknown_type(self):
@ -307,11 +308,13 @@ class TestCollectionParams(TestcaseBase):
expected: raise exception
"""
self._connect()
with pytest.raises(Exception, match="Field type not support <DataType.UNKNOWN: 999"):
FieldSchema("unknown", DataType.UNKNOWN)
error = {ct.err_code: 0, ct.err_msg: "Field type not support <DataType.UNKNOWN: 999"}
self.field_schema_wrap.init_field_schema(name="unknown", dtype=DataType.UNKNOWN,
check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_invalid_field_name(self, get_invalid_string):
@pytest.mark.parametrize("name", [[], 1, (1,), {1: 1}, "12-s"])
def test_collection_invalid_type_field(self, name):
"""
target: test collection with invalid field name
method: invalid string name
@ -319,14 +322,41 @@ class TestCollectionParams(TestcaseBase):
"""
self._connect()
c_name = cf.gen_unique_str(prefix)
field = FieldSchema(name=get_invalid_string, dtype=5)
schema = cf.gen_collection_schema(fields=[field])
ex, _ = self.collection_wrap.init_collection(c_name, schema=schema,
check_task=CheckTasks.err_res)
message_one = "but expected one of: bytes, unicode"
message_two = "You should specify the name of field"
message_three = "Invalid field name"
assert message_one or message_two or message_three in str(ex)
field, _ = self.field_schema_wrap.init_field_schema(name=name, dtype=5)
vec_field = cf.gen_float_vec_field()
schema = cf.gen_collection_schema(fields=[field, vec_field])
error = {ct.err_code: 1, ct.err_msg: "expected one of: bytes, unicode"}
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.parametrize("name", ["12-s", "12 s", "(mn)", "中文", "%$#", "a".join("a" for i in range(256))])
def test_collection_invalid_field_name(self, name):
"""
target: test collection with invalid field name
method: invalid string name
expected: raise exception
"""
self._connect()
c_name = cf.gen_unique_str(prefix)
field, _ = self.field_schema_wrap.init_field_schema(name=name, dtype=5)
vec_field = cf.gen_float_vec_field()
schema = cf.gen_collection_schema(fields=[field, vec_field])
error = {ct.err_code: 1, ct.err_msg: "Invalid field name"}
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_none_field_name(self):
"""
target: test field schema with None name
method: None field name
expected: raise exception
"""
self._connect()
c_name = cf.gen_unique_str(prefix)
field, _ = self.field_schema_wrap.init_field_schema(name=None, dtype=5)
schema = cf.gen_collection_schema(fields=[field, cf.gen_float_vec_field()])
error = {ct.err_code: 1, ct.err_msg: "You should specify the name of field"}
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.parametrize("dtype", [6, [[]], {}, (), "", "a"])
@ -337,8 +367,9 @@ class TestCollectionParams(TestcaseBase):
expected: raise exception
"""
self._connect()
with pytest.raises(Exception, match="Field type must be of DataType"):
FieldSchema(name="test", dtype=dtype)
error = {ct.err_code: 0, ct.err_msg: "Field type must be of DataType"}
self.field_schema_wrap.init_field_schema(name="test", dtype=dtype,
check_task=CheckTasks.err_res, check_items=error)
def test_collection_field_float_type(self):
"""
@ -348,12 +379,10 @@ class TestCollectionParams(TestcaseBase):
"""
self._connect()
c_name = cf.gen_unique_str(prefix)
field = FieldSchema(name=ct.default_int64_field_name, dtype=5.0)
vec_field = cf.gen_float_vec_field()
schema = cf.gen_collection_schema(fields=[field, vec_field])
ex, _ = self.collection_wrap.init_collection(c_name, schema=schema,
check_task=CheckTasks.err_res)
assert "Field type must be of DataType" in str(ex)
field, _ = self.field_schema_wrap.init_field_schema(name=ct.default_int64_field_name, dtype=5.0)
schema = cf.gen_collection_schema(fields=[field, cf.gen_float_vec_field()])
error = {ct.err_code: 0, ct.err_msg: "Field type must be of DataType"}
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L0)
def test_collection_empty_fields(self):
@ -365,9 +394,8 @@ class TestCollectionParams(TestcaseBase):
self._connect()
c_name = cf.gen_unique_str(prefix)
schema = cf.gen_collection_schema(fields=[])
ex, _ = self.collection_wrap.init_collection(c_name, schema=schema,
check_task=CheckTasks.err_res)
assert "The field of the schema cannot be empty" in str(ex)
error = {ct.err_code: 0, ct.err_msg: "The field of the schema cannot be empty"}
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_dup_field(self):
@ -381,11 +409,9 @@ class TestCollectionParams(TestcaseBase):
field_one = cf.gen_int64_field()
field_two = cf.gen_int64_field()
schema = cf.gen_collection_schema(fields=[field_one, field_two])
ex, _ = self.collection_wrap.init_collection(c_name, schema=schema,
check_task=CheckTasks.err_res)
assert "duplicated field name" in str(ex)
has, _ = self.utility_wrap.has_collection(c_name)
assert not has
error = {ct.err_code: 0, ct.err_msg: "duplicated field name"}
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)
assert not self.utility_wrap.has_collection(c_name)[0]
@pytest.mark.tags(CaseLabel.L0)
@pytest.mark.parametrize("field", [cf.gen_float_vec_field(), cf.gen_binary_vec_field()])
@ -398,8 +424,8 @@ class TestCollectionParams(TestcaseBase):
self._connect()
c_name = cf.gen_unique_str(prefix)
schema = cf.gen_collection_schema(fields=[field])
collection, _ = self.collection_wrap.init_collection(c_name, schema=schema)
assert_default_collection(collection, c_name, exp_schema=schema)
self.collection_wrap.init_collection(c_name, schema=schema)
assert_default_collection(self.collection_wrap, c_name, exp_schema=schema)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_multi_float_vectors(self):
@ -412,8 +438,8 @@ class TestCollectionParams(TestcaseBase):
c_name = cf.gen_unique_str(prefix)
fields = [cf.gen_float_vec_field(), cf.gen_float_vec_field(name="tmp")]
schema = cf.gen_collection_schema(fields=fields)
collection, _ = self.collection_wrap.init_collection(c_name, schema=schema)
assert_default_collection(collection, c_name, exp_schema=schema)
self.collection_wrap.init_collection(c_name, schema=schema)
assert_default_collection(self.collection_wrap, c_name, exp_schema=schema)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_mix_vectors(self):
@ -426,8 +452,8 @@ class TestCollectionParams(TestcaseBase):
c_name = cf.gen_unique_str(prefix)
fields = [cf.gen_float_vec_field(), cf.gen_binary_vec_field()]
schema = cf.gen_collection_schema(fields=fields)
collection, _ = self.collection_wrap.init_collection(c_name, schema=schema)
assert_default_collection(collection, c_name, exp_schema=schema)
self.collection_wrap.init_collection(c_name, schema=schema)
assert_default_collection(self.collection_wrap, c_name, exp_schema=schema)
@pytest.mark.tags(CaseLabel.L0)
def test_collection_without_vectors(self):
@ -439,9 +465,8 @@ class TestCollectionParams(TestcaseBase):
self._connect()
c_name = cf.gen_unique_str(prefix)
schema = cf.gen_collection_schema([cf.gen_int64_field()])
ex, _ = self.collection_wrap.init_collection(c_name, schema=schema,
check_task=CheckTasks.err_res)
assert "The schema must have vector column" in str(ex)
error = {ct.err_code: 0, ct.err_msg: "The schema must have vector column"}
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L0)
def test_collection_primary_field(self):
@ -453,8 +478,8 @@ class TestCollectionParams(TestcaseBase):
self._connect()
c_name = cf.gen_unique_str(prefix)
schema = cf.gen_default_collection_schema(primary_field=ct.default_int64_field_name)
collection, _ = self.collection_wrap.init_collection(c_name, schema=schema)
assert collection.primary_field.name == ct.default_int64_field_name
self.collection_wrap.init_collection(c_name, schema=schema)
assert self.collection_wrap.primary_field.name == ct.default_int64_field_name
@pytest.mark.tags(CaseLabel.L1)
def test_collection_unsupported_primary_field(self, get_unsupported_primary_field):
@ -466,11 +491,10 @@ class TestCollectionParams(TestcaseBase):
self._connect()
c_name = cf.gen_unique_str(prefix)
field = get_unsupported_primary_field
vec_field = cf.gen_float_vec_field()
vec_field = cf.gen_float_vec_field(name="vec")
schema = cf.gen_collection_schema(fields=[field, vec_field], primary_field=field.name)
ex, _ = self.collection_wrap.init_collection(c_name, schema=schema,
check_task=CheckTasks.err_res)
assert "the data type of primary key should be int64" in str(ex)
error = {ct.err_code: 1, ct.err_msg: "the data type of primary key should be int64"}
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_multi_primary_fields(self):
@ -484,9 +508,8 @@ class TestCollectionParams(TestcaseBase):
int_field = cf.gen_int64_field(is_primary=True)
float_vec_field = cf.gen_float_vec_field(is_primary=True)
schema = cf.gen_collection_schema(fields=[int_field, float_vec_field])
ex, _ = self.collection_wrap.init_collection(c_name, schema=schema,
check_task=CheckTasks.err_res)
assert "there are more than one primary key" in str(ex)
error = {ct.err_code: 0, ct.err_msg: "there are more than one primary key"}
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_primary_inconsistent(self):
@ -500,9 +523,8 @@ class TestCollectionParams(TestcaseBase):
int_field = cf.gen_int64_field(name="int", is_primary=True)
float_vec_field = cf.gen_float_vec_field(name="vec")
schema = cf.gen_collection_schema(fields=[int_field, float_vec_field], primary_field="vec")
ex, _ = self.collection_wrap.init_collection(c_name, schema=schema,
check_task=CheckTasks.err_res)
assert "there are more than one primary key" in str(ex)
error = {ct.err_code: 0, ct.err_msg: "there are more than one primary key"}
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_field_primary_false(self):
@ -516,28 +538,23 @@ class TestCollectionParams(TestcaseBase):
int_field = cf.gen_int64_field(name="int")
float_vec_field = cf.gen_float_vec_field()
schema = cf.gen_collection_schema(fields=[int_field, float_vec_field])
collection, _ = self.collection_wrap.init_collection(c_name, schema=schema)
assert collection.primary_field is None
assert collection.schema.auto_id
self.collection_wrap.init_collection(c_name, schema=schema)
assert self.collection_wrap.primary_field is None
assert self.collection_wrap.schema.auto_id
@pytest.mark.tags(CaseLabel.L1)
def test_collection_field_invalid_primary(self, get_invalid_string):
@pytest.mark.parametrize("is_primary", ct.get_invalid_strs)
def test_collection_field_invalid_primary(self, is_primary):
"""
target: test collection with invalid primary
method: define field with is_primary=non-bool
expected: raise exception
"""
self._connect()
c_name = cf.gen_unique_str(prefix)
int_field = cf.gen_int64_field(name="int", is_primary=get_invalid_string)
float_vec_field = cf.gen_float_vec_field()
schema = cf.gen_collection_schema(fields=[int_field, float_vec_field])
ex, _ = self.collection_wrap.init_collection(c_name, schema=schema,
check_task=CheckTasks.err_res)
log.info(str(ex))
cf.gen_unique_str(prefix)
with pytest.raises(Exception, match="Param is_primary must be bool type"):
cf.gen_int64_field(name="int", is_primary=get_invalid_string)
name = cf.gen_unique_str(prefix)
error = {ct.err_code: 0, ct.err_msg: "Param is_primary must be bool type"}
self.field_schema_wrap.init_field_schema(name=name, dtype=DataType.INT64, is_primary=is_primary,
check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L0)
@pytest.mark.parametrize("dtype", [DataType.FLOAT_VECTOR, DataType.BINARY_VECTOR])
@ -549,11 +566,10 @@ class TestCollectionParams(TestcaseBase):
"""
self._connect()
c_name = cf.gen_unique_str(prefix)
float_vec_field = FieldSchema(name="vec", dtype=dtype)
float_vec_field, _ = self.field_schema_wrap.init_field_schema(name="vec", dtype=dtype)
schema = cf.gen_collection_schema(fields=[float_vec_field])
ex, _ = self.collection_wrap.init_collection(c_name, schema=schema,
check_task=CheckTasks.err_res)
assert "dimension is not defined in field type params" in str(ex)
error = {ct.err_code: 0, ct.err_msg: "dimension is not defined in field type params"}
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_vector_invalid_dim(self, get_invalid_dim):
@ -566,9 +582,8 @@ class TestCollectionParams(TestcaseBase):
c_name = cf.gen_unique_str(prefix)
float_vec_field = cf.gen_float_vec_field(dim=get_invalid_dim)
schema = cf.gen_collection_schema(fields=[float_vec_field])
ex, _ = self.collection_wrap.init_collection(c_name, schema=schema,
check_task=CheckTasks.err_res)
assert "dim must be of int" in str(ex)
error = {ct.err_code: 0, ct.err_msg: "dim must be of int"}
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.parametrize("dim", [-1, 32769])
@ -582,9 +597,8 @@ class TestCollectionParams(TestcaseBase):
c_name = cf.gen_unique_str(prefix)
float_vec_field = cf.gen_float_vec_field(dim=dim)
schema = cf.gen_collection_schema(fields=[float_vec_field])
ex, _ = self.collection_wrap.init_collection(c_name, schema=schema,
check_task=CheckTasks.err_res)
assert "invalid dimension: {}. should be in range 1 ~ 32768".format(dim) in str(ex)
error = {ct.err_code: 0, ct.err_msg: "invalid dimension: {}. should be in range 1 ~ 32768".format(dim)}
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_non_vector_field_dim(self):
@ -595,25 +609,37 @@ class TestCollectionParams(TestcaseBase):
"""
self._connect()
c_name = cf.gen_unique_str(prefix)
int_field = FieldSchema(name="int", dtype=DataType.INT64, dim=ct.default_dim)
int_field, _ = self.field_schema_wrap.init_field_schema(name="int", dtype=DataType.INT64, dim=ct.default_dim)
float_vec_field = cf.gen_float_vec_field()
schema = cf.gen_collection_schema(fields=[int_field, float_vec_field])
collection, _ = self.collection_wrap.init_collection(c_name, schema=schema)
assert_default_collection(collection, c_name, exp_schema=schema)
self.collection_wrap.init_collection(c_name, schema=schema)
assert_default_collection(self.collection_wrap, c_name, exp_schema=schema)
@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.parametrize("desc", [None, ct.collection_desc])
def test_collection_desc(self, desc):
def test_collection_desc(self):
"""
target: test collection with none description
method: create with none description
target: test collection with description
method: create with description
expected: assert default description
"""
self._connect()
c_name = cf.gen_unique_str(prefix)
schema = cf.gen_default_collection_schema(description=desc)
collection, _ = self.collection_wrap.init_collection(c_name, schema=schema)
assert_default_collection(collection, c_name, exp_schema=schema)
schema = cf.gen_default_collection_schema(description=ct.collection_desc)
self.collection_wrap.init_collection(c_name, schema=schema)
assert_default_collection(self.collection_wrap, c_name, exp_schema=schema)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_none_desc(self):
"""
target: test collection with none description
method: create with none description
expected: raise exception
"""
self._connect()
c_name = cf.gen_unique_str(prefix)
schema = cf.gen_default_collection_schema(description=None)
error = {ct.err_code: 0, ct.err_msg: "expected one of: bytes, unicode"}
self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_long_desc(self):
@ -626,7 +652,7 @@ class TestCollectionParams(TestcaseBase):
c_name = cf.gen_unique_str(prefix)
desc = "a".join("a" for _ in range(256))
schema = cf.gen_default_collection_schema(description=desc)
collection, _ = self.collection_wrap.init_collection(c_name, schema=schema)
collection, _ = self.self.collection_wrap.init_collection(c_name, schema=schema)
assert_default_collection(collection, c_name, exp_schema=schema)
@pytest.mark.tags(CaseLabel.L0)
@ -637,12 +663,11 @@ class TestCollectionParams(TestcaseBase):
expected: collection num entities equal to nb
"""
conn = self._connect()
nb = ct.default_nb
c_name = cf.gen_unique_str(prefix)
data = cf.gen_default_dataframe_data(nb)
collection, _ = self.collection_wrap.init_collection(c_name, schema=default_schema, data=data)
data = cf.gen_default_dataframe_data(ct.default_nb)
self.collection_wrap.init_collection(c_name, schema=default_schema, data=data)
conn.flush([c_name])
assert_default_collection(collection, c_name, exp_num=nb)
assert_default_collection(self.collection_wrap, c_name, exp_num=ct.default_nb)
@pytest.mark.tags(CaseLabel.L0)
def test_collection_with_data_list(self):
@ -652,14 +677,14 @@ class TestCollectionParams(TestcaseBase):
expected: collection num entities equal to nb
"""
conn = self._connect()
nb = ct.default_nb
c_name = cf.gen_unique_str(prefix)
data = cf.gen_default_list_data(nb)
collection, _ = self.collection_wrap.init_collection(c_name, schema=default_schema, data=data)
data = cf.gen_default_list_data(ct.default_nb)
self.collection_wrap.init_collection(c_name, schema=default_schema, data=data)
conn.flush([c_name])
assert_default_collection(collection, c_name, exp_num=nb)
assert_default_collection(self.collection_wrap, c_name, exp_num=ct.default_nb)
@pytest.mark.tags(CaseLabel.L0)
@pytest.mark.xfail(reason="issue #5667")
def test_collection_binary(self):
"""
target: test collection with binary-vec
@ -668,45 +693,37 @@ class TestCollectionParams(TestcaseBase):
"""
self._connect()
c_name = cf.gen_unique_str(prefix)
collection, _ = self.collection_wrap.init_collection(c_name, data=None, schema=default_binary_schema)
assert_default_collection(collection, c_name, exp_schema=default_binary_schema)
self.collection_wrap.init_collection(c_name, data=None, schema=default_binary_schema)
assert_default_collection(self.collection_wrap, c_name, exp_schema=default_binary_schema)
assert c_name in self.utility_wrap.list_collections()[0]
@pytest.mark.tags(CaseLabel.L0)
# @pytest.mark.xfail(reason="issue #5414")
def test_collection_binary_with_dataframe(self):
"""
target: test binary collection with dataframe
method: create binary collection with dataframe
expected: collection num entities equal to nb
"""
self._connect()
nb = ct.default_nb
conn = self._connect()
c_name = cf.gen_unique_str(prefix)
data = cf.gen_default_binary_dataframe_data(3)
collection, _ = self.collection_wrap.init_collection(c_name,
schema=default_binary_schema,
data=data)
assert_default_collection(collection, c_name,
exp_schema=default_binary_schema,
exp_num=nb)
df, _ = cf.gen_default_binary_dataframe_data(nb=ct.default_nb)
self.collection_wrap.init_collection(c_name, schema=default_binary_schema, data=df)
conn.flush([c_name])
assert_default_collection(self.collection_wrap, c_name, exp_schema=default_binary_schema, exp_num=ct.default_nb)
@pytest.mark.tags(CaseLabel.L0)
@pytest.mark.xfail(reason="issue #5414")
def test_collection_binary_with_data_list(self):
"""
target: test collection with data (list-like)
method: create binary collection with data (list-like)
expected: collection num entities equal to nb
"""
self._connect()
nb = ct.default_nb
conn = self._connect()
c_name = cf.gen_unique_str(prefix)
data = cf.gen_default_binary_list_data(nb)
ex, _ = self.collection_wrap.init_collection(c_name, schema=default_binary_schema,
data=data,
check_task=CheckTasks.err_res)
log.debug(str(ex))
data, _ = cf.gen_default_binary_list_data(ct.default_nb)
self.collection_wrap.init_collection(c_name, schema=default_binary_schema, data=data)
conn.flush([c_name])
assert_default_collection(self.collection_wrap, c_name, exp_schema=default_binary_schema, exp_num=ct.default_nb)
class TestCollectionOperation(TestcaseBase):
@ -716,12 +733,9 @@ class TestCollectionOperation(TestcaseBase):
******************************************************************
"""
def teardown_method(self):
if self.collection_wrap is not None and self.collection_wrap.collection is not None:
self.collection_wrap.drop()
def setup_method(self):
pass
# def teardown_method(self):
# if self.self.collection_wrap is not None and self.self.collection_wrap.collection is not None:
# self.self.collection_wrap.drop()
@pytest.fixture(scope="function", params=ct.get_invalid_strs)
def get_non_df(self, request):
@ -729,11 +743,8 @@ class TestCollectionOperation(TestcaseBase):
pytest.skip("skip None")
yield request.param
@pytest.fixture(scope="function", params=cf.gen_invalid_dataframe())
def get_invalid_df(self, request):
yield request.param
@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.xfail(reason="issue #5671")
def test_collection_without_connection(self):
"""
target: test collection without connection
@ -743,14 +754,15 @@ class TestCollectionOperation(TestcaseBase):
self._connect()
c_name = cf.gen_unique_str(prefix)
self.connection_wrap.remove_connection(ct.default_alias)
res_list = self.connection_wrap.list_connections()
res_list, _ = self.connection_wrap.list_connections()
assert ct.default_alias not in res_list
ex, check = self.collection_wrap.init_collection(c_name, schema=default_schema,
check_task=CheckTasks.err_res)
assert "There is no connection with alias '{}'".format(ct.default_alias) in str(ex)
error = {ct.err_code: 0, ct.err_msg: "There is no connection with alias '{}'".format(ct.default_alias)}
self.collection_wrap.init_collection(c_name, schema=default_schema,
check_task=CheckTasks.err_res, check_items=error)
assert self.collection_wrap.collection is None
@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.xfail(reason="issue #5667")
def test_collection_multi_create_drop(self):
"""
target: test cycle creation and deletion of multiple collections
@ -761,10 +773,10 @@ class TestCollectionOperation(TestcaseBase):
c_num = 20
for _ in range(c_num):
c_name = cf.gen_unique_str(prefix)
collection, _ = self.collection_wrap.init_collection(c_name, schema=default_schema)
assert_default_collection(collection, c_name)
collection.drop()
assert c_name not in self.utility_wrap.list_collections()
self.collection_wrap.init_collection(c_name, schema=default_schema)
assert_default_collection(self.collection_wrap, c_name)
self.collection_wrap.drop()
assert c_name not in self.utility_wrap.list_collections()[0]
@pytest.mark.tags(CaseLabel.L1)
def test_collection_dup_name_drop(self):
@ -775,15 +787,14 @@ class TestCollectionOperation(TestcaseBase):
expected: collection dropped
"""
self._connect()
collection = self._collection()
assert_default_collection(collection)
dup_collection, _ = self.collection_wrap.init_collection(collection.name)
assert_default_collection(dup_collection, collection.name)
dup_collection.drop()
has, _ = self.utility_wrap.has_collection(collection.name, check_res=CheckTasks.err_res)
assert not has
with pytest.raises(Exception, match="can't find collection"):
collection.num_entities
collection_w = self.init_collection_wrap()
assert_default_collection(collection_w)
self.collection_wrap.init_collection(collection_w.name)
assert_default_collection(self.collection_wrap, collection_w.name)
self.collection_wrap.drop()
assert not self.utility_wrap.has_collection(collection_w.name)[0]
error = {ct.err_code: 0, ct.err_msg: "can't find collection"}
self.collection_wrap.has_partition("p", check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_created_by_dataframe(self):
@ -793,13 +804,12 @@ class TestCollectionOperation(TestcaseBase):
expected: create successfully
"""
conn = self._connect()
nb = ct.default_nb
c_name = cf.gen_unique_str(prefix)
df = cf.gen_default_dataframe_data(nb)
df = cf.gen_default_dataframe_data(nb=ct.default_nb)
schema = cf.gen_default_collection_schema()
collection, _ = self.collection_wrap.init_collection(name=c_name, data=df)
self.collection_wrap.init_collection(name=c_name, data=df)
conn.flush([c_name])
assert_default_collection(collection, exp_name=c_name, exp_num=nb, exp_schema=schema)
assert_default_collection(self.collection_wrap, exp_name=c_name, exp_num=ct.default_nb, exp_schema=schema)
@pytest.mark.tags(CaseLabel.L0)
def test_collection_created_by_empty_dataframe(self):
@ -811,13 +821,14 @@ class TestCollectionOperation(TestcaseBase):
self._connect()
c_name = cf.gen_unique_str(prefix)
data = pd.DataFrame()
ex, _ = self.collection_wrap.init_collection(name=c_name, schema=None,
data=data,
check_task=CheckTasks.err_res)
assert "The field of the schema cannot be empty" in str(ex)
error = {ct.err_code: 0, ct.err_msg: "The field of the schema cannot be empty"}
self.collection_wrap.init_collection(name=c_name, schema=None, data=data,
check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_created_by_invalid_dataframe(self, get_invalid_df):
@pytest.mark.parametrize("df", [pd.DataFrame({"date": pd.date_range('20210101', periods=3)}),
pd.DataFrame({'%$#': cf.gen_vectors(3, 2)})])
def test_collection_created_by_invalid_dataframe(self, df):
"""
target: test collection with invalid dataframe
method: create with invalid dataframe
@ -825,13 +836,37 @@ class TestCollectionOperation(TestcaseBase):
"""
self._connect()
c_name = cf.gen_unique_str(prefix)
ex, _ = self.collection_wrap.init_collection(name=c_name, schema=None,
data=get_invalid_df,
check_task=CheckTasks.err_res)
message_one = "Cannot infer schema from empty dataframe"
message_two = "Field name should not be empty"
message_three = "Invalid field name"
assert message_one or message_two or message_three in str(ex)
error = {ct.err_code: 0, ct.err_msg: "Invalid field name"}
self.collection_wrap.init_collection(name=c_name, schema=None, data=df,
check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_construct_only_column_dataframe(self):
"""
target: test collection with dataframe only columns
method: dataframe only has columns
expected: raise exception
"""
self._connect()
c_name = cf.gen_unique_str(prefix)
df = pd.DataFrame(columns=[ct.default_int64_field_name, ct.default_float_vec_field_name])
error = {ct.err_code: 0, ct.err_msg: "Cannot infer schema from empty dataframe"}
self.collection_wrap.init_collection(name=c_name, schema=None, data=df,
check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_construct_no_column_dataframe(self):
"""
target: test collection with dataframe without columns
method: dataframe without columns
expected: raise exception
"""
self._connect()
c_name = cf.gen_unique_str(prefix)
df = pd.DataFrame({' ': cf.gen_vectors(3, 2)})
error = {ct.err_code: 0, ct.err_msg: "Field name should not be empty"}
self.collection_wrap.init_collection(name=c_name, schema=None, data=df,
check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_created_by_inconsistent_dataframe(self):
@ -845,10 +880,9 @@ class TestCollectionOperation(TestcaseBase):
# one field different type df
mix_data = [(1, 2., [0.1, 0.2]), (2, 3., 4)]
df = pd.DataFrame(data=mix_data, columns=list("ABC"))
ex, _ = self.collection_wrap.init_collection(name=c_name, schema=None,
data=df,
check_task=CheckTasks.err_res)
assert "The data in the same column must be of the same type" in str(ex)
error = {ct.err_code: 0, ct.err_msg: "The data in the same column must be of the same type"}
self.collection_wrap.init_collection(name=c_name, schema=None, data=df,
check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L0)
def test_collection_created_by_non_dataframe(self, get_non_df):
@ -859,10 +893,9 @@ class TestCollectionOperation(TestcaseBase):
"""
self._connect()
c_name = cf.gen_unique_str(prefix)
ex, _ = self.collection_wrap.init_collection(name=c_name, schema=None,
data=get_non_df,
check_task=CheckTasks.err_res)
assert "Data of not pandas.DataFrame type should bepassed into the schema" in str(ex)
error = {ct.err_code: 0, ct.err_msg: "Data of not pandas.DataFrame type should bepassed into the schema"}
self.collection_wrap.init_collection(name=c_name, schema=None, data=get_non_df,
check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L0)
def test_collection_created_by_data_list(self):
@ -874,10 +907,9 @@ class TestCollectionOperation(TestcaseBase):
self._connect()
c_name = cf.gen_unique_str(prefix)
data = cf.gen_default_list_data(nb=100)
ex, _ = self.collection_wrap.init_collection(name=c_name, schema=None,
data=data,
check_task=CheckTasks.err_res)
assert "Data of not pandas.DataFrame type should bepassed into the schema" in str(ex)
error = {ct.err_code: 0, ct.err_msg: "Data of not pandas.DataFrame type should bepassed into the schema"}
self.collection_wrap.init_collection(name=c_name, schema=None, data=data,
check_task=CheckTasks.err_res, check_items=error)
@pytest.mark.tags(CaseLabel.L1)
def test_collection_after_drop(self):
@ -886,17 +918,16 @@ class TestCollectionOperation(TestcaseBase):
method: 1. create a 2. drop a 3, re-create a
expected: no exception
"""
collection = self._collection()
assert_default_collection(collection)
c_name = collection.name
collection.drop()
assert not self.utility_wrap.has_collection(c_name)[0]
re_collection = self._collection(name=c_name)
assert_default_collection(re_collection, c_name)
assert self.utility_wrap.has_collection(c_name)[0]
collection_w = self.init_collection_wrap()
assert_default_collection(collection_w)
collection_w.drop()
assert not self.utility_wrap.has_collection(collection_w.name)[0]
collection_w2 = self.init_collection_wrap(name=collection_w.name)
assert_default_collection(collection_w2, collection_w.name)
assert self.utility_wrap.has_collection(collection_w.name)[0]
@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.xfail(reason="issue #5414")
@pytest.mark.xfail(reason="issue #5675")
def test_collection_binary_created_by_dataframe(self):
"""
target: test collection with dataframe
@ -904,12 +935,11 @@ class TestCollectionOperation(TestcaseBase):
expected: create successfully
"""
self._connect()
nb = ct.default_nb
c_name = cf.gen_unique_str(prefix)
df = cf.gen_default_binary_dataframe_data(nb)
df, _ = cf.gen_default_binary_dataframe_data(ct.default_nb)
schema = cf.gen_default_binary_collection_schema()
collection, _ = self.collection_wrap.init_collection(name=c_name, data=df)
assert_default_collection(collection, exp_name=c_name, exp_num=nb, exp_schema=schema)
self.collection_wrap.init_collection(name=c_name, data=df)
assert_default_collection(self.collection_wrap, exp_name=c_name, exp_num=ct.default_nb, exp_schema=schema)
@pytest.mark.tags(CaseLabel.L0)
def test_collection_binary_created_by_data_list(self):
@ -920,7 +950,7 @@ class TestCollectionOperation(TestcaseBase):
"""
self._connect()
c_name = cf.gen_unique_str(prefix)
data = cf.gen_default_binary_list_data(nb=100)
ex, _ = self.collection_wrap.init_collection(name=c_name, schema=None, data=data,
check_task=CheckTasks.err_res)
assert "Data of not pandas.DataFrame type should bepassed into the schema" in str(ex)
data, _ = cf.gen_default_binary_list_data(nb=100)
error = {ct.err_code: 0, ct.err_msg: "Data of not pandas.DataFrame type should bepassed into the schema"}
self.collection_wrap.init_collection(name=c_name, schema=None, data=data,
check_task=CheckTasks.err_res, check_items=error)