def test_round_trip_annotations(): """Test that annotations can make the round trip from a simple dictionary to the synapse format and back""" a = dict(foo=1234, zoo=[123.1, 456.2, 789.3], species='Moose', birthdays=[Datetime(1969, 4, 28), Datetime(1973, 12, 8), Datetime(2008, 1, 3), Datetime(2013, 3, 15)]) sa = to_synapse_annotations(a) a2 = from_synapse_annotations(sa) a = a2
def test_mixed_annotations(): """test that to_synapse_annotations will coerce a list of mixed types to strings""" a = dict(foo=[1, 'a', Datetime(1969, 4, 28, 11, 47)]) sa = to_synapse_annotations(a) a2 = from_synapse_annotations(sa) assert a2['foo'][0] == '1' assert a2['foo'][1] == 'a' assert a2['foo'][2].find('1969') > -1
def test_from_synapse_annotations__empty(): ssa = {'id': 'syn123', 'etag': '7bdb83e9-a50a-46e4-987a-4962559f090f', 'annotations': {}} annos = from_synapse_annotations(ssa) assert {} == annos assert 'syn123' == annos.id assert '7bdb83e9-a50a-46e4-987a-4962559f090f' == annos.etag
def test_mixed_annotations(): """test that to_synapse_annotations will coerce a list of mixed types to strings""" a = dict(foo=[1, 'a', Datetime(1969, 4, 28, 11, 47)]) sa = to_synapse_annotations(a) a2 = from_synapse_annotations(sa) assert_equals(a2['foo'][0], '1') assert_equals(a2['foo'][1], 'a') assert_greater(a2['foo'][2].find('1969'), -1)
def test_mixed_annotations(): """test that to_synapse_annotations will coerce a list of mixed types to strings""" a = dict(foo=[1, 'a', Datetime(1969,4,28,11,47)]) sa = to_synapse_annotations(a) # print(sa) a2 = from_synapse_annotations(sa) # print(a2) assert a2['foo'][0] == '1' assert a2['foo'][1] == 'a' assert a2['foo'][2].find('1969') > -1
def test_mixed_annotations(): """test that to_synapse_annotations will coerce a list of mixed types to strings""" a = Annotations('syn123', '7bdb83e9-a50a-46e4-987a-4962559f090f', {'foo': [1, 'a', Datetime(1969, 4, 28, 11, 47)]}) sa = to_synapse_annotations(a) a2 = from_synapse_annotations(sa) assert a2['foo'][0] == '1' assert a2['foo'][1] == 'a' assert a2['foo'][2].find('1969') > -1 assert 'syn123' == a2.id assert '7bdb83e9-a50a-46e4-987a-4962559f090f' == a2.etag
def test_annotation_name_collision(): """Test handling of a name collisions between typed user generated and untyped system generated annotations, see SYNPY-203 and PLFM-3248""" ## order is important: to repro the erro, the key uri has to come before stringAnnotations sa = OrderedDict() sa[u'uri'] = u'/entity/syn47396/annotations' sa[u'doubleAnnotations'] = {} sa[u'longAnnotations'] = {} sa[u'stringAnnotations'] = { 'tissueType': ['Blood'], 'uri': ['/repo/v1/dataset/47396']} sa[u'creationDate'] = u'1321168909232' sa[u'id'] = u'syn47396' a = from_synapse_annotations(sa) assert a['tissueType'] == ['Blood']
def _convert_to_annotation_cls( id: str, etag: str, values: typing.Union[Annotations, dict]) -> Annotations: """Convert synapse style annotation or dict to synapseclient.Annotation :param id: The id of the entity / submission :param etag: The etag of the entity / submission :param values: A synapseclient.Annotations or dict :returns: A synapseclient.Annotations """ if isinstance(values, Annotations): return values if is_synapse_annotations(values): values = from_synapse_annotations(values) else: values = Annotations(id=id, etag=etag, values=values) return values
def test_round_trip_annotations(): """Test that annotations can make the round trip from a simple dictionary to the synapse format and back""" a = Annotations( 'syn123', '7bdb83e9-a50a-46e4-987a-4962559f090f', { 'foo': [1234], 'zoo': [123.1, 456.2, 789.3], 'species': ['Moose'], 'birthdays': [ Datetime(1969, 4, 28), Datetime(1973, 12, 8), Datetime(2008, 1, 3), Datetime(2013, 3, 15) ] }) sa = to_synapse_annotations(a) a2 = from_synapse_annotations(sa) assert a == a2 assert a.id == a2.id assert a.etag == a2.etag
def _convert_to_annotation_cls( sub_status: SubmissionStatus, values: typing.Union[Annotations, dict]) -> Annotations: """Convert synapse style annotation or dict to synapseclient.Annotation Args: sub_status: A synapseclient.SubmissionStatus values: A synapseclient.Annotations or dict Returns: A synapseclient.Annotations """ if isinstance(values, Annotations): return values if is_synapse_annotations(values): values = from_synapse_annotations(values) else: values = Annotations(id=sub_status.id, etag=sub_status.etag, values=values) return values