def test_collection_dup_name_new_schema(self): """ target: test collection with dup name and new schema method: 1.create collection with default schema 2. collection with dup name and new schema expected: raise exception """ self._connect() c_name = cf.gen_unique_str(prefix) self.init_collection_wrap( name=c_name, check_task=CheckTasks.check_collection_property, check_items={ exp_name: c_name, exp_schema: default_schema }) fields = [cf.gen_int64_field()] schema = cf.gen_collection_schema(fields=fields) 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)
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 = cf.gen_unique_str(prefix) schema = cf.gen_collection_schema([cf.gen_int64_field()]) 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)
def test_collection_empty_fields(self): """ target: test collection with empty fields method: create collection with fields = [] expected: exception """ self._connect() c_name = cf.gen_unique_str(prefix) schema = cf.gen_collection_schema(fields=[]) 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)
def test_collection_only_vector(self, field): """ target: test collection just with vec field method: create with float-vec fields expected: no exception """ self._connect() c_name = cf.gen_unique_str(prefix) schema = cf.gen_collection_schema(fields=[field]) self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.check_collection_property, check_items={exp_name: c_name, exp_schema: schema})
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 = cf.gen_unique_str(prefix) schema = cf.gen_collection_schema([cf.gen_int64_field()]) ex, _ = self.collection.collection_init(c_name, schema=schema) assert "must" in str(ex)
def test_collection_field_float_type(self): """ target: test collection with float type method: create field with float type expected: """ self._connect() c_name = cf.gen_unique_str(prefix) 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)
def test_collection_mix_vectors(self): """ target: test collection with mix vectors method: create with float and binary vec expected: raise exception """ self._connect() 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) self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.check_collection_property, check_items={exp_name: c_name, exp_schema: schema})
def test_collection_vector_out_bounds_dim(self, dim): """ target: test collection with out of bounds dim method: invalid dim -1 and 32759 expected: raise exception """ self._connect() 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]) 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)
def test_collection_vector_without_dim(self, dtype): """ target: test collection without dimension method: define vector field without dim expected: raise exception """ self._connect() c_name = cf.gen_unique_str(prefix) float_vec_field, _ = self.field_schema_wrap.init_field_schema(name="vec", dtype=dtype) schema = cf.gen_collection_schema(fields=[float_vec_field]) 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)
def test_collection_vector_invalid_dim(self, get_invalid_dim): """ target: test collection with invalid dimension method: define float-vec field with invalid dimension expected: raise exception """ self._connect() 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]) 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)
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)
def test_collection_multi_float_vectors(self): """ target: test collection with multi float vectors method: create collection with two float-vec fields expected: raise exception """ self._connect() 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) self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.check_collection_property, check_items={exp_name: c_name, exp_schema: schema})
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)
def test_collection_non_vector_field_dim(self): """ target: test collection with dim for non-vector field method: define int64 field with dim expected: no exception """ self._connect() c_name = cf.gen_unique_str(prefix) 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]) self.collection_wrap.init_collection(c_name, schema=schema, check_task=CheckTasks.check_collection_property, check_items={exp_name: c_name, exp_schema: schema})
def test_collection_primary_inconsistent(self): """ target: test collection with different primary field setting method: 1. set A field is_primary 2. set primary_field is B expected: raise exception """ self._connect() c_name = cf.gen_unique_str(prefix) 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") 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)
def test_collection_multi_primary_fields(self): """ target: test collection with multi primary method: collection with two primary fields expected: raise exception """ self._connect() c_name = cf.gen_unique_str(prefix) 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]) 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)
def test_collection_unsupported_primary_field(self, get_unsupported_primary_field): """ target: test collection with unsupported primary field type method: specify non-int64 as primary field expected: raise exception """ self._connect() c_name = cf.gen_unique_str(prefix) field = get_unsupported_primary_field vec_field = cf.gen_float_vec_field(name="vec") schema = cf.gen_collection_schema(fields=[field, vec_field], primary_field=field.name) 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)
def test_collection_field_primary_false(self): """ target: test collection with primary false method: define field with is_primary false expected: no exception """ self._connect() c_name = cf.gen_unique_str(prefix) 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]) self.collection_wrap.init_collection(c_name, schema=schema) assert self.collection_wrap.primary_field is None assert self.collection_wrap.schema.auto_id
def test_collection_dup_field(self): """ target: test collection with dup field name method: Two FieldSchema have same name expected: raise exception """ self._connect() c_name = cf.gen_unique_str(prefix) field_one = cf.gen_int64_field() field_two = cf.gen_int64_field() schema = cf.gen_collection_schema(fields=[field_one, field_two]) 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]
def test_collection_dup_name_new_schema(self): """ target: test collection with dup name and new schema method: 1.create collection with default schema 2. collection with dup name and new schema expected: raise exception """ self._connect() c_name, collection = self._collection() assert_default_collection(collection, c_name) fields = [cf.gen_int64_field()] schema = cf.gen_collection_schema(fields=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)
def test_query_expr_non_primary_field(self): """ target: test query on non-primary field method: query on non-primary int field expected: raise exception """ fields = [cf.gen_int64_field(), cf.gen_int64_field(name='int2', is_primary=True), cf.gen_float_vec_field()] schema = cf.gen_collection_schema(fields) collection_w = self.init_collection_wrap(name=cf.gen_unique_str(prefix), schema=schema) nb = 100 data = [[i for i in range(nb)], [i for i in range(nb)], cf.gen_vectors(nb, ct.default_dim)] collection_w.insert(data) assert collection_w.num_entities == nb assert collection_w.primary_field.name == 'int2' error = {ct.err_code: 1, ct.err_msg: "column is not primary key"} collection_w.query(default_term_expr, check_task=CheckTasks.err_res, check_items=error)