diff --git a/api-openbis-python3-pybis/src/python/pybis/experiment.py b/api-openbis-python3-pybis/src/python/pybis/experiment.py index a7c9e50f61f43cb3f6ea5e8c3afdc7c320cb63d6..7e9f0bfd9f345c39e53c89f518eca1d6d9be65de 100644 --- a/api-openbis-python3-pybis/src/python/pybis/experiment.py +++ b/api-openbis-python3-pybis/src/python/pybis/experiment.py @@ -32,7 +32,7 @@ class Experiment( data_type = property_type['dataType'] if data_type in ("ARRAY_INTEGER", "ARRAY_REAL", "ARRAY_STRING", "ARRAY_TIMESTAMP"): value = self.formatter.to_array(data_type, value) - if "multiValue" in property_type: + elif "multiValue" in property_type: if property_type['multiValue'] is True: if type(value) is not list: value = [value] diff --git a/api-openbis-python3-pybis/src/python/pybis/property.py b/api-openbis-python3-pybis/src/python/pybis/property.py index 8a3317dc6b9553135010e2aed24cde76f2f9f4cf..e6fe02d6bfc02c98b012bc26ed253abd2247d181 100644 --- a/api-openbis-python3-pybis/src/python/pybis/property.py +++ b/api-openbis-python3-pybis/src/python/pybis/property.py @@ -134,12 +134,12 @@ class PropertyHolder: f"No such property: «{name}». Allowed properties are: {', '.join(self._property_names.keys())}" ) property_type = self._property_names[name] + data_type = property_type["dataType"] if "multiValue" in property_type and property_type["multiValue"] is not True and type( - value) == list: + value) == list and data_type.startswith('ARRAY_') is False: raise ValueError( f'Property type {property_type["code"]} is not a multi-value property!') - data_type = property_type["dataType"] if data_type == "CONTROLLEDVOCABULARY": terms = property_type["terms"] if "multiValue" in property_type and property_type["multiValue"] is True: diff --git a/api-openbis-python3-pybis/src/python/pybis/sample.py b/api-openbis-python3-pybis/src/python/pybis/sample.py index bd13d07113f5a4a292a345582686b5ee9e77e769..717355be8b71991f3b34e304936490374afefa58 100644 --- a/api-openbis-python3-pybis/src/python/pybis/sample.py +++ b/api-openbis-python3-pybis/src/python/pybis/sample.py @@ -96,7 +96,7 @@ class Sample(OpenBisObject, entity="sample", single_item_method_name="get_sample data_type = property_type['dataType'] if data_type in ("ARRAY_INTEGER", "ARRAY_REAL", "ARRAY_STRING", "ARRAY_TIMESTAMP"): value = self.formatter.to_array(data_type, value) - if "multiValue" in property_type: + elif "multiValue" in property_type: if property_type['multiValue'] is True: if type(value) is not list: value = [value] diff --git a/api-openbis-python3-pybis/src/python/tests/test_dataset.py b/api-openbis-python3-pybis/src/python/tests/test_dataset.py index 04425a08b62f7e132c0dde3992ff22534dea050b..c48c82bed785d48687a103b5a6400238e4a9503f 100644 --- a/api-openbis-python3-pybis/src/python/tests/test_dataset.py +++ b/api-openbis-python3-pybis/src/python/tests/test_dataset.py @@ -353,43 +353,44 @@ def create_array_properties(openbis, code_prefix): def test_dataset_array_properties(space): - create_array_properties(space.openbis, "DATASET") + timestamp = time.strftime("%a_%y%m%d_%H%M%S").lower() + create_array_properties(space.openbis, f"DATASET_{timestamp}") - dataset_code = 'TEST_ARRAY_DATASET' + dataset_code = f'TEST_ARRAY_DATASET_{timestamp}' dataset_type = space.openbis.new_dataset_type( code=dataset_code ) dataset_type.save() dataset_type.assign_property('$NAME') - dataset_type.assign_property('DATASET_ARRAY_INTEGER') - dataset_type.assign_property('DATASET_ARRAY_REAL') - dataset_type.assign_property('DATASET_ARRAY_STRING') - dataset_type.assign_property('DATASET_ARRAY_TIMESTAMP') - dataset_type.assign_property('DATASET_JSON') + dataset_type.assign_property(f'DATASET_{timestamp}_ARRAY_INTEGER') + dataset_type.assign_property(f'DATASET_{timestamp}_ARRAY_REAL') + dataset_type.assign_property(f'DATASET_{timestamp}_ARRAY_STRING') + dataset_type.assign_property(f'DATASET_{timestamp}_ARRAY_TIMESTAMP') + dataset_type.assign_property(f'DATASET_{timestamp}_JSON') testfile_path = os.path.join(os.path.dirname(__file__), "testdir/testfile") dataset = space.openbis.new_dataset( type=dataset_code, sample="/DEFAULT/DEFAULT/DEFAULT", files=[testfile_path], - props={'dataset_array_integer': [1, 2, 3]} + props={f'dataset_{timestamp}_array_integer': [1, 2, 3]} ) dataset.save() - dataset.props['dataset_array_integer'] = [3, 2, 1] - dataset.props['dataset_array_real'] = [3.1, 2.2, 1.3] - dataset.props['dataset_array_string'] = ["aa", "bb", "cc"] - dataset.props['dataset_array_timestamp'] = ['2023-05-18 11:17:03', '2023-05-18 11:17:04', + dataset.props[f'dataset_{timestamp}_array_integer'] = [3, 2, 1] + dataset.props[f'dataset_{timestamp}_array_real'] = [3.1, 2.2, 1.3] + dataset.props[f'dataset_{timestamp}_array_string'] = ["aa", "bb", "cc"] + dataset.props[f'dataset_{timestamp}_array_timestamp'] = ['2023-05-18 11:17:03', '2023-05-18 11:17:04', '2023-05-18 11:17:05'] - dataset.props['dataset_json'] = "{ \"key\": [1, 1, 1] }" + dataset.props[f'dataset_{timestamp}_json'] = "{ \"key\": [1, 1, 1] }" dataset.save() - assert dataset.props['dataset_array_integer'] == [3, 2, 1] - assert dataset.props['dataset_array_real'] == [3.1, 2.2, 1.3] - assert dataset.props['dataset_array_string'] == ["aa", "bb", "cc"] - assert dataset.props['dataset_json'] == "{ \"key\": [1, 1, 1] }" - assert dataset.props['dataset_array_timestamp'] == ['2023-05-18 11:17:03', + assert dataset.props[f'dataset_{timestamp}_array_integer'] == [3, 2, 1] + assert dataset.props[f'dataset_{timestamp}_array_real'] == [3.1, 2.2, 1.3] + assert dataset.props[f'dataset_{timestamp}_array_string'] == ["aa", "bb", "cc"] + assert dataset.props[f'dataset_{timestamp}_json'] == "{ \"key\": [1, 1, 1] }" + assert dataset.props[f'dataset_{timestamp}_array_timestamp'] == ['2023-05-18 11:17:03', '2023-05-18 11:17:04', '2023-05-18 11:17:05'] diff --git a/api-openbis-python3-pybis/src/python/tests/test_experiment.py b/api-openbis-python3-pybis/src/python/tests/test_experiment.py index 6963deae4e9005cdf827a651605e7d6b4a7c9503..5c1a24e7ad4fb300bfe3dc6016068cbdd9e867a7 100644 --- a/api-openbis-python3-pybis/src/python/tests/test_experiment.py +++ b/api-openbis-python3-pybis/src/python/tests/test_experiment.py @@ -152,35 +152,35 @@ def create_array_properties(openbis, code_prefix): def test_experiment_array_properties(space): + timestamp = time.strftime("%a_%y%m%d_%H%M%S").lower() + create_array_properties(space.openbis, f"EXPERIMENT_{timestamp}") - create_array_properties(space.openbis, "EXPERIMENT") - - collection_code = 'TEST_ARRAY_COLLECTION' + collection_code = f'TEST_ARRAY_COLLECTION_{timestamp}' experiment_type = space.openbis.new_experiment_type( collection_code, description=None, validationPlugin=None, ) experiment_type.save() - experiment_type.assign_property('EXPERIMENT_ARRAY_INTEGER') - experiment_type.assign_property('EXPERIMENT_ARRAY_REAL') - experiment_type.assign_property('EXPERIMENT_ARRAY_STRING') - experiment_type.assign_property('EXPERIMENT_ARRAY_TIMESTAMP') - experiment_type.assign_property('EXPERIMENT_JSON') + experiment_type.assign_property(f'EXPERIMENT_{timestamp}_ARRAY_INTEGER') + experiment_type.assign_property(f'EXPERIMENT_{timestamp}_ARRAY_REAL') + experiment_type.assign_property(f'EXPERIMENT_{timestamp}_ARRAY_STRING') + experiment_type.assign_property(f'EXPERIMENT_{timestamp}_ARRAY_TIMESTAMP') + experiment_type.assign_property(f'EXPERIMENT_{timestamp}_JSON') exp = space.openbis.new_experiment( code = 'EXP_PYTHON', type = collection_code, project = 'DEFAULT', - props = { 'experiment_array_integer': [1, 2, 3]}) + props = { f'experiment_{timestamp}_array_integer': [1, 2, 3]}) exp.save() - exp.props['experiment_array_integer'] = [3, 2, 1] - exp.props['experiment_array_real'] = [3.1, 2.2, 1.3] - exp.props['experiment_array_string'] = ["aa", "bb", "cc"] - exp.props['experiment_array_timestamp'] = ['2023-05-18 11:17:03', '2023-05-18 11:17:04', + exp.props[f'experiment_{timestamp}_array_integer'] = [3, 2, 1] + exp.props[f'experiment_{timestamp}_array_real'] = [3.1, 2.2, 1.3] + exp.props[f'experiment_{timestamp}_array_string'] = ["aa", "bb", "cc"] + exp.props[f'experiment_{timestamp}_array_timestamp'] = ['2023-05-18 11:17:03', '2023-05-18 11:17:04', '2023-05-18 11:17:05'] - exp.props['experiment_json'] = "{ \"key\": [1, 1, 1] }" + exp.props[f'experiment_{timestamp}_json'] = "{ \"key\": [1, 1, 1] }" exp.save() diff --git a/api-openbis-python3-pybis/src/python/tests/test_sample.py b/api-openbis-python3-pybis/src/python/tests/test_sample.py index 8dad5830d00314aaf4c18f1cb5804d01550fd33a..6d14be3dda482d488a2123dbaa34e8f834ad6594 100644 --- a/api-openbis-python3-pybis/src/python/tests/test_sample.py +++ b/api-openbis-python3-pybis/src/python/tests/test_sample.py @@ -243,9 +243,10 @@ def create_array_properties(openbis, code_prefix): def test_sample_array_properties(space): - create_array_properties(space.openbis, "SAMPLE") + timestamp = time.strftime("%a_%y%m%d_%H%M%S").lower() + create_array_properties(space.openbis, f"SAMPLE_{timestamp}") - sample_code = 'TEST_ARRAY_SAMPLE' + sample_code = f'TEST_ARRAY_SAMPLE_{timestamp}' sample_type = space.openbis.new_sample_type( sample_code, generatedCodePrefix='S-', @@ -254,29 +255,29 @@ def test_sample_array_properties(space): ) sample_type.save() - sample_type.assign_property('SAMPLE_ARRAY_INTEGER') - sample_type.assign_property('SAMPLE_ARRAY_REAL') - sample_type.assign_property('SAMPLE_ARRAY_STRING') - sample_type.assign_property('SAMPLE_ARRAY_TIMESTAMP') - sample_type.assign_property('SAMPLE_JSON') + sample_type.assign_property(f'SAMPLE_{timestamp}_ARRAY_INTEGER') + sample_type.assign_property(f'SAMPLE_{timestamp}_ARRAY_REAL') + sample_type.assign_property(f'SAMPLE_{timestamp}_ARRAY_STRING') + sample_type.assign_property(f'SAMPLE_{timestamp}_ARRAY_TIMESTAMP') + sample_type.assign_property(f'SAMPLE_{timestamp}_JSON') sample = space.openbis.new_sample( type=sample_code, experiment='/DEFAULT/DEFAULT/DEFAULT', - props={'sample_array_integer': [1, 2, 3]}) + props={f'sample_{timestamp}_array_integer': [1, 2, 3]}) sample.save() - assert sample.props['sample_array_integer'] == [1, 2, 3] + assert sample.props[f'sample_{timestamp}_array_integer'] == [1, 2, 3] - sample.props['sample_array_integer'] = [3, 2, 1] - sample.props['sample_array_real'] = [3.1, 2.2, 1.3] - sample.props['sample_array_string'] = ["aa", "bb", "cc"] - sample.props['sample_array_timestamp'] = ['2023-05-18 11:17:03', '2023-05-18 11:17:04', + sample.props[f'sample_{timestamp}_array_integer'] = [3, 2, 1] + sample.props[f'sample_{timestamp}_array_real'] = [3.1, 2.2, 1.3] + sample.props[f'sample_{timestamp}_array_string'] = ["aa", "bb", "cc"] + sample.props[f'sample_{timestamp}_array_timestamp'] = ['2023-05-18 11:17:03', '2023-05-18 11:17:04', '2023-05-18 11:17:05'] - sample.props['sample_json'] = "{ \"key\": [1, 1, 1] }" + sample.props[f'sample_{timestamp}_json'] = "{ \"key\": [1, 1, 1] }" sample.save() - assert sample.props['sample_array_integer'] == [3, 2, 1] + assert sample.props[f'sample_{timestamp}_array_integer'] == [3, 2, 1] def test_create_sample_type_assign_property(space):