def test_wrong_field ( self ): # Make an annotation makeAnno (p, 2) # Test the synapse type synapse_type = random.randint (0,100) f = setField(p, 'synapse_type', synapse_type) f = getField(p, 'synapse_type') assert synapse_type == int(f.read()) # Test the weight weight = random.random () f = setField(p, 'weight', weight) f = getField(p, 'weight') assert weight - float(f.read()) < 0.001 # Test inheritance status = random.randint (0,100) f = setField(p, 'status', status) f = getField(p, 'status') assert status == int(f.read()) # bad format to a number url = "http://{}/ca/{}/{}/{}/setField/status/aa/".format(SITE_HOST, 'unittest', 'unit_anno', p.annoid) with pytest.raises(urllib2.HTTPError): req = urllib2.Request ( url ) f = urllib2.urlopen ( url ) # request a missing field url = "http://{}/ca/{}/{}/{}/getField/othernonesuch/".format(SITE_HOST, 'unittest', 'unit_anno', p.annoid) with pytest.raises(urllib2.HTTPError): req = urllib2.Request ( url ) f = urllib2.urlopen ( url )
def test_seed_field (self): """Upload a seed and test it's fields""" # Make a seed makeAnno (p, 3) # Test the parent parent = random.randint (0,100) f = setField(p, 'parent', parent) f = getField(p, 'parent') assert parent == int(f.read()) # Test the source source = random.randint (0,100) f = setField(p, 'source', source) f = getField(p, 'source') assert source == int(f.read()) # Test the cubelocation cubelocation = random.randint (0,100) f = setField(p, 'cubelocation', cubelocation) f = getField(p, 'cubelocation') assert cubelocation == int(f.read()) # Test the position position = [random.randint (0,100), random.randint(0,100), random.randint(0,100)] f = setField(p, 'position', ','.join([str(i) for i in position])) f = getField(p, 'position') assert ','.join([str(i) for i in position]) == f.read()
def test_organelle_field (self): """Upload an organelle and test it's fields""" # Make an organelle makeAnno ( p, 6 ) # Test the parentseed parentseed = random.randint (0,100) f = setField(p, 'parentseed', parentseed) f = getField(p, 'parentseed') assert parentseed == int(f.read()) # Test the organelleclass organelleclass = random.randint (0,100) f = setField(p, 'organelleclass', organelleclass) f = getField(p, 'organelleclass') assert organelleclass == int(f.read()) # Test inheritance status = random.randint (0,100) f = setField(p, 'status', status) f = getField(p, 'status') assert status == int(f.read()) # Test the seeds seeds = [random.randint(0,100), random.randint(0,100), random.randint(0,100)] f = setField(p, 'seeds', ','.join([str(i) for i in seeds])) f = getField(p, 'seeds') assert ','.join([str(i) for i in seeds]) == f.read()
def test_segment_field (self): """Upload a segment and test it's fields""" # Make a segment makeAnno (p, 4) # Test the parentseed parentseed = random.randint (0,100) f = setField(p, 'parentseed', parentseed) f = getField(p, 'parentseed') assert parentseed == int(f.read()) # Test the segmentclass segmentclass = random.randint (0,100) f = setField(p, 'segmentclass', segmentclass) f = getField(p, 'segmentclass') assert segmentclass == int(f.read()) # Test the neuron neuron = random.randint (0,100) f = setField(p, 'neuron', neuron) f = getField(p, 'neuron') assert neuron == int(f.read()) # Test inheritance status = random.randint (0,100) f = setField(p, 'status', status) f = getField(p, 'status') assert status == int(f.read()) # Test the synapses synapses = [random.randint(0,100), random.randint(0,100), random.randint(0,100)] f = setField(p, 'synapses', ','.join([str(i) for i in synapses])) f = getField(p, 'synapses') assert ','.join([str(i) for i in synapses]) == f.read()
def test_seed_field(self): """Upload a seed and test it's fields""" # Make a seed makeAnno(p, 3) # Test the parent parent = random.randint(0, 100) f = setField(p, 'parent', parent) f = getField(p, 'parent') assert parent == int(f.read()) # Test the source source = random.randint(0, 100) f = setField(p, 'source', source) f = getField(p, 'source') assert source == int(f.read()) # Test the cubelocation cubelocation = random.randint(0, 100) f = setField(p, 'cubelocation', cubelocation) f = getField(p, 'cubelocation') assert cubelocation == int(f.read()) # Test the position position = [ random.randint(0, 100), random.randint(0, 100), random.randint(0, 100) ] f = setField(p, 'position', ','.join([str(i) for i in position])) f = getField(p, 'position') assert ','.join([str(i) for i in position]) == f.read()
def test_synapse_field (self): """Upload a synapse and test it's fields""" # Make a synapse makeAnno (p, 2) # Test synapse type synapse_type = random.randint (0,100) f = setField(p, 'synapse_type', synapse_type) f = getField(p, 'synapse_type') assert synapse_type == int(f.read()) # Test the weight weight = random.random () f = setField(p, 'weight', weight) f = getField(p, 'weight') assert weight - float(f.read()) < 0.001 # Test the inheritance status = random.randint (0,100) f = setField(p, 'status', status) f = getField(p, 'status') assert status == int(f.read()) # Test the seeds seeds = [random.randint(0,100), random.randint(0,100), random.randint(0,100)] f = setField(p, 'seeds', ','.join([str(i) for i in seeds])) f = getField(p, 'seeds') assert ','.join([str(i) for i in seeds]) == f.read()
def test_organelle_field(self): """Upload an organelle and test it's fields""" # Make an organelle makeAnno(p, 6) # Test the parentseed parentseed = random.randint(0, 100) f = setField(p, 'parentseed', parentseed) f = getField(p, 'parentseed') assert parentseed == int(f.read()) # Test the organelleclass organelleclass = random.randint(0, 100) f = setField(p, 'organelleclass', organelleclass) f = getField(p, 'organelleclass') assert organelleclass == int(f.read()) # Test inheritance status = random.randint(0, 100) f = setField(p, 'status', status) f = getField(p, 'status') assert status == int(f.read()) # Test the seeds seeds = [ random.randint(0, 100), random.randint(0, 100), random.randint(0, 100) ] f = setField(p, 'seeds', ','.join([str(i) for i in seeds])) f = getField(p, 'seeds') assert ','.join([str(i) for i in seeds]) == f.read()
def test_synapse_field(self): """Upload a synapse and test it's fields""" # Make a synapse makeAnno(p, 2) # Test synapse type synapse_type = random.randint(0, 100) f = setField(p, 'synapse_type', synapse_type) f = getField(p, 'synapse_type') assert synapse_type == int(f.read()) # Test the weight weight = random.random() f = setField(p, 'weight', weight) f = getField(p, 'weight') assert weight - float(f.read()) < 0.001 # Test the inheritance status = random.randint(0, 100) f = setField(p, 'status', status) f = getField(p, 'status') assert status == int(f.read()) # Test the seeds seeds = [ random.randint(0, 100), random.randint(0, 100), random.randint(0, 100) ] f = setField(p, 'seeds', ','.join([str(i) for i in seeds])) f = getField(p, 'seeds') assert ','.join([str(i) for i in seeds]) == f.read()
def test_neuron_field (self): """Upload a neuron and test it's fields""" # Make a neuron makeAnno (p, 5) # Test inheritance status = random.randint (0,100) f = setField(p, 'status', status) f = getField(p, 'status') assert status == int(f.read()) # Test segments status = [random.randint (0,100), random.randint(0,100), random.randint(0,100)] f = setField(p, 'segments', ",".join([str(i) for i in status])) f = getField(p, 'segments') assert ",".join([str(i) for i in status]) == f.read()
def test_annotation_field (self): """Upload an annotation and test it's fields""" # Make an annotation makeAnno (p, 1) # Test Status status = random.randint (0,100) f = setField(p, 'status', status) f = getField(p, 'status') assert status == int(f.read()) # Test confidence confidence = random.random () f = setField(p, 'confidence', confidence) f = getField(p, 'confidence') assert confidence - float(f.read()) < 0.001
def test_annotation_field(self): """Upload an annotation and test it's fields""" # Make an annotation makeAnno(p, 1) # Test Status status = random.randint(0, 100) f = setField(p, 'status', status) f = getField(p, 'status') assert status == int(f.read()) # Test confidence confidence = random.random() f = setField(p, 'confidence', confidence) f = getField(p, 'confidence') assert confidence - float(f.read()) < 0.001
def test_query_objects(self): """Test the function that lists objects of different types.""" # synapse annotations p.anntype = 2 status = random.randint(0, 100) confidence = random.random() * 0.3 + 0.1 # number between 0.1 and 0.4 synapse_type = random.randint(0, 100) synapse_weight = random.random( ) * 0.9 + 0.1 # number between 0.1 and 0.9 for i in range(10): # Make an annotation #annid = makeAnno ( anntype, SITE_HOST ) makeAnno(p, p.anntype) #H5AnnotationFile(p) # set some fields in the even annotations if i % 2 == 0: setField(p, 'status', status) # set the confidence setField(p, 'confidence', confidence) # set the type setField(p, 'synapse_type', synapse_type) # set some fields in the even annotations if i % 2 == 1: # set the confidence setField(p, 'confidence', 1.0 - confidence) # check the status h5 = queryField(p, 'status', status) assert (h5['ANNOIDS'].shape[0] == 5) # check all the confidence variants field_value = '/'.join(['lt', str(1.0 - confidence - 0.0001), '']) h5 = queryField(p, 'confidence', field_value) assert (h5['ANNOIDS'].shape[0] == 5) field_value = '/'.join(['gt', str(confidence + 0.0001), '']) h5 = queryField(p, 'confidence', field_value) assert (h5['ANNOIDS'].shape[0] == 5)
def test_query_objects (self): """Test the function that lists objects of different types.""" # synapse annotations p.anntype = 2 status = random.randint(0,100) confidence = random.random()*0.3+0.1 # number between 0.1 and 0.4 synapse_type = random.randint(0,100) synapse_weight = random.random()*0.9+0.1 # number between 0.1 and 0.9 for i in range (10): # Make an annotation #annid = makeAnno ( anntype, SITE_HOST ) makeAnno( p, p.anntype) #H5AnnotationFile(p) # set some fields in the even annotations if i % 2 == 0: setField(p, 'status', status) # set the confidence setField(p, 'confidence', confidence) # set the type setField(p, 'synapse_type', synapse_type) # set some fields in the even annotations if i % 2 == 1: # set the confidence setField(p, 'confidence', 1.0 - confidence) # check the status h5 = queryField(p, 'status', status) assert ( h5['ANNOIDS'].shape[0] == 5 ) # check all the confidence variants field_value = '/'.join( ['lt',str(1.0-confidence-0.0001), ''] ) h5 = queryField(p, 'confidence', field_value) assert ( h5['ANNOIDS'].shape[0] == 5 ) field_value = '/'.join( ['gt',str(confidence+0.0001), ''] ) h5 = queryField(p, 'confidence', field_value) assert ( h5['ANNOIDS'].shape[0] == 5 )
def test_neuron_field(self): """Upload a neuron and test it's fields""" # Make a neuron makeAnno(p, 5) # Test inheritance status = random.randint(0, 100) f = setField(p, 'status', status) f = getField(p, 'status') assert status == int(f.read()) # Test segments status = [ random.randint(0, 100), random.randint(0, 100), random.randint(0, 100) ] f = setField(p, 'segments', ",".join([str(i) for i in status])) f = getField(p, 'segments') assert ",".join([str(i) for i in status]) == f.read()
def test_segment_field(self): """Upload a segment and test it's fields""" # Make a segment makeAnno(p, 4) # Test the parentseed parentseed = random.randint(0, 100) f = setField(p, 'parentseed', parentseed) f = getField(p, 'parentseed') assert parentseed == int(f.read()) # Test the segmentclass segmentclass = random.randint(0, 100) f = setField(p, 'segmentclass', segmentclass) f = getField(p, 'segmentclass') assert segmentclass == int(f.read()) # Test the neuron neuron = random.randint(0, 100) f = setField(p, 'neuron', neuron) f = getField(p, 'neuron') assert neuron == int(f.read()) # Test inheritance status = random.randint(0, 100) f = setField(p, 'status', status) f = getField(p, 'status') assert status == int(f.read()) # Test the synapses synapses = [ random.randint(0, 100), random.randint(0, 100), random.randint(0, 100) ] f = setField(p, 'synapses', ','.join([str(i) for i in synapses])) f = getField(p, 'synapses') assert ','.join([str(i) for i in synapses]) == f.read()
def test_wrong_field(self): # Make an annotation makeAnno(p, 2) # Test the synapse type synapse_type = random.randint(0, 100) f = setField(p, 'synapse_type', synapse_type) f = getField(p, 'synapse_type') assert synapse_type == int(f.read()) # Test the weight weight = random.random() f = setField(p, 'weight', weight) f = getField(p, 'weight') assert weight - float(f.read()) < 0.001 # Test inheritance status = random.randint(0, 100) f = setField(p, 'status', status) f = getField(p, 'status') assert status == int(f.read()) # bad format to a number url = "http://{}/ca/{}/{}/{}/setField/status/aa/".format( SITE_HOST, 'unittest', 'unit_anno', p.annoid) with pytest.raises(urllib2.HTTPError): req = urllib2.Request(url) f = urllib2.urlopen(url) # request a missing field url = "http://{}/ca/{}/{}/{}/getField/othernonesuch/".format( SITE_HOST, 'unittest', 'unit_anno', p.annoid) with pytest.raises(urllib2.HTTPError): req = urllib2.Request(url) f = urllib2.urlopen(url)