예제 #1
0
def test_to_synapse_annotations__called_convert_to_annotations_list(mock_convert_to_annotations_list):
    """Test the helper function _convert_to_annotations_list called properly"""
    a = Annotations('syn123', '7bdb83e9-a50a-46e4-987a-4962559f090f',
                    {'foo': 'bar', 'zoo': ['zing', 'zaboo'], 'species': 'Platypus'})
    to_synapse_annotations(a)
    mock_convert_to_annotations_list.assert_called_once_with({'foo': 'bar', 'zoo': ['zing', 'zaboo'],
                                                              'species': 'Platypus'})
예제 #2
0
def test_idempotent_annotations():
    """test that to_synapse_annotations won't mess up a dictionary that's already in the synapse format"""
    a = dict(species='Moose', n=42, birthday=Datetime(1969, 4, 28))
    sa = to_synapse_annotations(a)
    a2 = dict()
    a2.update(sa)
    sa2 = to_synapse_annotations(a2)
    assert_equals(sa, sa2)
예제 #3
0
def test_idempotent_annotations():
    """test that to_synapse_annotations won't mess up a dictionary that's already in the synapse format"""
    a = Annotations('syn123', '7bdb83e9-a50a-46e4-987a-4962559f090f',
                    {'species': 'Moose', 'n': 42, 'birthday': Datetime(1969, 4, 28), 'fact': True})
    sa = to_synapse_annotations(a)
    a2 = {}
    a2.update(sa)
    sa2 = to_synapse_annotations(a2)
    assert sa == sa2
예제 #4
0
def test_annotations_unicode():
    a = Annotations(
        'syn123', '7bdb83e9-a50a-46e4-987a-4962559f090f', {
            'files': [u'文件.txt'],
            'cacheDir': u'/Users/chris/.synapseCache/python/syn1809087',
            u'foo': 1266
        })
    sa = to_synapse_annotations(a)
    expected = {
        'id': 'syn123',
        'etag': '7bdb83e9-a50a-46e4-987a-4962559f090f',
        'annotations': {
            'cacheDir': {
                'type': 'STRING',
                'value': ['/Users/chris/.synapseCache/python/syn1809087']
            },
            'files': {
                'type': 'STRING',
                'value': ['文件.txt']
            },
            'foo': {
                'type': 'LONG',
                'value': ['1266']
            }
        }
    }
    assert expected == sa
예제 #5
0
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
예제 #6
0
def test_annotations():
    """Test string annotations"""
    a = Annotations('syn123', '7bdb83e9-a50a-46e4-987a-4962559f090f', {
        'foo': 'bar',
        'zoo': ['zing', 'zaboo'],
        'species': 'Platypus'
    })
    sa = to_synapse_annotations(a)
    expected = {
        'id': 'syn123',
        'etag': '7bdb83e9-a50a-46e4-987a-4962559f090f',
        'annotations': {
            'foo': {
                'value': ['bar'],
                'type': 'STRING'
            },
            'zoo': {
                'value': ['zing', 'zaboo'],
                'type': 'STRING'
            },
            'species': {
                'value': ['Platypus'],
                'type': 'STRING'
            }
        }
    }
    assert expected == sa
def test_annotations():
    """Test string annotations"""
    a = dict(foo='bar', zoo=['zing', 'zaboo'], species='Platypus')
    sa = to_synapse_annotations(a)
    assert_equals(sa['stringAnnotations']['foo'], ['bar'])
    assert_equals(sa['stringAnnotations']['zoo'], ['zing', 'zaboo'])
    assert_equals(sa['stringAnnotations']['species'], ['Platypus'])
def test_annotations():
    """Test string annotations"""
    a = dict(foo='bar', zoo=['zing', 'zaboo'], species='Platypus')
    sa = to_synapse_annotations(a)
    assert sa['stringAnnotations']['foo'] == ['bar']
    assert sa['stringAnnotations']['zoo'] == ['zing', 'zaboo']
    assert sa['stringAnnotations']['species'] == ['Platypus']
def update_submission_status(sub_status: SubmissionStatus,
                             values: typing.Union[Annotations, dict],
                             status: str = None) -> SubmissionStatus:
    """Updates submission status and annotations

    Args:
        sub_status:  A synapseclient.SubmissionStatus
        values:  A synapseclient.Annotations or dict
        status: A submission status (e.g. RECEIVED, SCORED...)

    Returns:
        A updated synapseclient.SubmissionStatus

    """
    if status is not None:
        sub_status.status = status
    existing = sub_status.get("submissionAnnotations", {})
    # Convert to synapseclient.Annotation class
    existing_annotations = _convert_to_annotation_cls(sub_status, existing)
    new_annotations = _convert_to_annotation_cls(sub_status, values)
    # Can use dict.update to update annotations
    existing_annotations.update(new_annotations)
    # Must turn synapseclient.Annotation into a synapse style annotations
    syn_annotations = to_synapse_annotations(existing_annotations)
    sub_status.submissionAnnotations = syn_annotations
    return sub_status
예제 #10
0
def test_more_annotations():
    """Test long, float and data annotations"""
    a = dict(foo=1234,
             zoo=[123.1, 456.2, 789.3],
             species='Platypus',
             birthdays=[
                 Datetime(1969, 4, 28),
                 Datetime(1973, 12, 8),
                 Datetime(2008, 1, 3)
             ],
             test_boolean=True,
             test_mo_booleans=[False, True, True, False])
    sa = to_synapse_annotations(a)
    print sa
    assert sa['longAnnotations']['foo'] == [1234]
    assert sa['doubleAnnotations']['zoo'] == [123.1, 456.2, 789.3]
    assert sa['stringAnnotations']['species'] == ['Platypus']
    assert sa['stringAnnotations']['test_boolean'] == ['true']
    assert sa['stringAnnotations']['test_mo_booleans'] == [
        'false', 'true', 'true', 'false'
    ]

    ## this part of the test is kinda fragile. It it breaks again, it should be removed
    bdays = [
        utils.from_unix_epoch_time(t)
        for t in sa['dateAnnotations']['birthdays']
    ]
    assert all([
        t in bdays for t in
        [Datetime(1969, 4, 28),
         Datetime(1973, 12, 8),
         Datetime(2008, 1, 3)]
    ])
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)
    a2 = from_synapse_annotations(sa)
    assert a2['foo'][0] == '1'
    assert a2['foo'][1] == 'a'
    assert a2['foo'][2].find('1969') > -1
예제 #13
0
def test_to_synapse_annotations__empty():
    python_client_annos = Annotations('syn123', '7bdb83e9-a50a-46e4-987a-4962559f090f', {})
    assert (
        {
            'id': 'syn123',
            'etag': '7bdb83e9-a50a-46e4-987a-4962559f090f',
            'annotations': {}
        } == to_synapse_annotations(python_client_annos)
    )
예제 #14
0
def test_annotations_unicode():
    a = {
        'files': [u'tmp6y5tVr.txt'],
        'cacheDir': u'/Users/chris/.synapseCache/python/syn1809087',
        u'foo': 1266
    }
    sa = to_synapse_annotations(a)
    assert_equals(sa['stringAnnotations']['cacheDir'],
                  [u'/Users/chris/.synapseCache/python/syn1809087'])
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
예제 #16
0
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
예제 #17
0
def test_more_annotations():
    """Test long, float and data annotations"""
    a = dict(foo=1234, zoo=[123.1, 456.2, 789.3], species='Platypus', birthdays=[Datetime(1969,4,28), Datetime(1973,12,8), Datetime(2008,1,3)])
    sa = to_synapse_annotations(a)
    # print sa
    assert sa['longAnnotations']['foo'] == [1234]
    assert sa['doubleAnnotations']['zoo'] == [123.1, 456.2, 789.3]
    assert sa['stringAnnotations']['species'] == ['Platypus']

    ## this part of the test is kinda fragile. It it breaks again, it should be removed
    bdays = [utils.from_unix_epoch_time(t) for t in sa['dateAnnotations']['birthdays']]
    assert all([t in bdays for t in [Datetime(1969,4,28), Datetime(1973,12,8), Datetime(2008,1,3)]])
예제 #18
0
def test_more_annotations():
    """Test long, float and data annotations"""
    a = Annotations(
        'syn123', '7bdb83e9-a50a-46e4-987a-4962559f090f', {
            'foo':
            1234,
            'zoo': [123.1, 456.2, 789.3],
            'species':
            'Platypus',
            'birthdays': [
                Datetime(1969, 4, 28),
                Datetime(1973, 12, 8),
                Datetime(2008, 1, 3)
            ],
            'test_boolean':
            True,
            'test_mo_booleans': [False, True, True, False]
        })
    sa = to_synapse_annotations(a)

    expected = {
        'id': 'syn123',
        'etag': '7bdb83e9-a50a-46e4-987a-4962559f090f',
        'annotations': {
            'foo': {
                'value': ['1234'],
                'type': 'LONG'
            },
            'zoo': {
                'value': ['123.1', '456.2', '789.3'],
                'type': 'DOUBLE'
            },
            'species': {
                'value': ['Platypus'],
                'type': 'STRING'
            },
            'birthdays': {
                'value': ['-21427200000', '124156800000', '1199318400000'],
                'type': 'TIMESTAMP_MS'
            },
            'test_boolean': {
                'value': ['true'],
                'type': 'STRING'
            },
            'test_mo_booleans': {
                'value': ['false', 'true', 'true', 'false'],
                'type': 'STRING'
            }
        }
    }
    assert expected == sa
def test_more_annotations():
    """Test long, float and data annotations"""
    a = dict(foo=1234,
             zoo=[123.1, 456.2, 789.3],
             species='Platypus',
             birthdays=[Datetime(1969, 4, 28), Datetime(1973, 12, 8), Datetime(2008, 1, 3)],
             test_boolean=True,
             test_mo_booleans=[False, True, True, False])
    sa = to_synapse_annotations(a)
    assert_equals(sa['longAnnotations']['foo'], [1234])
    assert_equals(sa['doubleAnnotations']['zoo'], [123.1, 456.2, 789.3])
    assert_equals(sa['stringAnnotations']['species'], ['Platypus'])
    assert_equals(sa['stringAnnotations']['test_boolean'], ['true'])
    assert_equals(sa['stringAnnotations']['test_mo_booleans'], ['false', 'true', 'true', 'false'])

    # this part of the test is kinda fragile. It it breaks again, it should be removed
    bdays = [utils.from_unix_epoch_time(t) for t in sa['dateAnnotations']['birthdays']]
    assert_true(all([t in bdays for t in [Datetime(1969, 4, 28), Datetime(1973, 12, 8), Datetime(2008, 1, 3)]]))
예제 #20
0
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
예제 #21
0
    def json(self, ensure_ascii=True):
        """Overloaded json function, turning submissionAnnotations into
        synapse style annotations"""

        json_dict = self
        # If not synapse annotations, turn them into synapseclient.Annotations
        # must have id and etag to turn into synapse annotations
        if not is_synapse_annotations(self.submissionAnnotations):
            json_dict = self.copy()

            annotations = _convert_to_annotation_cls(
                id=self.id, etag=self.etag, values=self.submissionAnnotations)
            # Turn into synapse annotation
            json_dict['submissionAnnotations'] = to_synapse_annotations(
                annotations)
        return json.dumps(json_dict,
                          sort_keys=True,
                          indent=2,
                          ensure_ascii=ensure_ascii)
def test_annotations_unicode():
    a = {'files': [u'tmp6y5tVr.txt'], 'cacheDir': u'/Users/chris/.synapseCache/python/syn1809087', u'foo': 1266}
    sa = to_synapse_annotations(a)
    assert sa['stringAnnotations']['cacheDir'] == [u'/Users/chris/.synapseCache/python/syn1809087']