Skip to content

Commit 0c135b5

Browse files
authored
Merge pull request #880 from Sage-Bionetworks/develop-blank-annotations
Update annotations unit test
2 parents 8f19c7d + 0c0eade commit 0c135b5

File tree

8 files changed

+229
-581
lines changed

8 files changed

+229
-581
lines changed

poetry.lock

Lines changed: 199 additions & 520 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ PyYAML = "^5.4.1"
5555
rdflib = "^5.0.0"
5656
setuptools = "^52.0.0"
5757
synapseclient = "2.5.1"
58+
tenacity = "^8.0.1"
5859
toml = "^0.10.2"
5960
Flask = "^1.1.4"
6061
connexion = {extras = ["swagger-ui"], version = "^2.8.0"}

tests/conftest.py

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,31 +66,11 @@ def get_schema_explorer(path=None, *paths):
6666
return se
6767

6868
@staticmethod
69-
def get_version_specific_manifest_path(self, path):
69+
def get_python_version(self):
7070
version=platform.python_version()
71-
manifest_path = self.get_data_path(path)
72-
temp_manifest_path = manifest_path.replace('.csv',version[0:3]+'.csv')
73-
return temp_manifest_path
74-
75-
@staticmethod
76-
def get_version_specific_syn_dataset():
77-
version=platform.python_version()
78-
79-
synId = None
80-
81-
if version.startswith('3.7'):
82-
synId = 'syn34999062'
83-
elif version.startswith('3.8'):
84-
synId = 'syn34999080'
85-
elif version.startswith('3.9'):
86-
synId = 'syn34999096'
87-
88-
if not synId:
89-
raise OSError(
90-
"Unsupported Version of Python"
91-
)
92-
else:
93-
return synId
71+
base_version=".".join(version.split('.')[0:2])
72+
73+
return base_version
9474

9575
@pytest.fixture
9676
def helpers():
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Component,CheckList,CheckRegexList,CheckRegexSingle,CheckNum,CheckFloat,CheckInt,CheckString,CheckURL,CheckMatchatLeast,CheckMatchatLeastvalues,CheckMatchExactly,CheckMatchExactlyvalues,CheckRecommended,CheckAges,CheckUnique
2-
MockComponent,"valid,list,values","a,c,f",a,6,99.65,7,valid,https://www.google.com/,1985,4891,23487492,24323472834,,6571,str1
3-
MockComponent,"valid,list,values","a,c,f",a,6,99.65,8.52,valid,https://www.google.com/,1985,4891,23487492,24323472834,,6571,str1
1+
Component,CheckList,CheckRegexList,CheckRegexSingle,CheckNum,CheckFloat,CheckInt,CheckString,CheckURL,CheckMatchatLeast,CheckMatchatLeastvalues,CheckMatchExactly,CheckMatchExactlyvalues,CheckRecommended,CheckAges,CheckUnique,Uuid,entityId
2+
MockComponent,"valid,list,values","a,c,f",a,6,99.65,7,valid,https://www.google.com/,1985,4891,23487492,24323472834,,6571,str1,0f7812cc-8a0e-4f54-b8c4-e497cb7b34d0,syn35367245
3+
MockComponent,"valid,list,values","a,c,f",a,6,99.65,8.52,valid,https://www.google.com/,1985,4891,23487492,24323472834,,6571,str1,da82f8e2-c7b0-428f-8f9d-677252ef5f68,syn35367246

tests/data/mock_manifests/annotations_test_manifest3.7.csv

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/data/mock_manifests/annotations_test_manifest3.8.csv

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/data/mock_manifests/annotations_test_manifest3.9.csv

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/test_store.py

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55
import pytest
66
import time
7+
from tenacity import Retrying, RetryError, stop_after_attempt, wait_random_exponential
78

89
import pandas as pd
910
from synapseclient import EntityViewSchema
@@ -47,6 +48,9 @@ def dataset_fileview_table_tidy(dataset_fileview, dataset_fileview_table):
4748
yield table
4849

4950

51+
def raise_final_error(retry_state):
52+
return retry_state.outcome.result()
53+
5054
class TestBaseStorage:
5155
def test_init(self):
5256

@@ -81,40 +85,33 @@ def test_getFileAnnotations(self, synapse_store):
8185
assert expected_dict == actual_dict
8286

8387
def test_annotation_submission(self, synapse_store, helpers, config):
84-
# Duplicate base file to avoid conflicts
8588
manifest_path = "mock_manifests/annotations_test_manifest.csv"
86-
temp_manifest_path = helpers.get_version_specific_manifest_path(helpers, manifest_path)
8789

8890
# Upload dataset annotations
8991
inputModelLocaiton = helpers.get_data_path(get_from_config(config.DATA, ("model", "input", "location")))
9092
sg = SchemaGenerator(inputModelLocaiton)
9193

9294
try:
93-
manifest_id = synapse_store.associateMetadataWithFiles(
94-
schemaGenerator=sg,
95-
metadataManifestPath=temp_manifest_path,
96-
datasetId=helpers.get_version_specific_syn_dataset(),
97-
manifest_record_type = 'entity',
98-
useSchemaLabel = True,
99-
hideBlanks = True,
100-
restrict_manifest = False,
101-
)
102-
except(SynapseHTTPError):
103-
time.sleep(30)
104-
105-
manifest_id = synapse_store.associateMetadataWithFiles(
106-
schemaGenerator=sg,
107-
metadataManifestPath=temp_manifest_path,
108-
datasetId=helpers.get_version_specific_syn_dataset(),
109-
manifest_record_type = 'entity',
110-
useSchemaLabel = True,
111-
hideBlanks = True,
112-
restrict_manifest = False,
113-
)
114-
95+
for attempt in Retrying(
96+
stop = stop_after_attempt(15),
97+
wait = wait_random_exponential(multiplier=1,min=10,max=120),
98+
retry_error_callback = raise_final_error
99+
):
100+
with attempt:
101+
manifest_id = synapse_store.associateMetadataWithFiles(
102+
schemaGenerator = sg,
103+
metadataManifestPath = helpers.get_data_path(manifest_path),
104+
datasetId = 'syn34295552',
105+
manifest_record_type = 'entity',
106+
useSchemaLabel = True,
107+
hideBlanks = True,
108+
restrict_manifest = False,
109+
)
110+
except RetryError:
111+
pass
115112

116113
# Retrive annotations
117-
entity_id, entity_id_spare = helpers.get_data_frame(temp_manifest_path)["entityId"][0:2]
114+
entity_id, entity_id_spare = helpers.get_data_frame(manifest_path)["entityId"][0:2]
118115
annotations = synapse_store.getFileAnnotations(entity_id)
119116

120117
# Check annotations of interest

0 commit comments

Comments
 (0)