mirror of https://github.com/milvus-io/milvus.git
Add cases for creating collections (#5286)
- add cases for creating collections - change unique str from var to function - improve coding standards See also: #5273 #5285 Signed-off-by: ThreadDao yufen.zong@zilliz.compull/5289/head
parent
fc630bc1c8
commit
9b37cab922
|
@ -103,7 +103,7 @@ class ApiReq(Base):
|
|||
res = self.connection.create_connection(alias='default')
|
||||
return res
|
||||
|
||||
def _collection(self, name=get_unique_str, data=None, schema=None, check_res=None, **kwargs):
|
||||
def _collection(self, name=gen_unique_str(), data=None, schema=None, check_res=None, **kwargs):
|
||||
""" Testing func """
|
||||
self._connect()
|
||||
res = self.collection.collection_init(name=name, data=data, schema=schema, check_res=check_res, **kwargs)
|
||||
|
|
|
@ -6,40 +6,43 @@ from sklearn import preprocessing
|
|||
|
||||
from pymilvus_orm.types import DataType
|
||||
from pymilvus_orm.schema import CollectionSchema, FieldSchema
|
||||
|
||||
from common.common_type import int_field_desc, float_field_desc, float_vec_field_desc, binary_vec_field_desc
|
||||
from common.common_type import default_nb, all_index_types, binary_support, default_index_params
|
||||
from common.common_type import default_int64_field, default_float_field, default_float_vec_field_name, default_binary_vec_field_name
|
||||
from common.common_type import default_dim, collection_desc, default_collection_desc, default_binary_desc
|
||||
from utils.util_log import test_log as log
|
||||
from common.common_type import *
|
||||
|
||||
"""" Methods of processing data """
|
||||
l2 = lambda x, y: np.linalg.norm(np.array(x) - np.array(y))
|
||||
|
||||
get_unique_str = "test_" + "".join(random.choice(string.ascii_letters + string.digits) for _ in range(8))
|
||||
|
||||
def gen_unique_str(str_value=None):
|
||||
prefix = "".join(random.choice(string.ascii_letters + string.digits) for _ in range(8))
|
||||
return "test_" + prefix if str_value is None else str_value + "_" + prefix
|
||||
|
||||
|
||||
def gen_int64_field(is_primary=False):
|
||||
description = "int64 type field"
|
||||
def gen_int64_field(is_primary=False, description=int_field_desc):
|
||||
int64_field = FieldSchema(name=default_int64_field, dtype=DataType.INT64, description=description,
|
||||
is_primary=is_primary)
|
||||
return int64_field
|
||||
|
||||
|
||||
def gen_float_field(is_primary=False):
|
||||
description = "float type field"
|
||||
def gen_float_field(is_primary=False, description=float_field_desc):
|
||||
float_field = FieldSchema(name=default_float_field, dtype=DataType.FLOAT, description=description,
|
||||
is_primary=is_primary)
|
||||
return float_field
|
||||
|
||||
|
||||
def gen_float_vec_field(is_primary=False):
|
||||
description = "float vector type field"
|
||||
def gen_float_vec_field(is_primary=False, dim=default_dim, description=float_vec_field_desc):
|
||||
float_vec_field = FieldSchema(name=default_float_vec_field_name, dtype=DataType.FLOAT_VECTOR,
|
||||
description=description, dim=default_dim, is_primary=is_primary)
|
||||
description=description, dim=dim, is_primary=is_primary)
|
||||
return float_vec_field
|
||||
|
||||
|
||||
def gen_binary_vec_field(is_primary=False):
|
||||
description = "binary vector type field"
|
||||
def gen_binary_vec_field(is_primary=False, dim=default_dim, description=binary_vec_field_desc):
|
||||
binary_vec_field = FieldSchema(name=default_binary_vec_field_name, dtype=DataType.BINARY_VECTOR,
|
||||
description=description, is_primary=is_primary)
|
||||
description=description, dim=dim, is_primary=is_primary)
|
||||
return binary_vec_field
|
||||
|
||||
|
||||
|
@ -49,30 +52,17 @@ def gen_default_collection_schema(description=default_collection_desc, primary_f
|
|||
return schema
|
||||
|
||||
|
||||
def gen_collection_schema(fields, description="collection", **kwargs):
|
||||
def gen_collection_schema(fields, description=collection_desc, **kwargs):
|
||||
schema = CollectionSchema(fields=fields, description=description, **kwargs)
|
||||
return schema
|
||||
|
||||
|
||||
def gen_default_binary_collection_schema():
|
||||
def gen_default_binary_collection_schema(description=default_binary_desc, primary_field=None):
|
||||
fields = [gen_int64_field(), gen_float_field(), gen_binary_vec_field()]
|
||||
binary_schema = CollectionSchema(fields=fields, description="default binary collection")
|
||||
binary_schema = CollectionSchema(fields=fields, description=description, primary_field=primary_field)
|
||||
return binary_schema
|
||||
|
||||
|
||||
def get_binary_default_fields(auto_id=True):
|
||||
default_fields = {
|
||||
"fields": [
|
||||
{"name": "int64", "type": DataType.INT64},
|
||||
{"name": "float", "type": DataType.FLOAT},
|
||||
{"name": default_binary_vec_field_name, "type": DataType.BINARY_VECTOR, "params": {"dim": default_dim}}
|
||||
],
|
||||
"segment_row_limit": default_segment_row_limit,
|
||||
"auto_id": auto_id
|
||||
}
|
||||
return default_fields
|
||||
|
||||
|
||||
def gen_simple_index():
|
||||
index_params = []
|
||||
for i in range(len(all_index_types)):
|
||||
|
|
|
@ -22,6 +22,12 @@ default_partition_name = "_default"
|
|||
default_tag = "1970_01_01"
|
||||
row_count = "row_count"
|
||||
default_collection_desc = "default collection"
|
||||
default_binary_desc = "default binary collection"
|
||||
collection_desc = "collection"
|
||||
int_field_desc = "int64 type field"
|
||||
float_field_desc = "float type field"
|
||||
float_vec_field_desc = "float vector type field"
|
||||
binary_vec_field_desc = "binary vector type field"
|
||||
|
||||
|
||||
"""" List of parameters used to pass """
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[pytest]
|
||||
|
||||
addopts = --host 192.168.1.240 --html=/Users/wt/Desktop/report.html
|
||||
;addopts = --host 192.168.1.242 --html=/tmp/report.html
|
||||
;addopts = --host 172.28.255.155 --html=/tmp/report.html
|
||||
# python3 -W ignore -m pytest
|
|
@ -1,16 +1,18 @@
|
|||
import pytest
|
||||
from base.client_request import ApiReq
|
||||
from common.common_type import get_invalid_strs, CaseLabel, default_int64_field, default_alias
|
||||
from utils.util_log import test_log as log
|
||||
from common.common_type import *
|
||||
from common.common_func import *
|
||||
from common.common_func import gen_default_collection_schema, gen_unique_str, gen_collection_schema
|
||||
from common.common_func import gen_int64_field, gen_float_vec_field
|
||||
|
||||
prefix = "collection"
|
||||
default_schema = gen_default_collection_schema()
|
||||
|
||||
|
||||
def assert_default_collection(collection, exp_name, exp_schema=default_schema, exp_num=0, exp_primary=None):
|
||||
assert collection.name == exp_name
|
||||
assert collection.description == exp_schema.description
|
||||
assert collection.schema == default_schema
|
||||
assert collection.schema == exp_schema
|
||||
if exp_num == 0:
|
||||
assert collection.is_empty
|
||||
assert collection.num_entities == exp_num
|
||||
|
@ -24,7 +26,7 @@ class TestCollectionParams(ApiReq):
|
|||
""" Test case of collection interface """
|
||||
|
||||
def teardown_method(self):
|
||||
if self.collection.collection is not None:
|
||||
if self.collection is not None and self.collection.collection is not None:
|
||||
self.collection.drop()
|
||||
|
||||
def setup_method(self):
|
||||
|
@ -37,6 +39,15 @@ class TestCollectionParams(ApiReq):
|
|||
def get_invalid_string(self, request):
|
||||
yield request.param
|
||||
|
||||
@pytest.fixture(
|
||||
scope="function",
|
||||
params=get_invalid_strs
|
||||
)
|
||||
def get_invalid_schema(self, request):
|
||||
if request.param is None:
|
||||
pytest.skip("None schema is valid")
|
||||
yield request.param
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L0)
|
||||
@pytest.mark.xfail(reason="issue #5224")
|
||||
def test_collection(self):
|
||||
|
@ -46,7 +57,7 @@ class TestCollectionParams(ApiReq):
|
|||
expected: assert collection property
|
||||
"""
|
||||
self._connect()
|
||||
c_name = get_unique_str
|
||||
c_name = gen_unique_str(prefix)
|
||||
collection, _ = self.collection.collection_init(c_name, data=None, schema=default_schema)
|
||||
assert_default_collection(collection, c_name)
|
||||
assert c_name in self.utility.list_collections()
|
||||
|
@ -84,8 +95,8 @@ class TestCollectionParams(ApiReq):
|
|||
expected: collection properties consistent
|
||||
"""
|
||||
self._connect()
|
||||
c_name = get_unique_str
|
||||
collection, _ = self.collection.collection_init(c_name, data=None, schema=default_schema)
|
||||
c_name = gen_unique_str(prefix)
|
||||
collection, _ = self.collection.collection_init(c_name, schema=default_schema)
|
||||
assert_default_collection(collection, c_name)
|
||||
dup_collection, _ = self.collection.collection_init(c_name)
|
||||
assert_default_collection(dup_collection, c_name)
|
||||
|
@ -103,7 +114,7 @@ class TestCollectionParams(ApiReq):
|
|||
expected: raise exception
|
||||
"""
|
||||
self._connect()
|
||||
c_name = get_unique_str
|
||||
c_name = gen_unique_str(prefix)
|
||||
collection, _ = self.collection.collection_init(c_name, data=None, schema=default_schema)
|
||||
assert_default_collection(collection, c_name)
|
||||
fields = [gen_int64_field()]
|
||||
|
@ -120,7 +131,7 @@ class TestCollectionParams(ApiReq):
|
|||
expected: raise exception
|
||||
"""
|
||||
self._connect()
|
||||
c_name = get_unique_str
|
||||
c_name = gen_unique_str(prefix)
|
||||
collection, _ = self.collection.collection_init(c_name, schema=default_schema)
|
||||
assert_default_collection(collection, c_name)
|
||||
schema = gen_default_collection_schema(primary_field=default_int64_field)
|
||||
|
@ -128,6 +139,94 @@ class TestCollectionParams(ApiReq):
|
|||
assert "The collection already exist, but the schema isnot the same as the passed in" in str(ex)
|
||||
assert collection.primary_field is None
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
def test_collection_dup_name_new_dim(self):
|
||||
"""
|
||||
target: test collection with dup name and new dim schema
|
||||
method: 1. default schema 2. schema with new dim
|
||||
expected: raise exception
|
||||
"""
|
||||
self._connect()
|
||||
c_name = gen_unique_str(prefix)
|
||||
new_dim = 120
|
||||
collection, _ = self.collection.collection_init(c_name, schema=default_schema)
|
||||
assert_default_collection(collection, c_name)
|
||||
schema = gen_default_collection_schema()
|
||||
new_fields = gen_float_vec_field(dim=new_dim)
|
||||
schema.fields[-1] = new_fields
|
||||
ex, _ = self.collection.collection_init(c_name, schema=schema)
|
||||
assert "The collection already exist, but the schema isnot the same as the passed in" in str(ex)
|
||||
assert collection.primary_field is None
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
def test_collection_dup_name_invalid_schema(self, get_invalid_schema):
|
||||
"""
|
||||
target: test collection with dup name and invalid schema
|
||||
method: 1. default schema 2. invalid schema
|
||||
expected: raise exception and
|
||||
"""
|
||||
self._connect()
|
||||
c_name = gen_unique_str(prefix)
|
||||
collection, _ = self.collection.collection_init(c_name, schema=default_schema)
|
||||
assert_default_collection(collection, c_name)
|
||||
ex, _ = self.collection.collection_init(c_name, schema=get_invalid_schema)
|
||||
assert "schema type must be schema.CollectionSchema" in str(ex)
|
||||
assert_default_collection(collection, c_name)
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
@pytest.mark.xfail(reason="issue #5231, #5241")
|
||||
def test_collection_dup_name_same_schema(self):
|
||||
"""
|
||||
target: test collection with dup name and same schema
|
||||
method: dup name and same schema
|
||||
expected: two collection object is available
|
||||
"""
|
||||
self._connect()
|
||||
c_name = gen_unique_str(prefix)
|
||||
collection, _ = self.collection.collection_init(c_name, schema=default_schema)
|
||||
assert_default_collection(collection, c_name)
|
||||
dup_collection, _ = self.collection.collection_init(c_name, schema=default_schema)
|
||||
assert_default_collection(dup_collection, c_name)
|
||||
assert id(collection) == id(dup_collection)
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L0)
|
||||
def test_collection_none_schema(self):
|
||||
"""
|
||||
target: test collection with none schema
|
||||
method: create collection with none schema
|
||||
expected: raise exception
|
||||
"""
|
||||
self._connect()
|
||||
c_name = gen_unique_str(prefix)
|
||||
ex, _ = self.collection.collection_init(c_name, schema=None)
|
||||
assert "Collection missing schema" in str(ex)
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L0)
|
||||
def test_collection_invalid_schema(self, get_invalid_schema):
|
||||
"""
|
||||
target: test collection with invalid schema
|
||||
method: create collection with non-CollectionSchema type schema
|
||||
expected: raise exception
|
||||
"""
|
||||
self._connect()
|
||||
c_name = gen_unique_str(prefix)
|
||||
ex, _ = self.collection.collection_init(c_name, schema=get_invalid_schema)
|
||||
assert "schema type must be schema.CollectionSchema" in str(ex)
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L0)
|
||||
@pytest.mark.xfail(reason="issue #5285")
|
||||
def test_collection_without_vectors(self):
|
||||
"""
|
||||
target: test collection without vectors
|
||||
method: create collection only with int field
|
||||
expected: raise exception
|
||||
"""
|
||||
self._connect()
|
||||
c_name = gen_unique_str(prefix)
|
||||
schema = gen_collection_schema([gen_int64_field()])
|
||||
ex, _ = self.collection.collection_init(c_name, schema=schema)
|
||||
assert "must" in str(ex)
|
||||
|
||||
|
||||
class TestCollectionOperation(ApiReq):
|
||||
"""
|
||||
|
@ -136,6 +235,8 @@ class TestCollectionOperation(ApiReq):
|
|||
******************************************************************
|
||||
"""
|
||||
|
||||
# #5237
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
def test_collection_without_connection(self):
|
||||
"""
|
||||
target: test collection without connection
|
||||
|
@ -143,10 +244,26 @@ class TestCollectionOperation(ApiReq):
|
|||
expected: raise exception
|
||||
"""
|
||||
self._connect()
|
||||
c_name = gen_unique_str(prefix)
|
||||
self.connection.remove_connection(default_alias)
|
||||
res_list = self.connection.list_connections()
|
||||
assert len(res_list) == 0
|
||||
c_name = get_unique_str
|
||||
assert default_alias not in res_list
|
||||
ex, check = self.collection.collection_init(c_name, schema=default_schema)
|
||||
assert "no connection" in str(ex)
|
||||
assert self.collection is None
|
||||
assert "There is no connection with alias '{}'".format(default_alias) in str(ex)
|
||||
assert self.collection.collection is None
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
def test_collection_multi_create_drop(self):
|
||||
"""
|
||||
target: test cycle creation and deletion of multiple collections
|
||||
method: in a loop, collections are created and deleted sequentially
|
||||
expected: no exception
|
||||
"""
|
||||
self._connect()
|
||||
c_num = 20
|
||||
for _ in range(c_num):
|
||||
c_name = gen_unique_str(prefix)
|
||||
collection, _ = self.collection.collection_init(c_name, schema=default_schema)
|
||||
assert_default_collection(collection, c_name)
|
||||
collection.drop()
|
||||
assert c_name not in self.utility.list_collections()
|
||||
|
|
Loading…
Reference in New Issue